From e956acf1fa77c428153538ba00e6286aeba28670 Mon Sep 17 00:00:00 2001 From: fo Date: Mon, 1 Sep 2014 12:53:50 +0300 Subject: [PATCH] Add fix to the tooltip library so tooltips never go out of the window. #106 --- libs/tooltip.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/tooltip.js b/libs/tooltip.js index f6c0a376c..d62d5a466 100644 --- a/libs/tooltip.js +++ b/libs/tooltip.js @@ -185,6 +185,29 @@ that.$element.trigger('shown.bs.' + that.type) } + var deltas = { + "bottom": $tip[0].getBoundingClientRect().bottom - window.innerHeight, + "right": $tip[0].getBoundingClientRect().right - window.innerWidth, + "left": -$tip[0].getBoundingClientRect().left, + "top": -$tip[0].getBoundingClientRect().top + }; + for(var direction in deltas) { + if (deltas[direction] > 0) { + var delta = deltas[direction]; + if(direction === "right" || direction === "bottom") { + delta = -delta; + } + direction = direction === "top" || direction === "bottom" ? "top" : "left"; + var currentPosition = parseInt($tip.css(direction), 10); + $tip.css(direction, currentPosition + delta); + if(direction === "left") { + $tip.children(".arrow").css(direction, parseInt($tip.children(".arrow").css(direction), 10) - delta); + } else { + $tip.children(".arrow").css(direction, 50 - $tip[0].getBoundingClientRect().height / delta + "%"); + } + } + } + $.support.transition && this.$tip.hasClass('fade') ? $tip .one($.support.transition.end, complete)