tooltip.js 19.8 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
2
3
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Mark Otto's avatar
dist    
Mark Otto committed
4

Mark Otto's avatar
dist    
Mark Otto committed
5
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
6

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

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

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

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


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

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

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

Jacob Thornton's avatar
Jacob Thornton committed
127

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
139
140
141
142
143
144
145
    _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
146
      }
Mark Otto's avatar
Mark Otto committed
147

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

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

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
175
176
177
178
179
    _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');
180

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

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
227
        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
228

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

Mark Otto's avatar
dist    
Mark Otto committed
231
232
233
        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
234

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

Mark Otto's avatar
dist    
Mark Otto committed
239
240
241
242
243
244
        $(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
245
            },
Mark Otto's avatar
dist    
Mark Otto committed
246
247
            flip: {
              behavior: this.config.fallbackPlacement
Mark Otto's avatar
build    
Mark Otto committed
248
            },
Mark Otto's avatar
dist    
Mark Otto committed
249
250
            arrow: {
              element: Selector.ARROW
Mark Otto's avatar
dist    
Mark Otto committed
251
252
253
            },
            preventOverflow: {
              boundariesElement: this.config.boundary
Mark Otto's avatar
dist    
Mark Otto committed
254
255
256
257
            }
          },
          onCreate: function onCreate(data) {
            if (data.originalPlacement !== data.placement) {
Johann-S's avatar
build    
Johann-S committed
258
259
              _this._handlePopperPlacementChange(data);
            }
Mark Otto's avatar
dist    
Mark Otto committed
260
261
262
          },
          onUpdate: function onUpdate(data) {
            _this._handlePopperPlacementChange(data);
Johann-S's avatar
build    
Johann-S committed
263
          }
Mark Otto's avatar
dist    
Mark Otto committed
264
        });
Mark Otto's avatar
dist    
Mark Otto committed
265
        $(tip).addClass(ClassName.SHOW); // If this is a touch-enabled device we add extra
Mark Otto's avatar
dist    
Mark Otto committed
266
267
268
        // 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
269

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
288
289
290
        if ($(this.tip).hasClass(ClassName.FADE)) {
          var transitionDuration = Util.getTransitionDurationFromElement(this.tip);
          $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
Mark Otto's avatar
dist    
Mark Otto committed
291
292
        } else {
          complete();
293
        }
Mark Otto's avatar
dist    
Mark Otto committed
294
295
      }
    };
296

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

Mark Otto's avatar
dist    
Mark Otto committed
300
301
302
303
304
305
      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
306
        }
307

Mark Otto's avatar
dist    
Mark Otto committed
308
        _this2._cleanTipClass();
Mark Otto's avatar
grunt    
Mark Otto committed
309

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
340
341
342
      if ($(this.tip).hasClass(ClassName.FADE)) {
        var transitionDuration = Util.getTransitionDurationFromElement(tip);
        $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
Mark Otto's avatar
dist    
Mark Otto committed
343
344
      } else {
        complete();
Mark Otto's avatar
dist    
Mark Otto committed
345
      }
Mark Otto's avatar
dist    
Mark Otto committed
346
347
348
349
350
351
352

      this._hoverState = '';
    };

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


    _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
380
        // Content is a DOM node or a jQuery
Mark Otto's avatar
dist    
Mark Otto committed
381
382
383
        if (html) {
          if (!$(content).parent().is($element)) {
            $element.empty().append(content);
XhmikosR's avatar
XhmikosR committed
384
385
          }
        } else {
Mark Otto's avatar
dist    
Mark Otto committed
386
          $element.text($(content).text());
XhmikosR's avatar
XhmikosR committed
387
        }
Mark Otto's avatar
dist    
Mark Otto committed
388
389
      } else {
        $element[html ? 'html' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
390
      }
Mark Otto's avatar
dist    
Mark Otto committed
391
    };
392

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

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

Mark Otto's avatar
dist    
Mark Otto committed
400
      return title;
Mark Otto's avatar
dist    
Mark Otto committed
401
    }; // Private
402

Mark Otto's avatar
grunt    
Mark Otto committed
403

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

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

Mark Otto's avatar
dist    
Mark Otto committed
411
412
413
414
415
416
417
418
419
420
421
422
423
      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
424
425
          });
        }
Mark Otto's avatar
dist    
Mark Otto committed
426
427
428
429
430
431
432

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

      if (this.config.selector) {
Mark Otto's avatar
dist    
Mark Otto committed
433
        this.config = _objectSpread({}, this.config, {
Mark Otto's avatar
dist    
Mark Otto committed
434
435
436
437
438
          trigger: 'manual',
          selector: ''
        });
      } else {
        this._fixTitle();
Mark Otto's avatar
grunt    
Mark Otto committed
439
      }
Mark Otto's avatar
dist    
Mark Otto committed
440
    };
441

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

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

Mark Otto's avatar
dist    
Mark Otto committed
451
452
453
    _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
454

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

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

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
484
485
486
487
488
489
490
    _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
491
492
      }

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

Mark Otto's avatar
dist    
Mark Otto committed
497
498
499
      if (context._isWithActiveTrigger()) {
        return;
      }
500

Mark Otto's avatar
dist    
Mark Otto committed
501
502
      clearTimeout(context._timeout);
      context._hoverState = HoverState.OUT;
503

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
523
524
      return false;
    };
fat's avatar
fat committed
525

Mark Otto's avatar
dist    
Mark Otto committed
526
    _proto._getConfig = function _getConfig(config) {
Mark Otto's avatar
dist    
Mark Otto committed
527
      config = _objectSpread({}, this.constructor.Default, $(this.element).data(), config);
Mark Otto's avatar
grunt    
Mark Otto committed
528

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

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

Mark Otto's avatar
dist    
Mark Otto committed
540
541
542
      if (typeof config.content === 'number') {
        config.content = config.content.toString();
      }
Mark Otto's avatar
grunt    
Mark Otto committed
543

Mark Otto's avatar
dist    
Mark Otto committed
544
545
546
      Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
      return config;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
547

Mark Otto's avatar
dist    
Mark Otto committed
548
549
    _proto._getDelegateConfig = function _getDelegateConfig() {
      var config = {};
Mark Otto's avatar
grunt    
Mark Otto committed
550

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

      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
568
      }
Mark Otto's avatar
dist    
Mark Otto committed
569
570
571
572
573
574
575
576
577
578
579
580
581
582
    };

    _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
583
      }
Mark Otto's avatar
dist    
Mark Otto committed
584
585
586
587
588
589

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


    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
600
601
          return;
        }
Mark Otto's avatar
dist    
Mark Otto committed
602

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

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

Mark Otto's avatar
dist    
Mark Otto committed
613
614
615
616
          data[config]();
        }
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
617

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

    return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
656
657
658
659
660
661
  }();
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
662

Mark Otto's avatar
dist    
Mark Otto committed
663

664
665
  $.fn[NAME] = Tooltip._jQueryInterface;
  $.fn[NAME].Constructor = Tooltip;
Mark Otto's avatar
dist    
Mark Otto committed
666

667
668
669
670
671
672
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Tooltip._jQueryInterface;
  };

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