Add fix to the tooltip library so tooltips never go out of the window. #106

This commit is contained in:
fo 2014-09-01 12:53:50 +03:00
parent d148161a42
commit e956acf1fa
1 changed files with 23 additions and 0 deletions

View File

@ -185,6 +185,29 @@
that.$element.trigger('shown.bs.' + that.type) 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') ? $.support.transition && this.$tip.hasClass('fade') ?
$tip $tip
.one($.support.transition.end, complete) .one($.support.transition.end, complete)