tooltip.js 19.4 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
2
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

Mark Otto's avatar
dist    
Mark Otto committed
3
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); } }
Mark Otto's avatar
dist    
Mark Otto committed
4

Mark Otto's avatar
dist    
Mark Otto committed
5
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
6
7
8

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
9
 * Bootstrap (v4.0.0): tooltip.js
10
11
12
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */
Mark Otto's avatar
dist    
Mark Otto committed
13
var Tooltip = function ($) {
14
15
16
17
18
19
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */
  var NAME = 'tooltip';
Mark Otto's avatar
Mark Otto committed
20
  var VERSION = '4.0.0';
21
  var DATA_KEY = 'bs.tooltip';
Mark Otto's avatar
dist    
Mark Otto committed
22
  var EVENT_KEY = "." + DATA_KEY;
23
24
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  var TRANSITION_DURATION = 150;
Johann-S's avatar
build    
Johann-S committed
25
  var CLASS_PREFIX = 'bs-tooltip';
Mark Otto's avatar
dist    
Mark Otto committed
26
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
fat's avatar
fat committed
27
28
29
  var DefaultType = {
    animation: 'boolean',
    template: 'string',
XhmikosR's avatar
XhmikosR committed
30
    title: '(string|element|function)',
fat's avatar
fat committed
31
32
33
34
35
    trigger: 'string',
    delay: '(number|object)',
    html: 'boolean',
    selector: '(string|boolean)',
    placement: '(string|function)',
Johann-S's avatar
build    
Johann-S committed
36
37
    offset: '(number|string)',
    container: '(string|element|boolean)',
Mark Otto's avatar
dist    
Mark Otto committed
38
39
    fallbackPlacement: '(string|array)',
    boundary: '(string|element)'
40
  };
fat's avatar
fat committed
41
  var AttachmentMap = {
Mark Otto's avatar
build    
Mark Otto committed
42
    AUTO: 'auto',
Johann-S's avatar
build    
Johann-S committed
43
44
45
46
47
48
49
    TOP: 'top',
    RIGHT: 'right',
    BOTTOM: 'bottom',
    LEFT: 'left'
  };
  var Default = {
    animation: true,
Mark Otto's avatar
build    
Mark Otto committed
50
    template: '<div class="tooltip" role="tooltip">' + '<div class="arrow"></div>' + '<div class="tooltip-inner"></div></div>',
Johann-S's avatar
build    
Johann-S committed
51
52
53
54
55
56
57
58
    trigger: 'hover focus',
    title: '',
    delay: 0,
    html: false,
    selector: false,
    placement: 'top',
    offset: 0,
    container: false,
Mark Otto's avatar
dist    
Mark Otto committed
59
60
    fallbackPlacement: 'flip',
    boundary: 'scrollParent'
61
62
  };
  var HoverState = {
Mark Otto's avatar
grunt    
Mark Otto committed
63
    SHOW: 'show',
64
65
66
    OUT: 'out'
  };
  var Event = {
Mark Otto's avatar
dist    
Mark Otto committed
67
68
69
70
71
72
73
74
75
76
    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
77
78
79
  };
  var ClassName = {
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
80
    SHOW: 'show'
81
82
83
  };
  var Selector = {
    TOOLTIP: '.tooltip',
Mark Otto's avatar
build    
Mark Otto committed
84
85
    TOOLTIP_INNER: '.tooltip-inner',
    ARROW: '.arrow'
86
  };
fat's avatar
fat committed
87
88
89
90
91
  var Trigger = {
    HOVER: 'hover',
    FOCUS: 'focus',
    CLICK: 'click',
    MANUAL: 'manual'
Mark Otto's avatar
dist    
Mark Otto committed
92
93
94
95
96
    /**
     * ------------------------------------------------------------------------
     * Class Definition
     * ------------------------------------------------------------------------
     */
97

Mark Otto's avatar
dist    
Mark Otto committed
98
  };
99

Mark Otto's avatar
dist    
Mark Otto committed
100
101
102
103
  var Tooltip =
  /*#__PURE__*/
  function () {
    function Tooltip(element, config) {
Mark Otto's avatar
dist    
Mark Otto committed
104
105
106
107
108
      /**
       * Check for Popper dependency
       * Popper - https://popper.js.org
       */
      if (typeof Popper === 'undefined') {
Mark Otto's avatar
dist    
Mark Otto committed
109
        throw new TypeError('Bootstrap tooltips require Popper.js (https://popper.js.org)');
Mark Otto's avatar
dist    
Mark Otto committed
110
111
112
      } // private


113
114
115
116
      this._isEnabled = true;
      this._timeout = 0;
      this._hoverState = '';
      this._activeTrigger = {};
Mark Otto's avatar
dist    
Mark Otto committed
117
      this._popper = null; // Protected
118
119
120
121
122
123

      this.element = element;
      this.config = this._getConfig(config);
      this.tip = null;

      this._setListeners();
Mark Otto's avatar
dist    
Mark Otto committed
124
    } // Getters
125

Jacob Thornton's avatar
Jacob Thornton committed
126

Mark Otto's avatar
dist    
Mark Otto committed
127
    var _proto = Tooltip.prototype;
128

Mark Otto's avatar
dist    
Mark Otto committed
129
    // Public
Mark Otto's avatar
dist    
Mark Otto committed
130
131
132
    _proto.enable = function enable() {
      this._isEnabled = true;
    };
133

Mark Otto's avatar
dist    
Mark Otto committed
134
135
136
    _proto.disable = function disable() {
      this._isEnabled = false;
    };
137

Mark Otto's avatar
dist    
Mark Otto committed
138
139
140
141
142
143
144
    _proto.toggleEnabled = function toggleEnabled() {
      this._isEnabled = !this._isEnabled;
    };

    _proto.toggle = function toggle(event) {
      if (!this._isEnabled) {
        return;
Mark Otto's avatar
dist    
Mark Otto committed
145
      }
Mark Otto's avatar
Mark Otto committed
146

Mark Otto's avatar
dist    
Mark Otto committed
147
148
149
      if (event) {
        var dataKey = this.constructor.DATA_KEY;
        var context = $(event.currentTarget).data(dataKey);
Mark Otto's avatar
Mark Otto committed
150

Mark Otto's avatar
dist    
Mark Otto committed
151
152
153
154
        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }
fat's avatar
fat committed
155

Mark Otto's avatar
dist    
Mark Otto committed
156
        context._activeTrigger.click = !context._activeTrigger.click;
fat's avatar
fat committed
157

Mark Otto's avatar
dist    
Mark Otto committed
158
159
        if (context._isWithActiveTrigger()) {
          context._enter(null, context);
Mark Otto's avatar
grunt    
Mark Otto committed
160
        } else {
Mark Otto's avatar
dist    
Mark Otto committed
161
162
163
164
165
          context._leave(null, context);
        }
      } else {
        if ($(this.getTipElement()).hasClass(ClassName.SHOW)) {
          this._leave(null, this);
fat's avatar
fat committed
166

Mark Otto's avatar
dist    
Mark Otto committed
167
          return;
Mark Otto's avatar
dist    
Mark Otto committed
168
        }
169

Mark Otto's avatar
dist    
Mark Otto committed
170
171
172
        this._enter(null, this);
      }
    };
173

Mark Otto's avatar
dist    
Mark Otto committed
174
175
176
177
178
    _proto.dispose = function dispose() {
      clearTimeout(this._timeout);
      $.removeData(this.element, this.constructor.DATA_KEY);
      $(this.element).off(this.constructor.EVENT_KEY);
      $(this.element).closest('.modal').off('hide.bs.modal');
179

Mark Otto's avatar
dist    
Mark Otto committed
180
181
182
      if (this.tip) {
        $(this.tip).remove();
      }
183

Mark Otto's avatar
dist    
Mark Otto committed
184
185
186
187
      this._isEnabled = null;
      this._timeout = null;
      this._hoverState = null;
      this._activeTrigger = null;
188

Mark Otto's avatar
dist    
Mark Otto committed
189
190
      if (this._popper !== null) {
        this._popper.destroy();
Mark Otto's avatar
grunt    
Mark Otto committed
191
      }
192

Mark Otto's avatar
dist    
Mark Otto committed
193
194
195
196
197
      this._popper = null;
      this.element = null;
      this.config = null;
      this.tip = null;
    };
198

Mark Otto's avatar
dist    
Mark Otto committed
199
200
    _proto.show = function show() {
      var _this = this;
201

Mark Otto's avatar
dist    
Mark Otto committed
202
203
204
      if ($(this.element).css('display') === 'none') {
        throw new Error('Please use show on visible elements');
      }
205

Mark Otto's avatar
dist    
Mark Otto committed
206
      var showEvent = $.Event(this.constructor.Event.SHOW);
207

Mark Otto's avatar
dist    
Mark Otto committed
208
209
210
      if (this.isWithContent() && this._isEnabled) {
        $(this.element).trigger(showEvent);
        var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element);
211

Mark Otto's avatar
dist    
Mark Otto committed
212
213
214
        if (showEvent.isDefaultPrevented() || !isInTheDom) {
          return;
        }
215

Mark Otto's avatar
dist    
Mark Otto committed
216
217
218
219
220
        var tip = this.getTipElement();
        var tipId = Util.getUID(this.constructor.NAME);
        tip.setAttribute('id', tipId);
        this.element.setAttribute('aria-describedby', tipId);
        this.setContent();
221

Mark Otto's avatar
dist    
Mark Otto committed
222
223
224
        if (this.config.animation) {
          $(tip).addClass(ClassName.FADE);
        }
225

Mark Otto's avatar
dist    
Mark Otto committed
226
        var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
Mark Otto's avatar
grunt    
Mark Otto committed
227

Mark Otto's avatar
dist    
Mark Otto committed
228
        var attachment = this._getAttachment(placement);
Mark Otto's avatar
grunt    
Mark Otto committed
229

Mark Otto's avatar
dist    
Mark Otto committed
230
231
232
        this.addAttachmentClass(attachment);
        var container = this.config.container === false ? document.body : $(this.config.container);
        $(tip).data(this.constructor.DATA_KEY, this);
Mark Otto's avatar
Mark Otto committed
233

Mark Otto's avatar
dist    
Mark Otto committed
234
235
236
        if (!$.contains(this.element.ownerDocument.documentElement, this.tip)) {
          $(tip).appendTo(container);
        }
Mark Otto's avatar
grunt    
Mark Otto committed
237

Mark Otto's avatar
dist    
Mark Otto committed
238
239
240
241
242
243
        $(this.element).trigger(this.constructor.Event.INSERTED);
        this._popper = new Popper(this.element, tip, {
          placement: attachment,
          modifiers: {
            offset: {
              offset: this.config.offset
Johann-S's avatar
build    
Johann-S committed
244
            },
Mark Otto's avatar
dist    
Mark Otto committed
245
246
            flip: {
              behavior: this.config.fallbackPlacement
Mark Otto's avatar
build    
Mark Otto committed
247
            },
Mark Otto's avatar
dist    
Mark Otto committed
248
249
            arrow: {
              element: Selector.ARROW
Mark Otto's avatar
dist    
Mark Otto committed
250
251
252
            },
            preventOverflow: {
              boundariesElement: this.config.boundary
Mark Otto's avatar
dist    
Mark Otto committed
253
254
255
256
            }
          },
          onCreate: function onCreate(data) {
            if (data.originalPlacement !== data.placement) {
Johann-S's avatar
build    
Johann-S committed
257
258
              _this._handlePopperPlacementChange(data);
            }
Mark Otto's avatar
dist    
Mark Otto committed
259
260
261
          },
          onUpdate: function onUpdate(data) {
            _this._handlePopperPlacementChange(data);
Johann-S's avatar
build    
Johann-S committed
262
          }
Mark Otto's avatar
dist    
Mark Otto committed
263
        });
Mark Otto's avatar
dist    
Mark Otto committed
264
        $(tip).addClass(ClassName.SHOW); // If this is a touch-enabled device we add extra
Mark Otto's avatar
dist    
Mark Otto committed
265
266
267
        // empty mouseover listeners to the body's immediate children;
        // only needed because of broken event delegation on iOS
        // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
Mark Otto's avatar
grunt    
Mark Otto committed
268

Mark Otto's avatar
dist    
Mark Otto committed
269
        if ('ontouchstart' in document.documentElement) {
Mark Otto's avatar
dist    
Mark Otto committed
270
          $(document.body).children().on('mouseover', null, $.noop);
Mark Otto's avatar
build    
Mark Otto committed
271
272
        }

273
        var complete = function complete() {
Mark Otto's avatar
dist    
Mark Otto committed
274
275
          if (_this.config.animation) {
            _this._fixTransition();
Johann-S's avatar
build    
Johann-S committed
276
          }
277

Mark Otto's avatar
dist    
Mark Otto committed
278
279
280
          var prevHoverState = _this._hoverState;
          _this._hoverState = null;
          $(_this.element).trigger(_this.constructor.Event.SHOWN);
281

Mark Otto's avatar
dist    
Mark Otto committed
282
283
          if (prevHoverState === HoverState.OUT) {
            _this._leave(null, _this);
284
285
286
          }
        };

Mark Otto's avatar
dist    
Mark Otto committed
287
288
289
290
        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
          $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
        } else {
          complete();
291
        }
Mark Otto's avatar
dist    
Mark Otto committed
292
293
      }
    };
