tooltip.js 18.9 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
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
2

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

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

Mark Otto's avatar
dist    
Mark Otto committed
94
  };
95

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


109
110
111
112
      this._isEnabled = true;
      this._timeout = 0;
      this._hoverState = '';
      this._activeTrigger = {};
Mark Otto's avatar
dist    
Mark Otto committed
113
      this._popper = null; // protected
114
115
116
117
118
119

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

      this._setListeners();
Mark Otto's avatar
dist    
Mark Otto committed
120
    } // getters
121

Jacob Thornton's avatar
Jacob Thornton committed
122

Mark Otto's avatar
dist    
Mark Otto committed
123
    var _proto = Tooltip.prototype;
124

Mark Otto's avatar
dist    
Mark Otto committed
125
126
127
128
    // public
    _proto.enable = function enable() {
      this._isEnabled = true;
    };
129

Mark Otto's avatar
dist    
Mark Otto committed
130
131
132
    _proto.disable = function disable() {
      this._isEnabled = false;
    };
133

Mark Otto's avatar
dist    
Mark Otto committed
134
135
136
137
138
139
140
    _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
141
      }
Mark Otto's avatar
Mark Otto committed
142

Mark Otto's avatar
dist    
Mark Otto committed
143
144
145
      if (event) {
        var dataKey = this.constructor.DATA_KEY;
        var context = $(event.currentTarget).data(dataKey);
Mark Otto's avatar
Mark Otto committed
146

Mark Otto's avatar
dist    
Mark Otto committed
147
148
149
150
        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }
fat's avatar
fat committed
151

Mark Otto's avatar
dist    
Mark Otto committed
152
        context._activeTrigger.click = !context._activeTrigger.click;
fat's avatar
fat committed
153

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

Mark Otto's avatar
dist    
Mark Otto committed
163
          return;
Mark Otto's avatar
dist    
Mark Otto committed
164
        }
165

Mark Otto's avatar
dist    
Mark Otto committed
166
167
168
        this._enter(null, this);
      }
    };
169

Mark Otto's avatar
dist    
Mark Otto committed
170
171
172
173
174
    _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');
175

Mark Otto's avatar
dist    
Mark Otto committed
176
177
178
      if (this.tip) {
        $(this.tip).remove();
      }
179

Mark Otto's avatar
dist    
Mark Otto committed
180
181
182
183
      this._isEnabled = null;
      this._timeout = null;
      this._hoverState = null;
      this._activeTrigger = null;
184

Mark Otto's avatar
dist    
Mark Otto committed
185
186
      if (this._popper !== null) {
        this._popper.destroy();
Mark Otto's avatar
grunt    
Mark Otto committed
187
      }
188

Mark Otto's avatar
dist    
Mark Otto committed
189
190
191
192
193
      this._popper = null;
      this.element = null;
      this.config = null;
      this.tip = null;
    };
194

Mark Otto's avatar
dist    
Mark Otto committed
195
196
    _proto.show = function show() {
      var _this = this;
197

Mark Otto's avatar
dist    
Mark Otto committed
198
199
200
      if ($(this.element).css('display') === 'none') {
        throw new Error('Please use show on visible elements');
      }
201

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

Mark Otto's avatar
dist    
Mark Otto committed
204
205
206
      if (this.isWithContent() && this._isEnabled) {
        $(this.element).trigger(showEvent);
        var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element);
207

Mark Otto's avatar
dist    
Mark Otto committed
208
209
210
        if (showEvent.isDefaultPrevented() || !isInTheDom) {
          return;
        }
211

Mark Otto's avatar
dist    
Mark Otto committed
212
213
214
215
216
        var tip = this.getTipElement();
        var tipId = Util.getUID(this.constructor.NAME);
        tip.setAttribute('id', tipId);
        this.element.setAttribute('aria-describedby', tipId);
        this.setContent();
217

Mark Otto's avatar
dist    
Mark Otto committed
218
219
220
        if (this.config.animation) {
          $(tip).addClass(ClassName.FADE);
        }
221

Mark Otto's avatar
dist    
Mark Otto committed
222
        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
223

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

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

Mark Otto's avatar
dist    
Mark Otto committed
230
231
232
        if (!$.contains(this.element.ownerDocument.documentElement, this.tip)) {
          $(tip).appendTo(container);
        }
Mark Otto's avatar
grunt    
Mark Otto committed
233

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

Mark Otto's avatar
dist    
Mark Otto committed
262
263
        if ('ontouchstart' in document.documentElement) {
          $('body').children().on('mouseover', null, $.noop);
Mark Otto's avatar
build    
Mark Otto committed
264
265
        }

266
        var complete = function complete() {
Mark Otto's avatar
dist    
Mark Otto committed
267
268
          if (_this.config.animation) {
            _this._fixTransition();
Johann-S's avatar
build    
Johann-S committed
269
          }
270

Mark Otto's avatar
dist    
Mark Otto committed
271
272
273
          var prevHoverState = _this._hoverState;
          _this._hoverState = null;
          $(_this.element).trigger(_this.constructor.Event.SHOWN);
274

Mark Otto's avatar
dist    
Mark Otto committed
275
276
          if (prevHoverState === HoverState.OUT) {
            _this._leave(null, _this);
277
278
279
          }
        };

Mark Otto's avatar
dist    
Mark Otto committed
280
281
282
283
        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
          $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
        } else {
          complete();
284
        }
