diff options
author | Mark Otto <otto@github.com> | 2013-02-06 10:42:54 +0400 |
---|---|---|
committer | Mark Otto <otto@github.com> | 2013-02-06 10:42:54 +0400 |
commit | 421f9f67c44d4b7c971b42808687ae7b71c99151 (patch) | |
tree | 4aa1c698f535d8ae8f7aae7a4b6d396bc86906a4 /docs/assets/js/bootstrap-tooltip.js | |
parent | 6d21d8600739fe16e8993a11f82a4727065ca78a (diff) | |
parent | 3b56227553f40cc567e161c68c64f1e315fd5241 (diff) |
Merge branch '2.3.0-wip' into 3.0.0-wip
Conflicts:
docs/assets/css/bootstrap-responsive.css
docs/assets/js/bootstrap-popover.js
docs/assets/js/bootstrap.js
docs/css.html
docs/templates/pages/base-css.mustache
js/bootstrap-popover.js
less/mixins.less
less/tooltip.less
Diffstat (limited to 'docs/assets/js/bootstrap-tooltip.js')
-rw-r--r-- | docs/assets/js/bootstrap-tooltip.js | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/docs/assets/js/bootstrap-tooltip.js b/docs/assets/js/bootstrap-tooltip.js index d57cd9d7f1..9218d5d353 100644 --- a/docs/assets/js/bootstrap-tooltip.js +++ b/docs/assets/js/bootstrap-tooltip.js @@ -67,7 +67,7 @@ } , getOptions: function (options) { - options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data()) + options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options) if (options.delay && typeof options.delay == 'number') { options.delay = { @@ -152,15 +152,58 @@ break } - $tip - .offset(tp) - .addClass(placement) - .addClass('in') - + this.applyPlacement(tp, placement) this.$element.trigger('shown') } } + , applyPlacement: function(offset, placement){ + var $tip = this.tip() + , width = $tip[0].offsetWidth + , height = $tip[0].offsetHeight + , actualWidth + , actualHeight + , delta + , replace + + $tip + .offset(offset) + .addClass(placement) + .addClass('in') + + 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){ + this + .arrow() + .css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') + } + , setContent: function () { var $tip = this.tip() , title = this.getTitle() @@ -212,7 +255,7 @@ , getPosition: function () { var el = this.$element[0] - return $.extend({}, el.getBoundingClientRect ? el.getBoundingClientRect() : { + return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { width: el.offsetWidth , height: el.offsetHeight }, this.$element.offset()) @@ -233,6 +276,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() |