294

Mark Otto's avatar
dist    
Mark Otto committed
295
296
    _proto.hide = function hide(callback) {
      var _this2 = this;
297

Mark Otto's avatar
dist    
Mark Otto committed
298
299
300
301
302
303
      var tip = this.getTipElement();
      var hideEvent = $.Event(this.constructor.Event.HIDE);

      var complete = function complete() {
        if (_this2._hoverState !== HoverState.SHOW && tip.parentNode) {
          tip.parentNode.removeChild(tip);
Mark Otto's avatar
grunt    
Mark Otto committed
304
        }
305

Mark Otto's avatar
dist    
Mark Otto committed
306
        _this2._cleanTipClass();
Mark Otto's avatar
grunt    
Mark Otto committed
307

Mark Otto's avatar
dist    
Mark Otto committed
308
        _this2.element.removeAttribute('aria-describedby');
309

Mark Otto's avatar
dist    
Mark Otto committed
310
311
312
313
        $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);

        if (_this2._popper !== null) {
          _this2._popper.destroy();
Mark Otto's avatar
dist    
Mark Otto committed
314
        }
315

Mark Otto's avatar
dist    
Mark Otto committed
316
317
        if (callback) {
          callback();
Mark Otto's avatar
dist    
Mark Otto committed
318
        }
Mark Otto's avatar
dist    
Mark Otto committed
319
      };
