Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap-rubygem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/bootstrap/tooltip.js')
-rw-r--r--assets/javascripts/bootstrap/tooltip.js929
1 files changed, 508 insertions, 421 deletions
diff --git a/assets/javascripts/bootstrap/tooltip.js b/assets/javascripts/bootstrap/tooltip.js
index c3fe4b0..a1bd768 100644
--- a/assets/javascripts/bootstrap/tooltip.js
+++ b/assets/javascripts/bootstrap/tooltip.js
@@ -1,514 +1,601 @@
-/* ========================================================================
- * Bootstrap: tooltip.js v3.3.5
- * http://getbootstrap.com/javascript/#tooltip
- * Inspired by the original jQuery.tipsy by Jason Frame
- * ========================================================================
- * Copyright 2011-2015 Twitter, Inc.
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
- * ======================================================================== */
-
-
-+function ($) {
- 'use strict';
-
- // TOOLTIP PUBLIC CLASS DEFINITION
- // ===============================
-
- var Tooltip = function (element, options) {
- this.type = null
- this.options = null
- this.enabled = null
- this.timeout = null
- this.hoverState = null
- this.$element = null
- this.inState = null
+'use strict';
- this.init('tooltip', element, options)
- }
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
- Tooltip.VERSION = '3.3.5'
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
- Tooltip.TRANSITION_DURATION = 150
-
- Tooltip.DEFAULTS = {
+/**
+ * --------------------------------------------------------------------------
+ * Bootstrap (v4.0.0): tooltip.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ * --------------------------------------------------------------------------
+ */
+
+var Tooltip = (function ($) {
+
+ /**
+ * ------------------------------------------------------------------------
+ * Constants
+ * ------------------------------------------------------------------------
+ */
+
+ var NAME = 'tooltip';
+ var VERSION = '4.0.0';
+ var DATA_KEY = 'bs.tooltip';
+ var EVENT_KEY = '.' + DATA_KEY;
+ var JQUERY_NO_CONFLICT = $.fn[NAME];
+ var TRANSITION_DURATION = 150;
+ var CLASS_PREFIX = 'bs-tether';
+
+ var Default = {
animation: true,
- placement: 'top',
- selector: false,
- template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
+ template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div></div>',
trigger: 'hover focus',
title: '',
delay: 0,
html: false,
- container: false,
- viewport: {
- selector: 'body',
- padding: 0
- }
- }
-
- Tooltip.prototype.init = function (type, element, options) {
- this.enabled = true
- this.type = type
- this.$element = $(element)
- this.options = this.getOptions(options)
- this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))
- this.inState = { click: false, hover: false, focus: false }
-
- if (this.$element[0] instanceof document.constructor && !this.options.selector) {
- throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')
+ selector: false,
+ placement: 'top',
+ offset: '0 0',
+ constraints: []
+ };
+
+ var DefaultType = {
+ animation: 'boolean',
+ template: 'string',
+ title: '(string|function)',
+ trigger: 'string',
+ delay: '(number|object)',
+ html: 'boolean',
+ selector: '(string|boolean)',
+ placement: '(string|function)',
+ offset: 'string',
+ constraints: 'array'
+ };
+
+ var AttachmentMap = {
+ TOP: 'bottom center',
+ RIGHT: 'middle left',
+ BOTTOM: 'top center',
+ LEFT: 'middle right'
+ };
+
+ var HoverState = {
+ IN: 'in',
+ OUT: 'out'
+ };
+
+ var Event = {
+ HIDE: 'hide' + EVENT_KEY,
+ HIDDEN: 'hidden' + EVENT_KEY,
+ SHOW: 'show' + EVENT_KEY,
+ SHOWN: 'shown' + EVENT_KEY,
+ INSERTED: 'inserted' + EVENT_KEY,
+ CLICK: 'click' + EVENT_KEY,
+ FOCUSIN: 'focusin' + EVENT_KEY,
+ FOCUSOUT: 'focusout' + EVENT_KEY,
+ MOUSEENTER: 'mouseenter' + EVENT_KEY,
+ MOUSELEAVE: 'mouseleave' + EVENT_KEY
+ };
+
+ var ClassName = {
+ FADE: 'fade',
+ IN: 'in'
+ };
+
+ var Selector = {
+ TOOLTIP: '.tooltip',
+ TOOLTIP_INNER: '.tooltip-inner'
+ };
+
+ var TetherClass = {
+ element: false,
+ enabled: false
+ };
+
+ var Trigger = {
+ HOVER: 'hover',
+ FOCUS: 'focus',
+ CLICK: 'click',
+ MANUAL: 'manual'
+ };
+
+ /**
+ * ------------------------------------------------------------------------
+ * Class Definition
+ * ------------------------------------------------------------------------
+ */
+
+ var Tooltip = (function () {
+ function Tooltip(element, config) {
+ _classCallCheck(this, Tooltip);
+
+ // private
+ this._isEnabled = true;
+ this._timeout = 0;
+ this._hoverState = '';
+ this._activeTrigger = {};
+ this._tether = null;
+
+ // protected
+ this.element = element;
+ this.config = this._getConfig(config);
+ this.tip = null;
+
+ this._setListeners();
}
- var triggers = this.options.trigger.split(' ')
-
- for (var i = triggers.length; i--;) {
- var trigger = triggers[i]
-
- if (trigger == 'click') {
- this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
- } else if (trigger != 'manual') {
- var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
- var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
-
- 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))
- }
- }
+ /**
+ * ------------------------------------------------------------------------
+ * jQuery
+ * ------------------------------------------------------------------------
+ */
- this.options.selector ?
- (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
- this.fixTitle()
- }
+ // getters
- Tooltip.prototype.getDefaults = function () {
- return Tooltip.DEFAULTS
- }
+ _createClass(Tooltip, [{
+ key: 'enable',
- Tooltip.prototype.getOptions = function (options) {
- options = $.extend({}, this.getDefaults(), this.$element.data(), options)
+ // public
- if (options.delay && typeof options.delay == 'number') {
- options.delay = {
- show: options.delay,
- hide: options.delay
+ value: function enable() {
+ this._isEnabled = true;
}
- }
-
- return options
- }
-
- Tooltip.prototype.getDelegateOptions = function () {
- var options = {}
- var defaults = this.getDefaults()
+ }, {
+ key: 'disable',
+ value: function disable() {
+ this._isEnabled = false;
+ }
+ }, {
+ key: 'toggleEnabled',
+ value: function toggleEnabled() {
+ this._isEnabled = !this._isEnabled;
+ }
+ }, {
+ key: 'toggle',
+ value: function toggle(event) {
+ if (event) {
+ var dataKey = this.constructor.DATA_KEY;
+ var context = $(event.currentTarget).data(dataKey);
+
+ if (!context) {
+ context = new this.constructor(event.currentTarget, this._getDelegateConfig());
+ $(event.currentTarget).data(dataKey, context);
+ }
+
+ context._activeTrigger.click = !context._activeTrigger.click;
+
+ if (context._isWithActiveTrigger()) {
+ context._enter(null, context);
+ } else {
+ context._leave(null, context);
+ }
+ } else {
+
+ if ($(this.getTipElement()).hasClass(ClassName.IN)) {
+ this._leave(null, this);
+ return;
+ }
+
+ this._enter(null, this);
+ }
+ }
+ }, {
+ key: 'dispose',
+ value: function dispose() {
+ clearTimeout(this._timeout);
- this._options && $.each(this._options, function (key, value) {
- if (defaults[key] != value) options[key] = value
- })
+ this.cleanupTether();
- return options
- }
+ $.removeData(this.element, this.constructor.DATA_KEY);
- Tooltip.prototype.enter = function (obj) {
- var self = obj instanceof this.constructor ?
- obj : $(obj.currentTarget).data('bs.' + this.type)
+ $(this.element).off(this.constructor.EVENT_KEY);
- if (!self) {
- self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
- $(obj.currentTarget).data('bs.' + this.type, self)
- }
+ if (this.tip) {
+ $(this.tip).remove();
+ }
- if (obj instanceof $.Event) {
- self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
- }
+ this._isEnabled = null;
+ this._timeout = null;
+ this._hoverState = null;
+ this._activeTrigger = null;
+ this._tether = null;
- if (self.tip().hasClass('in') || self.hoverState == 'in') {
- self.hoverState = 'in'
- return
- }
+ this.element = null;
+ this.config = null;
+ this.tip = null;
+ }
+ }, {
+ key: 'show',
+ value: function show() {
+ var _this = this;
- clearTimeout(self.timeout)
+ var showEvent = $.Event(this.constructor.Event.SHOW);
- self.hoverState = 'in'
+ if (this.isWithContent() && this._isEnabled) {
+ $(this.element).trigger(showEvent);
- if (!self.options.delay || !self.options.delay.show) return self.show()
+ var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element);
- self.timeout = setTimeout(function () {
- if (self.hoverState == 'in') self.show()
- }, self.options.delay.show)
- }
+ if (showEvent.isDefaultPrevented() || !isInTheDom) {
+ return;
+ }
- Tooltip.prototype.isInStateTrue = function () {
- for (var key in this.inState) {
- if (this.inState[key]) return true
- }
+ var tip = this.getTipElement();
+ var tipId = Util.getUID(this.constructor.NAME);
- return false
- }
+ tip.setAttribute('id', tipId);
+ this.element.setAttribute('aria-describedby', tipId);
- Tooltip.prototype.leave = function (obj) {
- var self = obj instanceof this.constructor ?
- obj : $(obj.currentTarget).data('bs.' + this.type)
+ this.setContent();
- if (!self) {
- self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
- $(obj.currentTarget).data('bs.' + this.type, self)
- }
+ if (this.config.animation) {
+ $(tip).addClass(ClassName.FADE);
+ }
- if (obj instanceof $.Event) {
- self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
- }
+ var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
- if (self.isInStateTrue()) return
+ var attachment = this._getAttachment(placement);
- clearTimeout(self.timeout)
+ $(tip).data(this.constructor.DATA_KEY, this).appendTo(document.body);
- self.hoverState = 'out'
+ $(this.element).trigger(this.constructor.Event.INSERTED);
- if (!self.options.delay || !self.options.delay.hide) return self.hide()
+ this._tether = new Tether({
+ attachment: attachment,
+ element: tip,
+ target: this.element,
+ classes: TetherClass,
+ classPrefix: CLASS_PREFIX,
+ offset: this.config.offset,
+ constraints: this.config.constraints
+ });
- self.timeout = setTimeout(function () {
- if (self.hoverState == 'out') self.hide()
- }, self.options.delay.hide)
- }
+ Util.reflow(tip);
+ this._tether.position();
- Tooltip.prototype.show = function () {
- var e = $.Event('show.bs.' + this.type)
+ $(tip).addClass(ClassName.IN);
- if (this.hasContent() && this.enabled) {
- this.$element.trigger(e)
+ var complete = function complete() {
+ var prevHoverState = _this._hoverState;
+ _this._hoverState = null;
- var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
- if (e.isDefaultPrevented() || !inDom) return
- var that = this
+ $(_this.element).trigger(_this.constructor.Event.SHOWN);
- var $tip = this.tip()
+ if (prevHoverState === HoverState.OUT) {
+ _this._leave(null, _this);
+ }
+ };
- var tipId = this.getUID(this.type)
+ if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
+ $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
+ return;
+ }
- this.setContent()
- $tip.attr('id', tipId)
- this.$element.attr('aria-describedby', tipId)
+ complete();
+ }
+ }
+ }, {
+ key: 'hide',
+ value: function hide(callback) {
+ var _this2 = this;
- if (this.options.animation) $tip.addClass('fade')
+ var tip = this.getTipElement();
+ var hideEvent = $.Event(this.constructor.Event.HIDE);
+ var complete = function complete() {
+ if (_this2._hoverState !== HoverState.IN && tip.parentNode) {
+ tip.parentNode.removeChild(tip);
+ }
- var placement = typeof this.options.placement == 'function' ?
- this.options.placement.call(this, $tip[0], this.$element[0]) :
- this.options.placement
+ _this2.element.removeAttribute('aria-describedby');
+ $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);
+ _this2.cleanupTether();
- var autoToken = /\s?auto?\s?/i
- var autoPlace = autoToken.test(placement)
- if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
+ if (callback) {
+ callback();
+ }
+ };
- $tip
- .detach()
- .css({ top: 0, left: 0, display: 'block' })
- .addClass(placement)
- .data('bs.' + this.type, this)
+ $(this.element).trigger(hideEvent);
- this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
- this.$element.trigger('inserted.bs.' + this.type)
+ if (hideEvent.isDefaultPrevented()) {
+ return;
+ }
- var pos = this.getPosition()
- var actualWidth = $tip[0].offsetWidth
- var actualHeight = $tip[0].offsetHeight
+ $(tip).removeClass(ClassName.IN);
- if (autoPlace) {
- var orgPlacement = placement
- var viewportDim = this.getPosition(this.$viewport)
+ if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
- placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' :
- placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' :
- placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' :
- placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' :
- placement
+ $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
+ } else {
+ complete();
+ }
- $tip
- .removeClass(orgPlacement)
- .addClass(placement)
+ this._hoverState = '';
}
- var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
-
- this.applyPlacement(calculatedOffset, placement)
-
- var complete = function () {
- var prevHoverState = that.hoverState
- that.$element.trigger('shown.bs.' + that.type)
- that.hoverState = null
+ // protected
- if (prevHoverState == 'out') that.leave(that)
+ }, {
+ key: 'isWithContent',
+ value: function isWithContent() {
+ return Boolean(this.getTitle());
}
-
- $.support.transition && this.$tip.hasClass('fade') ?
- $tip
- .one('bsTransitionEnd', complete)
- .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
- complete()
- }
- }
-
- Tooltip.prototype.applyPlacement = function (offset, placement) {
- var $tip = this.tip()
- var width = $tip[0].offsetWidth
- var height = $tip[0].offsetHeight
-
- // manually read margins because getBoundingClientRect includes difference
- var marginTop = parseInt($tip.css('margin-top'), 10)
- var marginLeft = parseInt($tip.css('margin-left'), 10)
-
- // we must check for NaN for ie 8/9
- if (isNaN(marginTop)) marginTop = 0
- if (isNaN(marginLeft)) marginLeft = 0
-
- offset.top += marginTop
- offset.left += marginLeft
-
- // $.fn.offset doesn't round pixel values
- // so we use setOffset directly with our own function B-0
- $.offset.setOffset($tip[0], $.extend({
- using: function (props) {
- $tip.css({
- top: Math.round(props.top),
- left: Math.round(props.left)
- })
+ }, {
+ key: 'getTipElement',
+ value: function getTipElement() {
+ return this.tip = this.tip || $(this.config.template)[0];
}
- }, offset), 0)
+ }, {
+ key: 'setContent',
+ value: function setContent() {
+ var tip = this.getTipElement();
+ var title = this.getTitle();
+ var method = this.config.html ? 'innerHTML' : 'innerText';
- $tip.addClass('in')
+ $(tip).find(Selector.TOOLTIP_INNER)[0][method] = title;
- // check to see if placing tip in new offset caused the tip to resize itself
- var actualWidth = $tip[0].offsetWidth
- var actualHeight = $tip[0].offsetHeight
+ $(tip).removeClass(ClassName.FADE).removeClass(ClassName.IN);
- if (placement == 'top' && actualHeight != height) {
- offset.top = offset.top + height - actualHeight
- }
+ this.cleanupTether();
+ }
+ }, {
+ key: 'getTitle',
+ value: function getTitle() {
+ var title = this.element.getAttribute('data-original-title');
- var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
+ if (!title) {
+ title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
+ }
- if (delta.left) offset.left += delta.left
- else offset.top += delta.top
+ return title;
+ }
+ }, {
+ key: 'cleanupTether',
+ value: function cleanupTether() {
+ if (this._tether) {
+ this._tether.destroy();
+
+ // clean up after tether's junk classes
+ // remove after they fix issue
+ // (https://github.com/HubSpot/tether/issues/36)
+ $(this.element).removeClass(this._removeTetherClasses);
+ $(this.tip).removeClass(this._removeTetherClasses);
+ }
+ }
- var isVertical = /top|bottom/.test(placement)
- var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
- var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
+ // private
- $tip.offset(offset)
- this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
- }
+ }, {
+ key: '_getAttachment',
+ value: function _getAttachment(placement) {
+ return AttachmentMap[placement.toUpperCase()];
+ }
+ }, {
+ key: '_setListeners',
+ value: function _setListeners() {
+ var _this3 = this;
+
+ var triggers = this.config.trigger.split(' ');
+
+ triggers.forEach(function (trigger) {
+ if (trigger === 'click') {
+ $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, $.proxy(_this3.toggle, _this3));
+ } else if (trigger !== Trigger.MANUAL) {
+ var eventIn = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSEENTER : _this3.constructor.Event.FOCUSIN;
+ var eventOut = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSELEAVE : _this3.constructor.Event.FOCUSOUT;
+
+ $(_this3.element).on(eventIn, _this3.config.selector, $.proxy(_this3._enter, _this3)).on(eventOut, _this3.config.selector, $.proxy(_this3._leave, _this3));
+ }
+ });
+
+ if (this.config.selector) {
+ this.config = $.extend({}, this.config, {
+ trigger: 'manual',
+ selector: ''
+ });
+ } else {
+ this._fixTitle();
+ }
+ }
+ }, {
+ key: '_removeTetherClasses',
+ value: function _removeTetherClasses(i, css) {
+ return ((css.baseVal || css).match(new RegExp('(^|\\s)' + CLASS_PREFIX + '-\\S+', 'g')) || []).join(' ');
+ }
+ }, {
+ key: '_fixTitle',
+ value: function _fixTitle() {
+ var titleType = typeof this.element.getAttribute('data-original-title');
+ if (this.element.getAttribute('title') || titleType !== 'string') {
+ this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
+ this.element.setAttribute('title', '');
+ }
+ }
+ }, {
+ key: '_enter',
+ value: function _enter(event, context) {
+ var dataKey = this.constructor.DATA_KEY;
- Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) {
- this.arrow()
- .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
- .css(isVertical ? 'top' : 'left', '')
- }
+ context = context || $(event.currentTarget).data(dataKey);
- Tooltip.prototype.setContent = function () {
- var $tip = this.tip()
- var title = this.getTitle()
+ if (!context) {
+ context = new this.constructor(event.currentTarget, this._getDelegateConfig());
+ $(event.currentTarget).data(dataKey, context);
+ }
- $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
- $tip.removeClass('fade in top bottom left right')
- }
+ if (event) {
+ context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
+ }
- Tooltip.prototype.hide = function (callback) {
- var that = this
- var $tip = $(this.$tip)
- var e = $.Event('hide.bs.' + this.type)
+ if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
+ context._hoverState = HoverState.IN;
+ return;
+ }
- function complete() {
- if (that.hoverState != 'in') $tip.detach()
- that.$element
- .removeAttr('aria-describedby')
- .trigger('hidden.bs.' + that.type)
- callback && callback()
- }
+ clearTimeout(context._timeout);
- this.$element.trigger(e)
+ context._hoverState = HoverState.IN;
- if (e.isDefaultPrevented()) return
+ if (!context.config.delay || !context.config.delay.show) {
+ context.show();
+ return;
+ }
- $tip.removeClass('in')
+ context._timeout = setTimeout(function () {
+ if (context._hoverState === HoverState.IN) {
+ context.show();
+ }
+ }, context.config.delay.show);
+ }
+ }, {
+ key: '_leave',
+ value: function _leave(event, context) {
+ var dataKey = this.constructor.DATA_KEY;
- $.support.transition && $tip.hasClass('fade') ?
- $tip
- .one('bsTransitionEnd', complete)
- .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
- complete()
+ context = context || $(event.currentTarget).data(dataKey);
- this.hoverState = null
+ if (!context) {
+ context = new this.constructor(event.currentTarget, this._getDelegateConfig());
+ $(event.currentTarget).data(dataKey, context);
+ }
- return this
- }
+ if (event) {
+ context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
+ }
- Tooltip.prototype.fixTitle = function () {
- var $e = this.$element
- if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') {
- $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
- }
- }
+ if (context._isWithActiveTrigger()) {
+ return;
+ }
- Tooltip.prototype.hasContent = function () {
- return this.getTitle()
- }
+ clearTimeout(context._timeout);
- Tooltip.prototype.getPosition = function ($element) {
- $element = $element || this.$element
+ context._hoverState = HoverState.OUT;
- var el = $element[0]
- var isBody = el.tagName == 'BODY'
+ if (!context.config.delay || !context.config.delay.hide) {
+ context.hide();
+ return;
+ }
- var elRect = el.getBoundingClientRect()
- if (elRect.width == null) {
- // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
- elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
- }
- var elOffset = isBody ? { top: 0, left: 0 } : $element.offset()
- var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
- var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
-
- return $.extend({}, elRect, scroll, outerDims, elOffset)
- }
-
- Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
- return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
- placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
- placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
- /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
-
- }
-
- Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
- var delta = { top: 0, left: 0 }
- if (!this.$viewport) return delta
-
- var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
- var viewportDimensions = this.getPosition(this.$viewport)
-
- if (/right|left/.test(placement)) {
- var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
- var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
- if (topEdgeOffset < viewportDimensions.top) { // top overflow
- delta.top = viewportDimensions.top - topEdgeOffset
- } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
- delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
+ context._timeout = setTimeout(function () {
+ if (context._hoverState === HoverState.OUT) {
+ context.hide();
+ }
+ }, context.config.delay.hide);
}
- } else {
- var leftEdgeOffset = pos.left - viewportPadding
- var rightEdgeOffset = pos.left + viewportPadding + actualWidth
- if (leftEdgeOffset < viewportDimensions.left) { // left overflow
- delta.left = viewportDimensions.left - leftEdgeOffset
- } else if (rightEdgeOffset > viewportDimensions.right) { // right overflow
- delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
+ }, {
+ key: '_isWithActiveTrigger',
+ value: function _isWithActiveTrigger() {
+ for (var trigger in this._activeTrigger) {
+ if (this._activeTrigger[trigger]) {
+ return true;
+ }
+ }
+
+ return false;
}
- }
-
- return delta
- }
-
- Tooltip.prototype.getTitle = function () {
- var title
- var $e = this.$element
- var o = this.options
+ }, {
+ key: '_getConfig',
+ value: function _getConfig(config) {
+ config = $.extend({}, this.constructor.Default, $(this.element).data(), config);
- title = $e.attr('data-original-title')
- || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
+ if (config.delay && typeof config.delay === 'number') {
+ config.delay = {
+ show: config.delay,
+ hide: config.delay
+ };
+ }
- return title
- }
+ Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
- Tooltip.prototype.getUID = function (prefix) {
- do prefix += ~~(Math.random() * 1000000)
- while (document.getElementById(prefix))
- return prefix
- }
-
- Tooltip.prototype.tip = function () {
- if (!this.$tip) {
- this.$tip = $(this.options.template)
- if (this.$tip.length != 1) {
- throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!')
- }
- }
- return this.$tip
- }
-
- Tooltip.prototype.arrow = function () {
- return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
- }
-
- Tooltip.prototype.enable = function () {
- this.enabled = true
- }
-
- Tooltip.prototype.disable = function () {
- this.enabled = false
- }
-
- Tooltip.prototype.toggleEnabled = function () {
- this.enabled = !this.enabled
- }
-
- Tooltip.prototype.toggle = function (e) {
- var self = this
- if (e) {
- self = $(e.currentTarget).data('bs.' + this.type)
- if (!self) {
- self = new this.constructor(e.currentTarget, this.getDelegateOptions())
- $(e.currentTarget).data('bs.' + this.type, self)
+ return config;
}
- }
-
- if (e) {
- self.inState.click = !self.inState.click
- if (self.isInStateTrue()) self.enter(self)
- else self.leave(self)
- } else {
- self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
- }
- }
-
- Tooltip.prototype.destroy = function () {
- var that = this
- clearTimeout(this.timeout)
- this.hide(function () {
- that.$element.off('.' + that.type).removeData('bs.' + that.type)
- if (that.$tip) {
- that.$tip.detach()
+ }, {
+ key: '_getDelegateConfig',
+ value: function _getDelegateConfig() {
+ var config = {};
+
+ if (this.config) {
+ for (var key in this.config) {
+ if (this.constructor.Default[key] !== this.config[key]) {
+ config[key] = this.config[key];
+ }
+ }
+ }
+
+ return config;
}
- that.$tip = null
- that.$arrow = null
- that.$viewport = null
- })
- }
-
-
- // TOOLTIP PLUGIN DEFINITION
- // =========================
- function Plugin(option) {
- return this.each(function () {
- var $this = $(this)
- var data = $this.data('bs.tooltip')
- var options = typeof option == 'object' && option
+ // static
- if (!data && /destroy|hide/.test(option)) return
- if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
- if (typeof option == 'string') data[option]()
- })
- }
+ }], [{
+ key: '_jQueryInterface',
+ value: function _jQueryInterface(config) {
+ return this.each(function () {
+ var data = $(this).data(DATA_KEY);
+ var _config = typeof config === 'object' ? config : null;
- var old = $.fn.tooltip
+ if (!data && /destroy|hide/.test(config)) {
+ return;
+ }
- $.fn.tooltip = Plugin
- $.fn.tooltip.Constructor = Tooltip
+ if (!data) {
+ data = new Tooltip(this, _config);
+ $(this).data(DATA_KEY, data);
+ }
+ if (typeof config === 'string') {
+ data[config]();
+ }
+ });
+ }
+ }, {
+ key: 'VERSION',
+ get: function get() {
+ return VERSION;
+ }
+ }, {
+ key: 'Default',
+ get: function get() {
+ return Default;
+ }
+ }, {
+ key: 'NAME',
+ get: function get() {
+ return NAME;
+ }
+ }, {
+ key: 'DATA_KEY',
+ get: function get() {
+ return DATA_KEY;
+ }
+ }, {
+ key: 'Event',
+ get: function get() {
+ return Event;
+ }
+ }, {
+ key: 'EVENT_KEY',
+ get: function get() {
+ return EVENT_KEY;
+ }
+ }, {
+ key: 'DefaultType',
+ get: function get() {
+ return DefaultType;
+ }
+ }]);
- // TOOLTIP NO CONFLICT
- // ===================
+ return Tooltip;
+ })();
- $.fn.tooltip.noConflict = function () {
- $.fn.tooltip = old
- return this
- }
+ $.fn[NAME] = Tooltip._jQueryInterface;
+ $.fn[NAME].Constructor = Tooltip;
+ $.fn[NAME].noConflict = function () {
+ $.fn[NAME] = JQUERY_NO_CONFLICT;
+ return Tooltip._jQueryInterface;
+ };
-}(jQuery);
+ return Tooltip;
+})(jQuery);
+//# sourceMappingURL=tooltip.js.map