vendor/assets/javascripts/twitter/bootstrap/tooltip.js in bootstrap-sass-rails-2.0.2.2 vs vendor/assets/javascripts/twitter/bootstrap/tooltip.js in bootstrap-sass-rails-2.0.3.0pre1

- old
+ new

@@ -1,7 +1,7 @@ /* =========================================================== - * bootstrap-tooltip.js v2.0.2 + * bootstrap-tooltip.js v2.0.3 * http://twitter.github.com/bootstrap/javascript.html#tooltips * Inspired by the original jQuery.tipsy by Jason Frame * =========================================================== * Copyright 2012 Twitter, Inc. * @@ -16,26 +16,28 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================== */ -!function( $ ) { - "use strict" +!function ($) { + "use strict"; // jshint ;_; + + /* TOOLTIP PUBLIC CLASS DEFINITION * =============================== */ - var Tooltip = function ( element, options ) { + var Tooltip = function (element, options) { this.init('tooltip', element, options) } Tooltip.prototype = { constructor: Tooltip - , init: function ( type, element, options ) { + , init: function (type, element, options) { var eventIn , eventOut this.type = type this.$element = $(element) @@ -52,11 +54,11 @@ this.options.selector ? (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : this.fixTitle() } - , getOptions: function ( options ) { + , getOptions: function (options) { options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data()) if (options.delay && typeof options.delay == 'number') { options.delay = { show: options.delay @@ -65,38 +67,32 @@ } return options } - , enter: function ( e ) { + , enter: function (e) { var self = $(e.currentTarget)[this.type](this._options).data(this.type) - if (!self.options.delay || !self.options.delay.show) { - self.show() - } else { - self.hoverState = 'in' - setTimeout(function() { - if (self.hoverState == 'in') { - self.show() - } - }, self.options.delay.show) - } + if (!self.options.delay || !self.options.delay.show) return self.show() + + clearTimeout(this.timeout) + self.hoverState = 'in' + this.timeout = setTimeout(function() { + if (self.hoverState == 'in') self.show() + }, self.options.delay.show) } - , leave: function ( e ) { + , leave: function (e) { var self = $(e.currentTarget)[this.type](this._options).data(this.type) - if (!self.options.delay || !self.options.delay.hide) { - self.hide() - } else { - self.hoverState = 'out' - setTimeout(function() { - if (self.hoverState == 'out') { - self.hide() - } - }, self.options.delay.hide) - } + if (!self.options.delay || !self.options.delay.hide) return self.hide() + + clearTimeout(this.timeout) + self.hoverState = 'out' + this.timeout = setTimeout(function() { + if (self.hoverState == 'out') self.hide() + }, self.options.delay.hide) } , show: function () { var $tip , inside @@ -150,13 +146,24 @@ .addClass(placement) .addClass('in') } } + , isHTML: function(text) { + // html string detection logic adapted from jQuery + return typeof text != 'string' + || ( text.charAt(0) === "<" + && text.charAt( text.length - 1 ) === ">" + && text.length >= 3 + ) || /^(?:[^<]*<[\w\W]+>[^>]*$)/.exec(text) + } + , setContent: function () { var $tip = this.tip() - $tip.find('.tooltip-inner').html(this.getTitle()) + , title = this.getTitle() + + $tip.find('.tooltip-inner')[this.isHTML(title) ? 'html' : 'text'](title) $tip.removeClass('fade in top bottom left right') } , hide: function () { var that = this @@ -204,12 +211,10 @@ , o = this.options title = $e.attr('data-original-title') || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) - title = (title || '').toString().replace(/(^\s*|\s*$)/, "") - return title } , tip: function () { return this.$tip = this.$tip || $(this.options.template) @@ -257,14 +262,14 @@ $.fn.tooltip.Constructor = Tooltip $.fn.tooltip.defaults = { animation: true - , delay: 0 - , selector: false , placement: 'top' + , selector: false + , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' , trigger: 'hover' , title: '' - , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' + , delay: 0 } -}( window.jQuery ); +}(window.jQuery); \ No newline at end of file