Mark Otto's avatar
grunt    
Mark Otto committed
320

Mark Otto's avatar
dist    
Mark Otto committed
321
      $(this.element).trigger(hideEvent);
Mark Otto's avatar
grunt    
Mark Otto committed
322

Mark Otto's avatar
dist    
Mark Otto committed
323
324
      if (hideEvent.isDefaultPrevented()) {
        return;
Johann-S's avatar
build    
Johann-S committed
325
      }
Mark Otto's avatar
dist    
Mark Otto committed
326

Mark Otto's avatar
dist    
Mark Otto committed
327
      $(tip).removeClass(ClassName.SHOW); // If this is a touch-enabled device we remove the extra
Mark Otto's avatar
dist    
Mark Otto committed
328
329
330
      // empty mouseover listeners we added for iOS support

      if ('ontouchstart' in document.documentElement) {
Mark Otto's avatar
dist    
Mark Otto committed
331
        $(document.body).children().off('mouseover', null, $.noop);
Mark Otto's avatar
dist    
Mark Otto committed
332
      }
Mark Otto's avatar
dist    
Mark Otto committed
333
334
335
336
337
338
339
340
341

      this._activeTrigger[Trigger.CLICK] = false;
      this._activeTrigger[Trigger.FOCUS] = false;
      this._activeTrigger[Trigger.HOVER] = false;

      if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
        $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
      } else {
        complete();
Mark Otto's avatar
dist    
Mark Otto committed
342
      }
