diff options
| author | Mark Otto <[email protected]> | 2012-12-26 09:21:34 -0600 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2012-12-26 09:21:34 -0600 |
| commit | 9749d6afc2730d41cab0111e1cc19bba7c5c3676 (patch) | |
| tree | 5420af50b680ac608d6ed177d24d79870dcad544 /js/bootstrap-tooltip.js | |
| parent | f74990d898b08be61f0f8b514378adf223d55a4b (diff) | |
| parent | b9c7f29134f2fa81931fa4663fc40ef7a0e363d1 (diff) | |
| download | bootstrap-9749d6afc2730d41cab0111e1cc19bba7c5c3676.tar.xz bootstrap-9749d6afc2730d41cab0111e1cc19bba7c5c3676.zip | |
Merge branch '2.3.0-wip' of github.com:twitter/bootstrap into 2.3.0-wip
Diffstat (limited to 'js/bootstrap-tooltip.js')
| -rw-r--r-- | js/bootstrap-tooltip.js | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js index e08604940..c23d8267a 100644 --- a/js/bootstrap-tooltip.js +++ b/js/bootstrap-tooltip.js @@ -38,19 +38,27 @@ , init: function (type, element, options) { var eventIn , eventOut + , triggers + , trigger + , i this.type = type this.$element = $(element) this.options = this.getOptions(options) this.enabled = true - if (this.options.trigger == 'click') { - this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) - } else if (this.options.trigger != 'manual') { - eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus' - eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur' - this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) - this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) + triggers = this.options.trigger.split(' ') + + for (i = triggers.length; i--;) { + trigger = triggers[i] + if (trigger == 'click') { + this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) + } else if (trigger != 'manual') { + eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' + eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' + this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) + this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) + } } this.options.selector ? @@ -102,8 +110,11 @@ , actualHeight , placement , tp + , e = $.Event('show') if (this.hasContent() && this.enabled) { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $tip = this.tip() this.setContent() @@ -118,7 +129,8 @@ $tip .detach() .css({ top: 0, left: 0, display: 'block' }) - .insertAfter(this.$element) + + this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) pos = this.getPosition() @@ -144,6 +156,8 @@ .offset(tp) .addClass(placement) .addClass('in') + + this.$element.trigger('shown') } } @@ -158,6 +172,10 @@ , hide: function () { var that = this , $tip = this.tip() + , e = $.Event('hide') + + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $tip.removeClass('in') @@ -176,6 +194,8 @@ removeWithAnimation() : $tip.detach() + this.$element.trigger('hidden') + return this } @@ -234,8 +254,8 @@ } , toggle: function (e) { - var self = $(e.currentTarget)[this.type](this._options).data(this.type) - self[self.tip().hasClass('in') ? 'hide' : 'show']() + var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this + self.tip().hasClass('in') ? self.hide() : self.show() } , destroy: function () { @@ -267,10 +287,11 @@ , placement: 'top' , selector: false , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' - , trigger: 'hover' + , trigger: 'hover focus' , title: '' , delay: 0 , html: false + , container: false } @@ -282,4 +303,4 @@ return this } -}(window.jQuery);
\ No newline at end of file +}(window.jQuery); |