Mark Otto's avatar
dist    
Mark Otto committed
285
286
      }
    };
287

Mark Otto's avatar
dist    
Mark Otto committed
288
289
    _proto.hide = function hide(callback) {
      var _this2 = this;
290

Mark Otto's avatar
dist    
Mark Otto committed
291
292
293
294
295
296
      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
297
        }
298

Mark Otto's avatar
dist    
Mark Otto committed
299
        _this2._cleanTipClass();
Mark Otto's avatar
grunt    
Mark Otto committed
300

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

Mark Otto's avatar
dist    
Mark Otto committed
303
304
305
306
        $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);

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

Mark Otto's avatar
dist    
Mark Otto committed
309
310
        if (callback) {
          callback();
Mark Otto's avatar
dist    
Mark Otto committed
311
        }
Mark Otto's avatar
dist    
Mark Otto committed
312
      };
Mark Otto's avatar
grunt    
Mark Otto committed
313

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

Mark Otto's avatar
dist    
Mark Otto committed
316
317
      if (hideEvent.isDefaultPrevented()) {
        return;
Johann-S's avatar
build    
Johann-S committed
318
      }
Mark Otto's avatar
dist    
Mark Otto committed
319
320
321
322
323
324

      $(tip).removeClass(ClassName.SHOW); // if this is a touch-enabled device we remove the extra
      // empty mouseover listeners we added for iOS support

      if ('ontouchstart' in document.documentElement) {
        $('body').children().off('mouseover', null, $.noop);
Mark Otto's avatar
dist    
Mark Otto committed
325
      }
Mark Otto's avatar
dist    
Mark Otto committed
326
327
328
329
330
331
332
333
334

      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
335
      }
Mark Otto's avatar
dist    
Mark Otto committed
336
337
338
339
340
341
342

      this._hoverState = '';
    };

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


    _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)) {
        // content is a DOM node or a jQuery
        if (html) {
          if (!$(content).parent().is($element)) {
            $element.empty().append(content);
XhmikosR's avatar
XhmikosR committed
374
375
          }
        } else {
Mark Otto's avatar
dist    
Mark Otto committed
376
          $element.text($(content).text());
XhmikosR's avatar
XhmikosR committed
377
        }
Mark Otto's avatar
dist    
Mark Otto committed
378
379
      } else {
        $element[html ? 'html' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
380
      }
Mark Otto's avatar
dist    
Mark Otto committed
381
    };
382

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

Mark Otto's avatar
dist    
Mark Otto committed
386
387
      if (!title) {
        title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
388
389
      }

Mark Otto's avatar
dist    
Mark Otto committed
390
391
      return title;
    }; // private
392

Mark Otto's avatar
grunt    
Mark Otto committed
393

Mark Otto's avatar
dist    
Mark Otto committed
394
395
396
397
398
399
    _proto._getAttachment = function _getAttachment(placement) {
      return AttachmentMap[placement.toUpperCase()];
    };

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

Mark Otto's avatar
dist    
Mark Otto committed
401
402
403
404
405
406
407
408
409
410
411
412
413
      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
414
415
          });
        }
Mark Otto's avatar
dist    
Mark Otto committed
416
417
418
419
420
421
422
423
424
425
426
427
428

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

      if (this.config.selector) {
        this.config = $.extend({}, this.config, {
          trigger: 'manual',
          selector: ''
        });
      } else {
        this._fixTitle();
Mark Otto's avatar
grunt    
Mark Otto committed
429
      }
Mark Otto's avatar
dist    
Mark Otto committed
430
    };
431

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

Mark Otto's avatar
dist    
Mark Otto committed
435
436
437
438
439
      if (this.element.getAttribute('title') || titleType !== 'string') {
        this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
        this.element.setAttribute('title', '');
      }
    };
440

Mark Otto's avatar
dist    
Mark Otto committed
441
442
443
    _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
444

Mark Otto's avatar
dist    
Mark Otto committed
445
446
447
448
      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
      }
Mark Otto's avatar
grunt    
Mark Otto committed
449

Mark Otto's avatar
dist    
Mark Otto committed
450
451
452
      if (event) {
        context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
      }
453

Mark Otto's avatar
dist    
Mark Otto committed
454
      if ($(context.getTipElement()).hasClass(ClassName.SHOW) || context._hoverState === HoverState.SHOW) {
Mark Otto's avatar
dist    
Mark Otto committed
455
        context._hoverState = HoverState.SHOW;
Mark Otto's avatar
dist    
Mark Otto committed
456
457
458
459
460
        return;
      }

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