Mark Otto's avatar
dist    
Mark Otto committed
343
344
345
346
347
348
349

      this._hoverState = '';
    };

    _proto.update = function update() {
      if (this._popper !== null) {
        this._popper.scheduleUpdate();
Mark Otto's avatar
dist    
Mark Otto committed
350
      }
Mark Otto's avatar
dist    
Mark Otto committed
351
    }; // Protected
Mark Otto's avatar
dist    
Mark Otto committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376


    _proto.isWithContent = function isWithContent() {
      return Boolean(this.getTitle());
    };

    _proto.addAttachmentClass = function addAttachmentClass(attachment) {
      $(this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
    };

    _proto.getTipElement = function getTipElement() {
      this.tip = this.tip || $(this.config.template)[0];
      return this.tip;
    };

    _proto.setContent = function setContent() {
      var $tip = $(this.getTipElement());
      this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle());
      $tip.removeClass(ClassName.FADE + " " + ClassName.SHOW);
    };

    _proto.setElementContent = function setElementContent($element, content) {
      var html = this.config.html;

      if (typeof content === 'object' && (content.nodeType || content.jquery)) {
Mark Otto's avatar
dist    
Mark Otto committed
377
        // Content is a DOM node or a jQuery
Mark Otto's avatar
dist    
Mark Otto committed
378
379
380
        if (html) {
          if (!$(content).parent().is($element)) {
            $element.empty().append(content);
XhmikosR's avatar
XhmikosR committed
381
382
          }
        } else {
Mark Otto's avatar
dist    
Mark Otto committed
383
          $element.text($(content).text());
XhmikosR's avatar
XhmikosR committed
384
        }
Mark Otto's avatar
dist    
Mark Otto committed
385
386
      } else {
        $element[html ? 'html' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
387
      }
Mark Otto's avatar
dist    
Mark Otto committed
388
    };
389

Mark Otto's avatar
dist    
Mark Otto committed
390
391
    _proto.getTitle = function getTitle() {
      var title = this.element.getAttribute('data-original-title');
392

Mark Otto's avatar
dist    
Mark Otto committed
393
394
      if (!title) {
        title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
395
396
      }

Mark Otto's avatar
dist    
Mark Otto committed
397
      return title;
Mark Otto's avatar
dist    
Mark Otto committed
398
    }; // Private
399

Mark Otto's avatar
grunt    
Mark Otto committed
400

Mark Otto's avatar
dist    
Mark Otto committed
401
402
403
404
405
406
    _proto._getAttachment = function _getAttachment(placement) {
      return AttachmentMap[placement.toUpperCase()];
    };

    _proto._setListeners = function _setListeners() {
      var _this3 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
407

Mark Otto's avatar
dist    
Mark Otto committed
408
409
410
411
412
413
414
415
416
417
418
419
420
      var triggers = this.config.trigger.split(' ');
      triggers.forEach(function (trigger) {
        if (trigger === 'click') {
          $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, function (event) {
            return _this3.toggle(event);
          });
        } 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, function (event) {
            return _this3._enter(event);
          }).on(eventOut, _this3.config.selector, function (event) {
            return _this3._leave(event);
Mark Otto's avatar
dist    
Mark Otto committed
421
422
          });
        }
Mark Otto's avatar
dist    
Mark Otto committed
423
424
425
426
427
428
429

        $(_this3.element).closest('.modal').on('hide.bs.modal', function () {
          return _this3.hide();
        });
      });

      if (this.config.selector) {
Mark Otto's avatar
dist    
Mark Otto committed
430
        this.config = _extends({}, this.config, {
Mark Otto's avatar
dist    
Mark Otto committed
431
432
433
434
435
          trigger: 'manual',
          selector: ''
        });
      } else {
        this._fixTitle();
Mark Otto's avatar
grunt    
Mark Otto committed
436
      }
