info@54: /* ======================================================================== info@54: * Bootstrap: tooltip.js v3.0.3 info@54: * http://getbootstrap.com/javascript/#tooltip info@54: * Inspired by the original jQuery.tipsy by Jason Frame info@54: * ======================================================================== info@54: * Copyright 2013 Twitter, Inc. info@54: * info@54: * Licensed under the Apache License, Version 2.0 (the "License"); info@54: * you may not use this file except in compliance with the License. info@54: * You may obtain a copy of the License at info@54: * info@54: * http://www.apache.org/licenses/LICENSE-2.0 info@54: * info@54: * Unless required by applicable law or agreed to in writing, software info@54: * distributed under the License is distributed on an "AS IS" BASIS, info@54: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. info@54: * See the License for the specific language governing permissions and info@54: * limitations under the License. info@54: * ======================================================================== */ info@54: info@54: info@54: +function ($) { "use strict"; info@54: info@54: // TOOLTIP PUBLIC CLASS DEFINITION info@54: // =============================== info@54: info@54: var Tooltip = function (element, options) { info@54: this.type = info@54: this.options = info@54: this.enabled = info@54: this.timeout = info@54: this.hoverState = info@54: this.$element = null info@54: info@54: this.init('tooltip', element, options) info@54: } info@54: info@54: Tooltip.DEFAULTS = { info@54: animation: true info@54: , placement: 'top' info@54: , selector: false info@54: , template: '
' info@54: , trigger: 'hover focus' info@54: , title: '' info@54: , delay: 0 info@54: , html: false info@54: , container: false info@54: } info@54: info@54: Tooltip.prototype.init = function (type, element, options) { info@54: this.enabled = true info@54: this.type = type info@54: this.$element = $(element) info@54: this.options = this.getOptions(options) info@54: info@54: var triggers = this.options.trigger.split(' ') info@54: info@54: for (var i = triggers.length; i--;) { info@54: var trigger = triggers[i] info@54: info@54: if (trigger == 'click') { info@54: this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) info@54: } else if (trigger != 'manual') { info@54: var eventIn = trigger == 'hover' ? 'mouseenter' : 'focus' info@54: var eventOut = trigger == 'hover' ? 'mouseleave' : 'blur' info@54: info@54: this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) info@54: this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) info@54: } info@54: } info@54: info@54: this.options.selector ? info@54: (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : info@54: this.fixTitle() info@54: } info@54: info@54: Tooltip.prototype.getDefaults = function () { info@54: return Tooltip.DEFAULTS info@54: } info@54: info@54: Tooltip.prototype.getOptions = function (options) { info@54: options = $.extend({}, this.getDefaults(), this.$element.data(), options) info@54: info@54: if (options.delay && typeof options.delay == 'number') { info@54: options.delay = { info@54: show: options.delay info@54: , hide: options.delay info@54: } info@54: } info@54: info@54: return options info@54: } info@54: info@54: Tooltip.prototype.getDelegateOptions = function () { info@54: var options = {} info@54: var defaults = this.getDefaults() info@54: info@54: this._options && $.each(this._options, function (key, value) { info@54: if (defaults[key] != value) options[key] = value info@54: }) info@54: info@54: return options info@54: } info@54: info@54: Tooltip.prototype.enter = function (obj) { info@54: var self = obj instanceof this.constructor ? info@54: obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) info@54: info@54: clearTimeout(self.timeout) info@54: info@54: self.hoverState = 'in' info@54: info@54: if (!self.options.delay || !self.options.delay.show) return self.show() info@54: info@54: self.timeout = setTimeout(function () { info@54: if (self.hoverState == 'in') self.show() info@54: }, self.options.delay.show) info@54: } info@54: info@54: Tooltip.prototype.leave = function (obj) { info@54: var self = obj instanceof this.constructor ? info@54: obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) info@54: info@54: clearTimeout(self.timeout) info@54: info@54: self.hoverState = 'out' info@54: info@54: if (!self.options.delay || !self.options.delay.hide) return self.hide() info@54: info@54: self.timeout = setTimeout(function () { info@54: if (self.hoverState == 'out') self.hide() info@54: }, self.options.delay.hide) info@54: } info@54: info@54: Tooltip.prototype.show = function () { info@54: var e = $.Event('show.bs.'+ this.type) info@54: info@54: if (this.hasContent() && this.enabled) { info@54: this.$element.trigger(e) info@54: info@54: if (e.isDefaultPrevented()) return info@54: info@54: var $tip = this.tip() info@54: info@54: this.setContent() info@54: info@54: if (this.options.animation) $tip.addClass('fade') info@54: info@54: var placement = typeof this.options.placement == 'function' ? info@54: this.options.placement.call(this, $tip[0], this.$element[0]) : info@54: this.options.placement info@54: info@54: var autoToken = /\s?auto?\s?/i info@54: var autoPlace = autoToken.test(placement) info@54: if (autoPlace) placement = placement.replace(autoToken, '') || 'top' info@54: info@54: $tip info@54: .detach() info@54: .css({ top: 0, left: 0, display: 'block' }) info@54: .addClass(placement) info@54: info@54: this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) info@54: info@54: var pos = this.getPosition() info@54: var actualWidth = $tip[0].offsetWidth info@54: var actualHeight = $tip[0].offsetHeight info@54: info@54: if (autoPlace) { info@54: var $parent = this.$element.parent() info@54: info@54: var orgPlacement = placement info@54: var docScroll = document.documentElement.scrollTop || document.body.scrollTop info@54: var parentWidth = this.options.container == 'body' ? window.innerWidth : $parent.outerWidth() info@54: var parentHeight = this.options.container == 'body' ? window.innerHeight : $parent.outerHeight() info@54: var parentLeft = this.options.container == 'body' ? 0 : $parent.offset().left info@54: info@54: placement = placement == 'bottom' && pos.top + pos.height + actualHeight - docScroll > parentHeight ? 'top' : info@54: placement == 'top' && pos.top - docScroll - actualHeight < 0 ? 'bottom' : info@54: placement == 'right' && pos.right + actualWidth > parentWidth ? 'left' : info@54: placement == 'left' && pos.left - actualWidth < parentLeft ? 'right' : info@54: placement info@54: info@54: $tip info@54: .removeClass(orgPlacement) info@54: .addClass(placement) info@54: } info@54: info@54: var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) info@54: info@54: this.applyPlacement(calculatedOffset, placement) info@54: this.$element.trigger('shown.bs.' + this.type) info@54: } info@54: } info@54: info@54: Tooltip.prototype.applyPlacement = function(offset, placement) { info@54: var replace info@54: var $tip = this.tip() info@54: var width = $tip[0].offsetWidth info@54: var height = $tip[0].offsetHeight info@54: info@54: // manually read margins because getBoundingClientRect includes difference info@54: var marginTop = parseInt($tip.css('margin-top'), 10) info@54: var marginLeft = parseInt($tip.css('margin-left'), 10) info@54: info@54: // we must check for NaN for ie 8/9 info@54: if (isNaN(marginTop)) marginTop = 0 info@54: if (isNaN(marginLeft)) marginLeft = 0 info@54: info@54: offset.top = offset.top + marginTop info@54: offset.left = offset.left + marginLeft info@54: info@54: $tip info@54: .offset(offset) info@54: .addClass('in') info@54: info@54: // check to see if placing tip in new offset caused the tip to resize itself info@54: var actualWidth = $tip[0].offsetWidth info@54: var actualHeight = $tip[0].offsetHeight info@54: info@54: if (placement == 'top' && actualHeight != height) { info@54: replace = true info@54: offset.top = offset.top + height - actualHeight info@54: } info@54: info@54: if (/bottom|top/.test(placement)) { info@54: var delta = 0 info@54: info@54: if (offset.left < 0) { info@54: delta = offset.left * -2 info@54: offset.left = 0 info@54: info@54: $tip.offset(offset) info@54: info@54: actualWidth = $tip[0].offsetWidth info@54: actualHeight = $tip[0].offsetHeight info@54: } info@54: info@54: this.replaceArrow(delta - width + actualWidth, actualWidth, 'left') info@54: } else { info@54: this.replaceArrow(actualHeight - height, actualHeight, 'top') info@54: } info@54: info@54: if (replace) $tip.offset(offset) info@54: } info@54: info@54: Tooltip.prototype.replaceArrow = function(delta, dimension, position) { info@54: this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + "%") : '') info@54: } info@54: info@54: Tooltip.prototype.setContent = function () { info@54: var $tip = this.tip() info@54: var title = this.getTitle() info@54: info@54: $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) info@54: $tip.removeClass('fade in top bottom left right') info@54: } info@54: info@54: Tooltip.prototype.hide = function () { info@54: var that = this info@54: var $tip = this.tip() info@54: var e = $.Event('hide.bs.' + this.type) info@54: info@54: function complete() { info@54: if (that.hoverState != 'in') $tip.detach() info@54: } info@54: info@54: this.$element.trigger(e) info@54: info@54: if (e.isDefaultPrevented()) return info@54: info@54: $tip.removeClass('in') info@54: info@54: $.support.transition && this.$tip.hasClass('fade') ? info@54: $tip info@54: .one($.support.transition.end, complete) info@54: .emulateTransitionEnd(150) : info@54: complete() info@54: info@54: this.$element.trigger('hidden.bs.' + this.type) info@54: info@54: return this info@54: } info@54: info@54: Tooltip.prototype.fixTitle = function () { info@54: var $e = this.$element info@54: if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { info@54: $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') info@54: } info@54: } info@54: info@54: Tooltip.prototype.hasContent = function () { info@54: return this.getTitle() info@54: } info@54: info@54: Tooltip.prototype.getPosition = function () { info@54: var el = this.$element[0] info@54: return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : { info@54: width: el.offsetWidth info@54: , height: el.offsetHeight info@54: }, this.$element.offset()) info@54: } info@54: info@54: Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { info@54: return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : info@54: placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : info@54: placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : info@54: /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } info@54: } info@54: info@54: Tooltip.prototype.getTitle = function () { info@54: var title info@54: var $e = this.$element info@54: var o = this.options info@54: info@54: title = $e.attr('data-original-title') info@54: || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) info@54: info@54: return title info@54: } info@54: info@54: Tooltip.prototype.tip = function () { info@54: return this.$tip = this.$tip || $(this.options.template) info@54: } info@54: info@54: Tooltip.prototype.arrow = function () { info@54: return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow') info@54: } info@54: info@54: Tooltip.prototype.validate = function () { info@54: if (!this.$element[0].parentNode) { info@54: this.hide() info@54: this.$element = null info@54: this.options = null info@54: } info@54: } info@54: info@54: Tooltip.prototype.enable = function () { info@54: this.enabled = true info@54: } info@54: info@54: Tooltip.prototype.disable = function () { info@54: this.enabled = false info@54: } info@54: info@54: Tooltip.prototype.toggleEnabled = function () { info@54: this.enabled = !this.enabled info@54: } info@54: info@54: Tooltip.prototype.toggle = function (e) { info@54: var self = e ? $(e.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) : this info@54: self.tip().hasClass('in') ? self.leave(self) : self.enter(self) info@54: } info@54: info@54: Tooltip.prototype.destroy = function () { info@54: this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) info@54: } info@54: info@54: info@54: // TOOLTIP PLUGIN DEFINITION info@54: // ========================= info@54: info@54: var old = $.fn.tooltip info@54: info@54: $.fn.tooltip = function (option) { info@54: return this.each(function () { info@54: var $this = $(this) info@54: var data = $this.data('bs.tooltip') info@54: var options = typeof option == 'object' && option info@54: info@54: if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) info@54: if (typeof option == 'string') data[option]() info@54: }) info@54: } info@54: info@54: $.fn.tooltip.Constructor = Tooltip info@54: info@54: info@54: // TOOLTIP NO CONFLICT info@54: // =================== info@54: info@54: $.fn.tooltip.noConflict = function () { info@54: $.fn.tooltip = old info@54: return this info@54: } info@54: info@54: }(jQuery);