Mark Otto's avatar
dist    
Mark Otto committed
462
463
464
465
466
467
468
      if (!context.config.delay || !context.config.delay.show) {
        context.show();
        return;
      }

      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.SHOW) {
469
470
          context.show();
        }
Mark Otto's avatar
dist    
Mark Otto committed
471
472
      }, context.config.delay.show);
    };
473

Mark Otto's avatar
dist    
Mark Otto committed
474
475
476
477
478
479
480
    _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
481
482
      }

Mark Otto's avatar
dist    
Mark Otto committed
483
484
485
      if (event) {
        context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
      }
486

Mark Otto's avatar
dist    
Mark Otto committed
487
488
489
      if (context._isWithActiveTrigger()) {
        return;
      }
490

Mark Otto's avatar
dist    
Mark Otto committed
491
492
      clearTimeout(context._timeout);
      context._hoverState = HoverState.OUT;
493

Mark Otto's avatar
dist    
Mark Otto committed
494
495
496
497
498
499
500
501
      if (!context.config.delay || !context.config.delay.hide) {
        context.hide();
        return;
      }

      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.OUT) {
          context.hide();
502
        }
Mark Otto's avatar
dist    
Mark Otto committed
503
504
      }, context.config.delay.hide);
    };
505

Mark Otto's avatar
dist    
Mark Otto committed
506
507
508
509
510
511
    _proto._isWithActiveTrigger = function _isWithActiveTrigger() {
      for (var trigger in this._activeTrigger) {
        if (this._activeTrigger[trigger]) {
          return true;
        }
      }
Mark Otto's avatar
grunt    
Mark Otto committed
512

Mark Otto's avatar
dist    
Mark Otto committed
513
514
      return false;
    };
fat's avatar
fat committed
515

Mark Otto's avatar
dist    
Mark Otto committed
516
517
    _proto._getConfig = function _getConfig(config) {
      config = $.extend({}, this.constructor.Default, $(this.element).data(), config);
Mark Otto's avatar
grunt    
Mark Otto committed
518

Mark Otto's avatar
dist    
Mark Otto committed
519
520
521
522
523
      if (typeof config.delay === 'number') {
        config.delay = {
          show: config.delay,
          hide: config.delay
        };
Mark Otto's avatar
grunt    
Mark Otto committed
524
525
      }

Mark Otto's avatar
dist    
Mark Otto committed
526
527
      if (typeof config.title === 'number') {
        config.title = config.title.toString();
Mark Otto's avatar
grunt    
Mark Otto committed
528
529
      }

Mark Otto's avatar
dist    
Mark Otto committed
530
531
532
      if (typeof config.content === 'number') {
        config.content = config.content.toString();
      }
Mark Otto's avatar
grunt    
Mark Otto committed
533

Mark Otto's avatar
dist    
Mark Otto committed
534
535
536
      Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
      return config;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
537

Mark Otto's avatar
dist    
Mark Otto committed
538
539
    _proto._getDelegateConfig = function _getDelegateConfig() {
      var config = {};
Mark Otto's avatar
grunt    
Mark Otto committed
540

Mark Otto's avatar
dist    
Mark Otto committed
541
542
543
544
      if (this.config) {
        for (var key in this.config) {
          if (this.constructor.Default[key] !== this.config[key]) {
            config[key] = this.config[key];
545
546
          }
        }
Johann-S's avatar
build    
Johann-S committed
547
      }
Mark Otto's avatar
dist    
Mark Otto committed
548
549
550
551
552
553
554
555
556
557

      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
558
      }
Mark Otto's avatar
dist    
Mark Otto committed
559
560
561
562
563
564
565
566
567
568
569
570
571
572
    };

    _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
573
      }
Mark Otto's avatar
dist    
Mark Otto committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589

      $(tip).removeClass(ClassName.FADE);
      this.config.animation = false;
      this.hide();
      this.show();
      this.config.animation = initConfigAnimation;
    }; // static


    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
590
591
          return;
        }
Mark Otto's avatar
dist    
Mark Otto committed
592

Mark Otto's avatar
dist    
Mark Otto committed
593
594
595
596
        if (!data) {
          data = new Tooltip(this, _config);
          $(this).data(DATA_KEY, data);
        }
Mark Otto's avatar
grunt    
Mark Otto committed
597

Mark Otto's avatar
dist    
Mark Otto committed
598
599
600
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new Error("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
601
602
          }

Mark Otto's avatar
dist    
Mark Otto committed
603
604
605
606
          data[config]();
        }
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
607

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

    return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
646
647
648
649
650
651
  }();
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
652

Mark Otto's avatar
dist    
Mark Otto committed
653

654
655
  $.fn[NAME] = Tooltip._jQueryInterface;
  $.fn[NAME].Constructor = Tooltip;
Mark Otto's avatar
dist    
Mark Otto committed
656

657
658
659
660
661
662
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Tooltip._jQueryInterface;
  };

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