Mark Otto's avatar
dist    
Mark Otto committed
437
    };
438

Mark Otto's avatar
dist    
Mark Otto committed
439
440
    _proto._fixTitle = function _fixTitle() {
      var titleType = typeof this.element.getAttribute('data-original-title');
441

Mark Otto's avatar
dist    
Mark Otto committed
442
443
444
445
446
      if (this.element.getAttribute('title') || titleType !== 'string') {
        this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
        this.element.setAttribute('title', '');
      }
    };
447

Mark Otto's avatar
dist    
Mark Otto committed
448
449
450
    _proto._enter = function _enter(event, context) {
      var dataKey = this.constructor.DATA_KEY;
      context = context || $(event.currentTarget).data(dataKey);
Mark Otto's avatar
grunt    
Mark Otto committed
451

Mark Otto's avatar
dist    
Mark Otto committed
452
453
454
455
      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
      }
Mark Otto's avatar
grunt    
Mark Otto committed
456

Mark Otto's avatar
dist    
Mark Otto committed
457
458
459
      if (event) {
        context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
      }
460

Mark Otto's avatar
dist    
Mark Otto committed
461
      if ($(context.getTipElement()).hasClass(ClassName.SHOW) || context._hoverState === HoverState.SHOW) {
Mark Otto's avatar
dist    
Mark Otto committed
462
        context._hoverState = HoverState.SHOW;
Mark Otto's avatar
dist    
Mark Otto committed
463
464
465
466
467
        return;
      }

      clearTimeout(context._timeout);
      context._hoverState = HoverState.SHOW;
