diff options
author | Guillaume Gautreau <guillaume+github@ghusse.com> | 2013-01-26 16:50:26 +0400 |
---|---|---|
committer | Guillaume Gautreau <guillaume+github@ghusse.com> | 2013-01-26 16:50:26 +0400 |
commit | 6803ff70f9203595a04c5adb20d7556cd52c5923 (patch) | |
tree | 7b32c30a7227c7c7a475ec06aad2dac49caa2b4b /js/bootstrap-tooltip.js | |
parent | 01b465928ec47d460ea1fd705e49aa2e0e9a4d28 (diff) |
Tooltip positionning on special cases
Diffstat (limited to 'js/bootstrap-tooltip.js')
-rw-r--r-- | js/bootstrap-tooltip.js | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index c23d8267a8..0d8a20f568 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -152,15 +152,68 @@ break } - $tip - .offset(tp) - .addClass(placement) - .addClass('in') + 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'); + + actualWidth = $tip[0].offsetWidth; + actualHeight = $tip[0].offsetHeight; + + if (placement == "top" && actualHeight != actualWidth){ + 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() , title = this.getTitle() @@ -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() |