diff options
author | fat <jacobthornton@gmail.com> | 2013-02-06 10:10:41 +0400 |
---|---|---|
committer | fat <jacobthornton@gmail.com> | 2013-02-06 10:10:41 +0400 |
commit | 5e4db94c240c5ac2af18bbf4238358a043ad4037 (patch) | |
tree | 4684990e086ba661c4a8fbc406c80255ccf10b9e /js/bootstrap-tooltip.js | |
parent | a4b31d39a26bf493d60d4aaadddd19996966e43c (diff) | |
parent | ee71fb492ffc664627436431c5f7b71d2107a526 (diff) |
Merge branch '2.3.0-wip' of git://github.com/ghusse/bootstrap into ghusse-2.3.0-wip
Diffstat (limited to 'js/bootstrap-tooltip.js')
-rw-r--r-- | js/bootstrap-tooltip.js | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index 9ba2d1214a..f17b311573 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -152,14 +152,67 @@ break } - $tip - .offset(tp) + this.applyPlacement(tp, placement) + + this.$element.trigger('shown') + } + } + + , applyPlacement: function(offset, placement){ + var $tip + , width + , height + , actualWidth + , actualHeight + , delta + , replace = false + + $tip = this.tip() + + width = $tip[0].offsetWidth + height = $tip[0].offsetHeight + + $tip + .offset(offset) .addClass(placement) .addClass('in') - this.$element.trigger('shown') + actualWidth = $tip[0].offsetWidth + actualHeight = $tip[0].offsetHeight + + if (placement == "top" && actualHeight != height){ + offset.top = offset.top + height - actualHeight + replace = true + } + + if (placement == "bottom" || placement == "top"){ + delta = 0 + + if (offset.left < 0){ + delta = -offset.left * 2 + offset.left = 0 + $tip.offset(offset) + actualWidth = $tip[0].offsetWidth + actualHeight = $tip[0].offsetHeight } + + this.replaceArrow(delta - width + actualWidth, actualWidth, "left") + }else{ + this.replaceArrow(actualHeight - height, actualHeight, "top") + } + + if (replace) $tip.offset(offset) + } + + , replaceArrow: function(delta, dimension, position){ + var $arrow = this.arrow() + + if (delta !== 0){ + $arrow.css(position, 50 * (1 - delta / dimension) + "%") + }else{ + $arrow.css(position, "") } + } , setContent: function () { var $tip = this.tip() @@ -233,6 +286,10 @@ return this.$tip = this.$tip || $(this.options.template) } + , arrow: function(){ + return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow") + } + , validate: function () { if (!this.$element[0].parentNode) { this.hide() |