Mark Otto's avatar
grunt    
Mark Otto committed
468

Mark Otto's avatar
dist    
Mark Otto committed
469
470
471
472
473
474
475
      if (!context.config.delay || !context.config.delay.show) {
        context.show();
        return;
      }

      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.SHOW) {
476
477
          context.show();
        }
Mark Otto's avatar
dist    
Mark Otto committed
478
479
      }, context.config.delay.show);
    };
480

Mark Otto's avatar
dist    
Mark Otto committed
481
482
483
484
485
486
487
    _proto._leave = function _leave(event, context) {
      var dataKey = this.constructor.DATA_KEY;
      context = context || $(event.currentTarget).data(dataKey);

      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
Mark Otto's avatar
grunt    
Mark Otto committed
488
489
      }

Mark Otto's avatar
dist    
Mark Otto committed
490
491
492
      if (event) {
        context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
      }
493

Mark Otto's avatar
dist    
Mark Otto committed
494
495
496
      if (context._isWithActiveTrigger()) {
        return;
      }
497

Mark Otto's avatar
dist    
Mark Otto committed
498
499
      clearTimeout(context._timeout);
      context._hoverState = HoverState.OUT;
500

Mark Otto's avatar
dist    
Mark Otto committed
501
502
503
504
505
506
507
508
      if (!context.config.delay || !context.config.delay.hide) {
        context.hide();
        return;
      }

      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.OUT) {
          context.hide();
509
        }
Mark Otto's avatar
dist    
Mark Otto committed
510
511
      }, context.config.delay.hide);
    };
512

Mark Otto's avatar
dist    
Mark Otto committed
513
514
515
516
517
518
    _proto._isWithActiveTrigger = function _isWithActiveTrigger() {
      for (var trigger in this._activeTrigger) {
        if (this._activeTrigger[trigger]) {
          return true;
        }
      }
Mark Otto's avatar
grunt    
Mark Otto committed
519

Mark Otto's avatar
dist    
Mark Otto committed
520
521
      return false;
    };
fat's avatar
fat committed
522

Mark Otto's avatar
dist    
Mark Otto committed
523
    _proto._getConfig = function _getConfig(config) {
Mark Otto's avatar
dist    
Mark Otto committed
524
      config = _extends({}, this.constructor.Default, $(this.element).data(), config);
Mark Otto's avatar
grunt    
Mark Otto committed
525

Mark Otto's avatar
dist    
Mark Otto committed
526
527
528
529
530
      if (typeof config.delay === 'number') {
        config.delay = {
          show: config.delay,
          hide: config.delay
        };
Mark Otto's avatar
grunt    
Mark Otto committed
531
532
      }

Mark Otto's avatar
dist    
Mark Otto committed
533
534
      if (typeof config.title === 'number') {
        config.title = config.title.toString();
Mark Otto's avatar
grunt    
Mark Otto committed
535
536
      }

Mark Otto's avatar
dist    
Mark Otto committed
537
538
539
      if (typeof config.content === 'number') {
        config.content = config.content.toString();
      }
Mark Otto's avatar
grunt    
Mark Otto committed
540

Mark Otto's avatar
dist    
Mark Otto committed
541
542
543
      Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
      return config;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
544

Mark Otto's avatar
dist    
Mark Otto committed
545
546
    _proto._getDelegateConfig = function _getDelegateConfig() {
      var config = {};
Mark Otto's avatar
grunt    
Mark Otto committed
547

Mark Otto's avatar
dist    
Mark Otto committed
548
549
550
551
      if (this.config) {
        for (var key in this.config) {
          if (this.constructor.Default[key] !== this.config[key]) {
            config[key] = this.config[key];
552
553
          }
        }
Johann-S's avatar
build    
Johann-S committed
554
      }
Mark Otto's avatar
dist    
Mark Otto committed
555
556
557
558
559
560
561
562
563
564

      return config;
    };

    _proto._cleanTipClass = function _cleanTipClass() {
      var $tip = $(this.getTipElement());
      var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);

      if (tabClass !== null && tabClass.length > 0) {
        $tip.removeClass(tabClass.join(''));
Johann-S's avatar
build    
Johann-S committed
565
      }
Mark Otto's avatar
dist    
Mark Otto committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
    };

    _proto._handlePopperPlacementChange = function _handlePopperPlacementChange(data) {
      this._cleanTipClass();

      this.addAttachmentClass(this._getAttachment(data.placement));
    };

    _proto._fixTransition = function _fixTransition() {
      var tip = this.getTipElement();
      var initConfigAnimation = this.config.animation;

      if (tip.getAttribute('x-placement') !== null) {
        return;
Mark Otto's avatar
dist    
Mark Otto committed
580
      }
Mark Otto's avatar
dist    
Mark Otto committed
581
582
583
584
585
586

      $(tip).removeClass(ClassName.FADE);
      this.config.animation = false;
      this.hide();
      this.show();
      this.config.animation = initConfigAnimation;
Mark Otto's avatar
dist    
Mark Otto committed
587
    }; // Static
