diff options
| author | Jacob Thornton <[email protected]> | 2013-07-24 20:57:26 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2013-07-24 20:57:26 -0700 |
| commit | e9c83647afb90b95ab8d8e86fa33bb5c71768f2d (patch) | |
| tree | 6946995a52c328417b43ff5d7ef33ff5f46c10b5 /js | |
| parent | aad910465c3379061b15f3d515a806dad63375ad (diff) | |
| download | bootstrap-e9c83647afb90b95ab8d8e86fa33bb5c71768f2d.tar.xz bootstrap-e9c83647afb90b95ab8d8e86fa33bb5c71768f2d.zip | |
fixes #8568 -- account for margins in offset
Diffstat (limited to 'js')
| -rw-r--r-- | js/tooltip.js | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/js/tooltip.js b/js/tooltip.js index 897a44517..faa434030 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -155,7 +155,6 @@ this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) - var tp var pos = this.getPosition() var actualWidth = $tip[0].offsetWidth var actualHeight = $tip[0].offsetHeight @@ -180,20 +179,10 @@ .addClass(placement) } - switch (placement) { - case 'bottom': - tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2} - break - case 'top': - tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2} - break - case 'left': - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth} - break - case 'right': - tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width} - break - } + var tp = placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : + placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : + /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } this.applyPlacement(tp, placement) this.$element.trigger('shown.bs.' + this.type) @@ -206,6 +195,10 @@ var width = $tip[0].offsetWidth var height = $tip[0].offsetHeight + // manually read margins because getBoundingClientRect includes difference + offset.top = offset.top + parseInt($tip.css('margin-top'), 10) + offset.left = offset.left + parseInt($tip.css('margin-left'), 10) + $tip .offset(offset) .addClass('in') |
