Skip to content

Commit

Permalink
fixes twbs#8568 -- account for margins in offset
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Jul 25, 2013
1 parent aad9104 commit e9c8364
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
23 changes: 8 additions & 15 deletions dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,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
Expand All @@ -1216,20 +1215,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)
Expand All @@ -1242,6 +1231,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')
Expand Down
Loading

0 comments on commit e9c8364

Please sign in to comment.