Mark Otto's avatar
dist    
Mark Otto committed
588
589
590
591
592
593
594
595
596


    Tooltip._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);

        var _config = typeof config === 'object' && config;

        if (!data && /dispose|hide/.test(config)) {
Mark Otto's avatar
grunt    
Mark Otto committed
597
598
          return;
        }
Mark Otto's avatar
dist    
Mark Otto committed
599

Mark Otto's avatar
dist    
Mark Otto committed
600
601
602
603
        if (!data) {
          data = new Tooltip(this, _config);
          $(this).data(DATA_KEY, data);
        }
Mark Otto's avatar
grunt    
Mark Otto committed
604

Mark Otto's avatar
dist    
Mark Otto committed
605
606
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
Mark Otto's avatar
dist    
Mark Otto committed
607
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
608
609
          }

Mark Otto's avatar
dist    
Mark Otto committed
610
611
612
613
          data[config]();
        }
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
614

Mark Otto's avatar
dist    
Mark Otto committed
615
616
    _createClass(Tooltip, null, [{
      key: "VERSION",
Jacob Thornton's avatar
Jacob Thornton committed
617
      get: function get() {
618
619
620
        return VERSION;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
621
      key: "Default",
Jacob Thornton's avatar
Jacob Thornton committed
622
      get: function get() {
623
624
        return Default;
      }
fat's avatar
fat committed
625
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
626
      key: "NAME",
Jacob Thornton's avatar
Jacob Thornton committed
627
      get: function get() {
fat's avatar
fat committed
628
629
630
        return NAME;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
631
      key: "DATA_KEY",
Jacob Thornton's avatar
Jacob Thornton committed
632
      get: function get() {
fat's avatar
fat committed
633
634
635
        return DATA_KEY;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
636
      key: "Event",
Jacob Thornton's avatar
Jacob Thornton committed
637
      get: function get() {
fat's avatar
fat committed
638
639
        return Event;
      }
fat's avatar
fat committed
640
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
641
      key: "EVENT_KEY",
Jacob Thornton's avatar
Jacob Thornton committed
642
      get: function get() {
fat's avatar
fat committed
643
644
        return EVENT_KEY;
      }
fat's avatar
fat committed
645
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
646
      key: "DefaultType",
Jacob Thornton's avatar
Jacob Thornton committed
647
      get: function get() {
fat's avatar
fat committed
648
649
        return DefaultType;
      }
650
651
652
    }]);

    return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
653
654
655
656
657
658
  }();
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
659

Mark Otto's avatar
dist    
Mark Otto committed
660

661
662
  $.fn[NAME] = Tooltip._jQueryInterface;
  $.fn[NAME].Constructor = Tooltip;
Mark Otto's avatar
dist    
Mark Otto committed
663

664
665
666
667
668
669
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Tooltip._jQueryInterface;
  };

  return Tooltip;
Mark Otto's avatar
dist    
Mark Otto committed
670
}($, Popper);
Mark Otto's avatar
build    
Mark Otto committed
671
//# sourceMappingURL=tooltip.js.map