diff options
| author | fat <[email protected]> | 2013-08-04 17:22:49 -0700 |
|---|---|---|
| committer | fat <[email protected]> | 2013-08-04 17:22:49 -0700 |
| commit | 2b6ec389876fac116ae2a152e47be321632dd9ba (patch) | |
| tree | c1d2b32f6e5532b551503467fe9b9a388fc985a2 /dist/js/bootstrap.js | |
| parent | f22a077f6ea0e0d85d9899a1f44eab4733ca6af6 (diff) | |
| download | bootstrap-2b6ec389876fac116ae2a152e47be321632dd9ba.tar.xz bootstrap-2b6ec389876fac116ae2a152e47be321632dd9ba.zip | |
fixes #8880
Diffstat (limited to 'dist/js/bootstrap.js')
| -rw-r--r-- | dist/js/bootstrap.js | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/dist/js/bootstrap.js b/dist/js/bootstrap.js index 6c560b292..dc6344d5a 100644 --- a/dist/js/bootstrap.js +++ b/dist/js/bootstrap.js @@ -1245,12 +1245,9 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } .addClass(placement) } - 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 } + var calculatedOffset = this.getCalcuatedOffset(placement, pos, actualWidth, actualHeight) - this.applyPlacement(tp, placement) + this.applyPlacement(calculatedOffset, placement) this.$element.trigger('shown.bs.' + this.type) } } @@ -1262,25 +1259,33 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } 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) + var marginTop = parseInt($tip.css('margin-top'), 10) + var marginLeft = parseInt($tip.css('margin-left'), 10) + + // we must check for NaN for ie 8/9 + if (isNaN(marginTop)) marginTop = 0 + if (isNaN(marginLeft)) marginLeft = 0 + + offset.top = offset.top + marginTop + offset.left = offset.left + marginLeft $tip .offset(offset) .addClass('in') + // check to see if placing tip in new offset caused the tip to resize itself var actualWidth = $tip[0].offsetWidth var actualHeight = $tip[0].offsetHeight if (placement == 'top' && actualHeight != height) { replace = true - offset.top = offset.top + height - actualHeight + offset.top = offset.top + height - actualHeight } - if (placement == 'bottom' || placement == 'top') { + if (/bottom|top/.test(placement)) { var delta = 0 - if (offset.left < 0){ + if (offset.left < 0) { delta = offset.left * -2 offset.left = 0 @@ -1353,6 +1358,13 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } }, this.$element.offset()) } + Tooltip.prototype.getCalcuatedOffset = function (placement, pos, actualWidth, actualHeight) { + return 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 } + } + Tooltip.prototype.getTitle = function () { var title var $e = this.$element @@ -1368,8 +1380,8 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } return this.$tip = this.$tip || $(this.options.template) } - Tooltip.prototype.arrow =function(){ - return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow") + Tooltip.prototype.arrow =function () { + return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow') } Tooltip.prototype.validate = function () { @@ -1508,6 +1520,10 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") } o.content) } + Popover.prototype.arrow =function () { + return this.$arrow = this.$arrow || this.tip().find('.arrow') + } + Popover.prototype.tip = function () { if (!this.$tip) this.$tip = $(this.options.template) return this.$tip |
