indvd00m@0: /* =========================================================== indvd00m@0: * bootstrap-tooltip.js v2.3.1 indvd00m@0: * http://twitter.github.com/bootstrap/javascript.html#tooltips indvd00m@0: * Inspired by the original jQuery.tipsy by Jason Frame indvd00m@0: * =========================================================== indvd00m@0: * Copyright 2012 Twitter, Inc. indvd00m@0: * indvd00m@0: * Licensed under the Apache License, Version 2.0 (the "License"); indvd00m@0: * you may not use this file except in compliance with the License. indvd00m@0: * You may obtain a copy of the License at indvd00m@0: * indvd00m@0: * http://www.apache.org/licenses/LICENSE-2.0 indvd00m@0: * indvd00m@0: * Unless required by applicable law or agreed to in writing, software indvd00m@0: * distributed under the License is distributed on an "AS IS" BASIS, indvd00m@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. indvd00m@0: * See the License for the specific language governing permissions and indvd00m@0: * limitations under the License. indvd00m@0: * ========================================================== */ indvd00m@0: indvd00m@0: indvd00m@0: !function ($) { indvd00m@0: indvd00m@0: "use strict"; // jshint ;_; indvd00m@0: indvd00m@0: indvd00m@0: /* TOOLTIP PUBLIC CLASS DEFINITION indvd00m@0: * =============================== */ indvd00m@0: indvd00m@0: var Tooltip = function (element, options) { indvd00m@0: this.init('tooltip', element, options) indvd00m@0: } indvd00m@0: indvd00m@0: Tooltip.prototype = { indvd00m@0: indvd00m@0: constructor: Tooltip indvd00m@0: indvd00m@0: , init: function (type, element, options) { indvd00m@0: var eventIn indvd00m@0: , eventOut indvd00m@0: , triggers indvd00m@0: , trigger indvd00m@0: , i indvd00m@0: indvd00m@0: this.type = type indvd00m@0: this.$element = $(element) indvd00m@0: this.options = this.getOptions(options) indvd00m@0: this.enabled = true indvd00m@0: indvd00m@0: triggers = this.options.trigger.split(' ') indvd00m@0: indvd00m@0: for (i = triggers.length; i--;) { indvd00m@0: trigger = triggers[i] indvd00m@0: if (trigger == 'click') { indvd00m@0: this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) indvd00m@0: } else if (trigger != 'manual') { indvd00m@0: eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' indvd00m@0: eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' indvd00m@0: this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) indvd00m@0: this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: this.options.selector ? indvd00m@0: (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : indvd00m@0: this.fixTitle() indvd00m@0: } indvd00m@0: indvd00m@0: , getOptions: function (options) { indvd00m@0: options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options) indvd00m@0: indvd00m@0: if (options.delay && typeof options.delay == 'number') { indvd00m@0: options.delay = { indvd00m@0: show: options.delay indvd00m@0: , hide: options.delay indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: return options indvd00m@0: } indvd00m@0: indvd00m@0: , enter: function (e) { indvd00m@0: var defaults = $.fn[this.type].defaults indvd00m@0: , options = {} indvd00m@0: , self indvd00m@0: indvd00m@0: this._options && $.each(this._options, function (key, value) { indvd00m@0: if (defaults[key] != value) options[key] = value indvd00m@0: }, this) indvd00m@0: indvd00m@0: self = $(e.currentTarget)[this.type](options).data(this.type) indvd00m@0: indvd00m@0: if (!self.options.delay || !self.options.delay.show) return self.show() indvd00m@0: indvd00m@0: clearTimeout(this.timeout) indvd00m@0: self.hoverState = 'in' indvd00m@0: this.timeout = setTimeout(function() { indvd00m@0: if (self.hoverState == 'in') self.show() indvd00m@0: }, self.options.delay.show) indvd00m@0: } indvd00m@0: indvd00m@0: , leave: function (e) { indvd00m@0: var self = $(e.currentTarget)[this.type](this._options).data(this.type) indvd00m@0: indvd00m@0: if (this.timeout) clearTimeout(this.timeout) indvd00m@0: if (!self.options.delay || !self.options.delay.hide) return self.hide() indvd00m@0: indvd00m@0: self.hoverState = 'out' indvd00m@0: this.timeout = setTimeout(function() { indvd00m@0: if (self.hoverState == 'out') self.hide() indvd00m@0: }, self.options.delay.hide) indvd00m@0: } indvd00m@0: indvd00m@0: , show: function () { indvd00m@0: var $tip indvd00m@0: , pos indvd00m@0: , actualWidth indvd00m@0: , actualHeight indvd00m@0: , placement indvd00m@0: , tp indvd00m@0: , e = $.Event('show') indvd00m@0: indvd00m@0: if (this.hasContent() && this.enabled) { indvd00m@0: this.$element.trigger(e) indvd00m@0: if (e.isDefaultPrevented()) return indvd00m@0: $tip = this.tip() indvd00m@0: this.setContent() indvd00m@0: indvd00m@0: if (this.options.animation) { indvd00m@0: $tip.addClass('fade') indvd00m@0: } indvd00m@0: indvd00m@0: placement = typeof this.options.placement == 'function' ? indvd00m@0: this.options.placement.call(this, $tip[0], this.$element[0]) : indvd00m@0: this.options.placement indvd00m@0: indvd00m@0: $tip indvd00m@0: .detach() indvd00m@0: .css({ top: 0, left: 0, display: 'block' }) indvd00m@0: indvd00m@0: this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) indvd00m@0: indvd00m@0: pos = this.getPosition() indvd00m@0: indvd00m@0: actualWidth = $tip[0].offsetWidth indvd00m@0: actualHeight = $tip[0].offsetHeight indvd00m@0: indvd00m@0: switch (placement) { indvd00m@0: case 'bottom': indvd00m@0: tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2} indvd00m@0: break indvd00m@0: case 'top': indvd00m@0: tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2} indvd00m@0: break indvd00m@0: case 'left': indvd00m@0: tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth} indvd00m@0: break indvd00m@0: case 'right': indvd00m@0: tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width} indvd00m@0: break indvd00m@0: } indvd00m@0: indvd00m@0: this.applyPlacement(tp, placement) indvd00m@0: this.$element.trigger('shown') indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: , applyPlacement: function(offset, placement){ indvd00m@0: var $tip = this.tip() indvd00m@0: , width = $tip[0].offsetWidth indvd00m@0: , height = $tip[0].offsetHeight indvd00m@0: , actualWidth indvd00m@0: , actualHeight indvd00m@0: , delta indvd00m@0: , replace indvd00m@0: indvd00m@0: $tip indvd00m@0: .offset(offset) indvd00m@0: .addClass(placement) indvd00m@0: .addClass('in') indvd00m@0: indvd00m@0: actualWidth = $tip[0].offsetWidth indvd00m@0: actualHeight = $tip[0].offsetHeight indvd00m@0: indvd00m@0: if (placement == 'top' && actualHeight != height) { indvd00m@0: offset.top = offset.top + height - actualHeight indvd00m@0: replace = true indvd00m@0: } indvd00m@0: indvd00m@0: if (placement == 'bottom' || placement == 'top') { indvd00m@0: delta = 0 indvd00m@0: indvd00m@0: if (offset.left < 0){ indvd00m@0: delta = offset.left * -2 indvd00m@0: offset.left = 0 indvd00m@0: $tip.offset(offset) indvd00m@0: actualWidth = $tip[0].offsetWidth indvd00m@0: actualHeight = $tip[0].offsetHeight indvd00m@0: } indvd00m@0: indvd00m@0: this.replaceArrow(delta - width + actualWidth, actualWidth, 'left') indvd00m@0: } else { indvd00m@0: this.replaceArrow(actualHeight - height, actualHeight, 'top') indvd00m@0: } indvd00m@0: indvd00m@0: if (replace) $tip.offset(offset) indvd00m@0: } indvd00m@0: indvd00m@0: , replaceArrow: function(delta, dimension, position){ indvd00m@0: this indvd00m@0: .arrow() indvd00m@0: .css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') indvd00m@0: } indvd00m@0: indvd00m@0: , setContent: function () { indvd00m@0: var $tip = this.tip() indvd00m@0: , title = this.getTitle() indvd00m@0: indvd00m@0: $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) indvd00m@0: $tip.removeClass('fade in top bottom left right') indvd00m@0: } indvd00m@0: indvd00m@0: , hide: function () { indvd00m@0: var that = this indvd00m@0: , $tip = this.tip() indvd00m@0: , e = $.Event('hide') indvd00m@0: indvd00m@0: this.$element.trigger(e) indvd00m@0: if (e.isDefaultPrevented()) return indvd00m@0: indvd00m@0: $tip.removeClass('in') indvd00m@0: indvd00m@0: function removeWithAnimation() { indvd00m@0: var timeout = setTimeout(function () { indvd00m@0: $tip.off($.support.transition.end).detach() indvd00m@0: }, 500) indvd00m@0: indvd00m@0: $tip.one($.support.transition.end, function () { indvd00m@0: clearTimeout(timeout) indvd00m@0: $tip.detach() indvd00m@0: }) indvd00m@0: } indvd00m@0: indvd00m@0: $.support.transition && this.$tip.hasClass('fade') ? indvd00m@0: removeWithAnimation() : indvd00m@0: $tip.detach() indvd00m@0: indvd00m@0: this.$element.trigger('hidden') indvd00m@0: indvd00m@0: return this indvd00m@0: } indvd00m@0: indvd00m@0: , fixTitle: function () { indvd00m@0: var $e = this.$element indvd00m@0: if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { indvd00m@0: $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: , hasContent: function () { indvd00m@0: return this.getTitle() indvd00m@0: } indvd00m@0: indvd00m@0: , getPosition: function () { indvd00m@0: var el = this.$element[0] indvd00m@0: return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { indvd00m@0: width: el.offsetWidth indvd00m@0: , height: el.offsetHeight indvd00m@0: }, this.$element.offset()) indvd00m@0: } indvd00m@0: indvd00m@0: , getTitle: function () { indvd00m@0: var title indvd00m@0: , $e = this.$element indvd00m@0: , o = this.options indvd00m@0: indvd00m@0: title = $e.attr('data-original-title') indvd00m@0: || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) indvd00m@0: indvd00m@0: return title indvd00m@0: } indvd00m@0: indvd00m@0: , tip: function () { indvd00m@0: return this.$tip = this.$tip || $(this.options.template) indvd00m@0: } indvd00m@0: indvd00m@0: , arrow: function(){ indvd00m@0: return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow") indvd00m@0: } indvd00m@0: indvd00m@0: , validate: function () { indvd00m@0: if (!this.$element[0].parentNode) { indvd00m@0: this.hide() indvd00m@0: this.$element = null indvd00m@0: this.options = null indvd00m@0: } indvd00m@0: } indvd00m@0: indvd00m@0: , enable: function () { indvd00m@0: this.enabled = true indvd00m@0: } indvd00m@0: indvd00m@0: , disable: function () { indvd00m@0: this.enabled = false indvd00m@0: } indvd00m@0: indvd00m@0: , toggleEnabled: function () { indvd00m@0: this.enabled = !this.enabled indvd00m@0: } indvd00m@0: indvd00m@0: , toggle: function (e) { indvd00m@0: var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this indvd00m@0: self.tip().hasClass('in') ? self.hide() : self.show() indvd00m@0: } indvd00m@0: indvd00m@0: , destroy: function () { indvd00m@0: this.hide().$element.off('.' + this.type).removeData(this.type) indvd00m@0: } indvd00m@0: indvd00m@0: } indvd00m@0: indvd00m@0: indvd00m@0: /* TOOLTIP PLUGIN DEFINITION indvd00m@0: * ========================= */ indvd00m@0: indvd00m@0: var old = $.fn.tooltip indvd00m@0: indvd00m@0: $.fn.tooltip = function ( option ) { indvd00m@0: return this.each(function () { indvd00m@0: var $this = $(this) indvd00m@0: , data = $this.data('tooltip') indvd00m@0: , options = typeof option == 'object' && option indvd00m@0: if (!data) $this.data('tooltip', (data = new Tooltip(this, options))) indvd00m@0: if (typeof option == 'string') data[option]() indvd00m@0: }) indvd00m@0: } indvd00m@0: indvd00m@0: $.fn.tooltip.Constructor = Tooltip indvd00m@0: indvd00m@0: $.fn.tooltip.defaults = { indvd00m@0: animation: true indvd00m@0: , placement: 'top' indvd00m@0: , selector: false indvd00m@0: , template: '
' indvd00m@0: , trigger: 'hover focus' indvd00m@0: , title: '' indvd00m@0: , delay: 0 indvd00m@0: , html: false indvd00m@0: , container: false indvd00m@0: } indvd00m@0: indvd00m@0: indvd00m@0: /* TOOLTIP NO CONFLICT indvd00m@0: * =================== */ indvd00m@0: indvd00m@0: $.fn.tooltip.noConflict = function () { indvd00m@0: $.fn.tooltip = old indvd00m@0: return this indvd00m@0: } indvd00m@0: indvd00m@0: }(window.jQuery);