tooltip.js 19.7 KB
Newer Older
Mark Otto's avatar
grunt    
Mark Otto committed
1
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
XhmikosR's avatar
XhmikosR committed
2

Mark Otto's avatar
grunt    
Mark Otto committed
3
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4

Mark Otto's avatar
grunt    
Mark Otto committed
5
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7
8

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
9
 * Bootstrap (v4.0.0-beta): tooltip.js
10
11
12
13
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

Mark Otto's avatar
grunt    
Mark Otto committed
14
var Tooltip = function ($) {
15

16
  /**
Johann-S's avatar
build    
Johann-S committed
17
18
   * Check for Popper dependency
   * Popper - https://popper.js.org
19
   */
Johann-S's avatar
build    
Johann-S committed
20
21
  if (typeof Popper === 'undefined') {
    throw new Error('Bootstrap tooltips require Popper.js (https://popper.js.org)');
22
23
  }

24
25
26
27
28
29
30
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'tooltip';
Mark Otto's avatar
Mark Otto committed
31
  var VERSION = '4.0.0-beta';
32
  var DATA_KEY = 'bs.tooltip';
fat's avatar
fat committed
33
  var EVENT_KEY = '.' + DATA_KEY;
34
35
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  var TRANSITION_DURATION = 150;
Johann-S's avatar
build    
Johann-S committed
36
37
  var CLASS_PREFIX = 'bs-tooltip';
  var BSCLS_PREFIX_REGEX = new RegExp('(^|\\s)' + CLASS_PREFIX + '\\S+', 'g');
fat's avatar
fat committed
38
39
40
41

  var DefaultType = {
    animation: 'boolean',
    template: 'string',
XhmikosR's avatar
XhmikosR committed
42
    title: '(string|element|function)',
fat's avatar
fat committed
43
44
45
46
47
    trigger: 'string',
    delay: '(number|object)',
    html: 'boolean',
    selector: '(string|boolean)',
    placement: '(string|function)',
Johann-S's avatar
build    
Johann-S committed
48
49
50
    offset: '(number|string)',
    container: '(string|element|boolean)',
    fallbackPlacement: '(string|array)'
51
52
  };

fat's avatar
fat committed
53
  var AttachmentMap = {
Mark Otto's avatar
build    
Mark Otto committed
54
    AUTO: 'auto',
Johann-S's avatar
build    
Johann-S committed
55
56
57
58
59
60
61
62
    TOP: 'top',
    RIGHT: 'right',
    BOTTOM: 'bottom',
    LEFT: 'left'
  };

  var Default = {
    animation: true,
Mark Otto's avatar
build    
Mark Otto committed
63
    template: '<div class="tooltip" role="tooltip">' + '<div class="arrow"></div>' + '<div class="tooltip-inner"></div></div>',
Johann-S's avatar
build    
Johann-S committed
64
65
66
67
68
69
70
71
72
    trigger: 'hover focus',
    title: '',
    delay: 0,
    html: false,
    selector: false,
    placement: 'top',
    offset: 0,
    container: false,
    fallbackPlacement: 'flip'
73
74
75
  };

  var HoverState = {
Mark Otto's avatar
grunt    
Mark Otto committed
76
    SHOW: 'show',
77
78
79
80
    OUT: 'out'
  };

  var Event = {
fat's avatar
fat committed
81
82
83
84
85
86
87
88
89
90
    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
91
92
93
94
  };

  var ClassName = {
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
95
    SHOW: 'show'
96
97
98
99
  };

  var Selector = {
    TOOLTIP: '.tooltip',
Mark Otto's avatar
build    
Mark Otto committed
100
101
    TOOLTIP_INNER: '.tooltip-inner',
    ARROW: '.arrow'
102
  };
103

fat's avatar
fat committed
104
105
106
107
108
  var Trigger = {
    HOVER: 'hover',
    FOCUS: 'focus',
    CLICK: 'click',
    MANUAL: 'manual'
Mark Otto's avatar
dist    
Mark Otto committed
109
  };
110

Mark Otto's avatar
dist    
Mark Otto committed
111
112
113
114
115
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
116

Mark Otto's avatar
grunt    
Mark Otto committed
117
  var Tooltip = function () {
118
119
120
121
122
123
124
125
    function Tooltip(element, config) {
      _classCallCheck(this, Tooltip);

      // private
      this._isEnabled = true;
      this._timeout = 0;
      this._hoverState = '';
      this._activeTrigger = {};
Johann-S's avatar
build    
Johann-S committed
126
      this._popper = null;
127
128
129
130
131
132
133
134
135

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

      this._setListeners();
    }

Jacob Thornton's avatar
Jacob Thornton committed
136
137
    // getters

Mark Otto's avatar
grunt    
Mark Otto committed
138
    // public
139

Mark Otto's avatar
grunt    
Mark Otto committed
140
141
142
    Tooltip.prototype.enable = function enable() {
      this._isEnabled = true;
    };
143

Mark Otto's avatar
grunt    
Mark Otto committed
144
145
146
    Tooltip.prototype.disable = function disable() {
      this._isEnabled = false;
    };
147

Mark Otto's avatar
grunt    
Mark Otto committed
148
149
150
    Tooltip.prototype.toggleEnabled = function toggleEnabled() {
      this._isEnabled = !this._isEnabled;
    };
Mark Otto's avatar
Mark Otto committed
151

Mark Otto's avatar
grunt    
Mark Otto committed
152
153
154
155
    Tooltip.prototype.toggle = function toggle(event) {
      if (event) {
        var dataKey = this.constructor.DATA_KEY;
        var context = $(event.currentTarget).data(dataKey);
Mark Otto's avatar
Mark Otto committed
156

Mark Otto's avatar
grunt    
Mark Otto committed
157
158
159
        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
160
        }
fat's avatar
fat committed
161

Mark Otto's avatar
grunt    
Mark Otto committed
162
        context._activeTrigger.click = !context._activeTrigger.click;
fat's avatar
fat committed
163

Mark Otto's avatar
grunt    
Mark Otto committed
164
165
166
167
        if (context._isWithActiveTrigger()) {
          context._enter(null, context);
        } else {
          context._leave(null, context);
fat's avatar
fat committed
168
        }
Mark Otto's avatar
grunt    
Mark Otto committed
169
      } else {
fat's avatar
fat committed
170

Mark Otto's avatar
grunt    
Mark Otto committed
171
        if ($(this.getTipElement()).hasClass(ClassName.SHOW)) {
Mark Otto's avatar
grunt    
Mark Otto committed
172
173
174
          this._leave(null, this);
          return;
        }
fat's avatar
fat committed
175

Mark Otto's avatar
grunt    
Mark Otto committed
176
        this._enter(null, this);
177
      }
Mark Otto's avatar
grunt    
Mark Otto committed
178
    };
179

Mark Otto's avatar
grunt    
Mark Otto committed
180
181
    Tooltip.prototype.dispose = function dispose() {
      clearTimeout(this._timeout);
182

Mark Otto's avatar
grunt    
Mark Otto committed
183
      $.removeData(this.element, this.constructor.DATA_KEY);
184

Mark Otto's avatar
grunt    
Mark Otto committed
185
      $(this.element).off(this.constructor.EVENT_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
186
      $(this.element).closest('.modal').off('hide.bs.modal');
187

Mark Otto's avatar
grunt    
Mark Otto committed
188
189
190
      if (this.tip) {
        $(this.tip).remove();
      }
191

Mark Otto's avatar
grunt    
Mark Otto committed
192
193
194
195
      this._isEnabled = null;
      this._timeout = null;
      this._hoverState = null;
      this._activeTrigger = null;
Johann-S's avatar
build    
Johann-S committed
196
197
198
199
      if (this._popper !== null) {
        this._popper.destroy();
      }
      this._popper = null;
200

Mark Otto's avatar
grunt    
Mark Otto committed
201
202
203
204
      this.element = null;
      this.config = null;
      this.tip = null;
    };
205

Mark Otto's avatar
grunt    
Mark Otto committed
206
207
    Tooltip.prototype.show = function show() {
      var _this = this;
208

Mark Otto's avatar
grunt    
Mark Otto committed
209
210
211
      if ($(this.element).css('display') === 'none') {
        throw new Error('Please use show on visible elements');
      }
212

Mark Otto's avatar
grunt    
Mark Otto committed
213
      var showEvent = $.Event(this.constructor.Event.SHOW);
Mark Otto's avatar
grunt    
Mark Otto committed
214
215
      if (this.isWithContent() && this._isEnabled) {
        $(this.element).trigger(showEvent);
216

Mark Otto's avatar
grunt    
Mark Otto committed
217
        var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element);
218

Mark Otto's avatar
grunt    
Mark Otto committed
219
220
221
        if (showEvent.isDefaultPrevented() || !isInTheDom) {
          return;
        }
222

Mark Otto's avatar
grunt    
Mark Otto committed
223
224
        var tip = this.getTipElement();
        var tipId = Util.getUID(this.constructor.NAME);
225

Mark Otto's avatar
grunt    
Mark Otto committed
226
227
        tip.setAttribute('id', tipId);
        this.element.setAttribute('aria-describedby', tipId);
228

Mark Otto's avatar
grunt    
Mark Otto committed
229
        this.setContent();
230

Mark Otto's avatar
grunt    
Mark Otto committed
231
232
233
        if (this.config.animation) {
          $(tip).addClass(ClassName.FADE);
        }
234

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

Mark Otto's avatar
grunt    
Mark Otto committed
237
        var attachment = this._getAttachment(placement);
Johann-S's avatar
build    
Johann-S committed
238
        this.addAttachmentClass(attachment);
239

Mark Otto's avatar
grunt    
Mark Otto committed
240
241
        var container = this.config.container === false ? document.body : $(this.config.container);

Mark Otto's avatar
grunt    
Mark Otto committed
242
243
244
245
246
        $(tip).data(this.constructor.DATA_KEY, this);

        if (!$.contains(this.element.ownerDocument.documentElement, this.tip)) {
          $(tip).appendTo(container);
        }
Mark Otto's avatar
Mark Otto committed
247

Mark Otto's avatar
grunt    
Mark Otto committed
248
249
        $(this.element).trigger(this.constructor.Event.INSERTED);

Johann-S's avatar
build    
Johann-S committed
250
251
252
253
254
255
256
257
        this._popper = new Popper(this.element, tip, {
          placement: attachment,
          modifiers: {
            offset: {
              offset: this.config.offset
            },
            flip: {
              behavior: this.config.fallbackPlacement
Mark Otto's avatar
build    
Mark Otto committed
258
259
260
            },
            arrow: {
              element: Selector.ARROW
Johann-S's avatar
build    
Johann-S committed
261
262
263
264
265
266
267
268
269
270
            }
          },
          onCreate: function onCreate(data) {
            if (data.originalPlacement !== data.placement) {
              _this._handlePopperPlacementChange(data);
            }
          },
          onUpdate: function onUpdate(data) {
            _this._handlePopperPlacementChange(data);
          }
Mark Otto's avatar
grunt    
Mark Otto committed
271
272
        });

Mark Otto's avatar
Mark Otto committed
273
        $(tip).addClass(ClassName.SHOW);
274

Mark Otto's avatar
build    
Mark Otto committed
275
276
277
278
        // 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
Mark Otto committed
279
        if ('ontouchstart' in document.documentElement) {
Mark Otto's avatar
build    
Mark Otto committed
280
281
282
          $('body').children().on('mouseover', null, $.noop);
        }

283
        var complete = function complete() {
Johann-S's avatar
build    
Johann-S committed
284
285
286
          if (_this.config.animation) {
            _this._fixTransition();
          }
Mark Otto's avatar
grunt    
Mark Otto committed
287
288
          var prevHoverState = _this._hoverState;
          _this._hoverState = null;
289

Mark Otto's avatar
grunt    
Mark Otto committed
290
          $(_this.element).trigger(_this.constructor.Event.SHOWN);
291

Mark Otto's avatar
grunt    
Mark Otto committed
292
293
          if (prevHoverState === HoverState.OUT) {
            _this._leave(null, _this);
294
295
296
          }
        };

Mark Otto's avatar
grunt    
Mark Otto committed
297
298
        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
          $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
Johann-S's avatar
build    
Johann-S committed
299
300
        } else {
          complete();
301
        }
Mark Otto's avatar
grunt    
Mark Otto committed
302
303
      }
    };
304

Mark Otto's avatar
grunt    
Mark Otto committed
305
306
    Tooltip.prototype.hide = function hide(callback) {
      var _this2 = this;
307

Mark Otto's avatar
grunt    
Mark Otto committed
308
309
310
      var tip = this.getTipElement();
      var hideEvent = $.Event(this.constructor.Event.HIDE);
      var complete = function complete() {
Mark Otto's avatar
grunt    
Mark Otto committed
311
        if (_this2._hoverState !== HoverState.SHOW && tip.parentNode) {
Mark Otto's avatar
grunt    
Mark Otto committed
312
          tip.parentNode.removeChild(tip);
313
314
        }

Mark Otto's avatar
grunt    
Mark Otto committed
315
        _this2._cleanTipClass();
Mark Otto's avatar
grunt    
Mark Otto committed
316
317
        _this2.element.removeAttribute('aria-describedby');
        $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);
Johann-S's avatar
build    
Johann-S committed
318
319
320
        if (_this2._popper !== null) {
          _this2._popper.destroy();
        }
321

Mark Otto's avatar
grunt    
Mark Otto committed
322
323
324
325
        if (callback) {
          callback();
        }
      };
326

Mark Otto's avatar
grunt    
Mark Otto committed
327
328
329
330
      $(this.element).trigger(hideEvent);

      if (hideEvent.isDefaultPrevented()) {
        return;
331
332
      }

Mark Otto's avatar
Mark Otto committed
333
      $(tip).removeClass(ClassName.SHOW);
334

Mark Otto's avatar
build    
Mark Otto committed
335
336
      // if this is a touch-enabled device we remove the extra
      // empty mouseover listeners we added for iOS support
Mark Otto's avatar
Mark Otto committed
337
      if ('ontouchstart' in document.documentElement) {
Mark Otto's avatar
build    
Mark Otto committed
338
339
340
        $('body').children().off('mouseover', null, $.noop);
      }

Mark Otto's avatar
grunt    
Mark Otto committed
341
342
343
344
      this._activeTrigger[Trigger.CLICK] = false;
      this._activeTrigger[Trigger.FOCUS] = false;
      this._activeTrigger[Trigger.HOVER] = false;

Mark Otto's avatar
grunt    
Mark Otto committed
345
      if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
Mark Otto's avatar
grunt    
Mark Otto committed
346

Mark Otto's avatar
grunt    
Mark Otto committed
347
348
349
        $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
      } else {
        complete();
350
      }
Mark Otto's avatar
grunt    
Mark Otto committed
351
352
353
354

      this._hoverState = '';
    };

Johann-S's avatar
build    
Johann-S committed
355
356
357
358
359
360
    Tooltip.prototype.update = function update() {
      if (this._popper !== null) {
        this._popper.scheduleUpdate();
      }
    };

Mark Otto's avatar
grunt    
Mark Otto committed
361
362
363
364
365
366
    // protected

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

Johann-S's avatar
build    
Johann-S committed
367
368
369
370
    Tooltip.prototype.addAttachmentClass = function addAttachmentClass(attachment) {
      $(this.getTipElement()).addClass(CLASS_PREFIX + '-' + attachment);
    };

Mark Otto's avatar
grunt    
Mark Otto committed
371
372
373
374
375
376
377
    Tooltip.prototype.getTipElement = function getTipElement() {
      return this.tip = this.tip || $(this.config.template)[0];
    };

    Tooltip.prototype.setContent = function setContent() {
      var $tip = $(this.getTipElement());
      this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle());
Mark Otto's avatar
grunt    
Mark Otto committed
378
      $tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW);
Mark Otto's avatar
grunt    
Mark Otto committed
379
380
381
382
383
384
385
386
387
    };

    Tooltip.prototype.setElementContent = function setElementContent($element, content) {
      var html = this.config.html;
      if ((typeof content === 'undefined' ? 'undefined' : _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
388
389
          }
        } else {
Mark Otto's avatar
grunt    
Mark Otto committed
390
          $element.text($(content).text());
XhmikosR's avatar
XhmikosR committed
391
        }
Mark Otto's avatar
grunt    
Mark Otto committed
392
393
      } else {
        $element[html ? 'html' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
394
      }
Mark Otto's avatar
grunt    
Mark Otto committed
395
    };
396

Mark Otto's avatar
grunt    
Mark Otto committed
397
398
    Tooltip.prototype.getTitle = function getTitle() {
      var title = this.element.getAttribute('data-original-title');
399

Mark Otto's avatar
grunt    
Mark Otto committed
400
401
      if (!title) {
        title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
402
403
      }

Mark Otto's avatar
grunt    
Mark Otto committed
404
405
      return title;
    };
406

Mark Otto's avatar
grunt    
Mark Otto committed
407
    // private
408

Mark Otto's avatar
grunt    
Mark Otto committed
409
410
411
    Tooltip.prototype._getAttachment = function _getAttachment(placement) {
      return AttachmentMap[placement.toUpperCase()];
    };
412

Mark Otto's avatar
grunt    
Mark Otto committed
413
414
    Tooltip.prototype._setListeners = function _setListeners() {
      var _this3 = this;
415

Mark Otto's avatar
grunt    
Mark Otto committed
416
417
418
419
      var triggers = this.config.trigger.split(' ');

      triggers.forEach(function (trigger) {
        if (trigger === 'click') {
Mark Otto's avatar
grunt    
Mark Otto committed
420
421
422
          $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, function (event) {
            return _this3.toggle(event);
          });
Mark Otto's avatar
grunt    
Mark Otto committed
423
424
425
426
        } 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;

Mark Otto's avatar
grunt    
Mark Otto committed
427
428
429
430
431
          $(_this3.element).on(eventIn, _this3.config.selector, function (event) {
            return _this3._enter(event);
          }).on(eventOut, _this3.config.selector, function (event) {
            return _this3._leave(event);
          });
432
        }
Mark Otto's avatar
grunt    
Mark Otto committed
433
434
435
436

        $(_this3.element).closest('.modal').on('hide.bs.modal', function () {
          return _this3.hide();
        });
Mark Otto's avatar
grunt    
Mark Otto committed
437
438
439
440
441
442
443
444
445
      });

      if (this.config.selector) {
        this.config = $.extend({}, this.config, {
          trigger: 'manual',
          selector: ''
        });
      } else {
        this._fixTitle();
446
      }
Mark Otto's avatar
grunt    
Mark Otto committed
447
    };
fat's avatar
fat committed
448

Mark Otto's avatar
grunt    
Mark Otto committed
449
450
451
452
453
454
455
    Tooltip.prototype._fixTitle = function _fixTitle() {
      var titleType = _typeof(this.element.getAttribute('data-original-title'));
      if (this.element.getAttribute('title') || titleType !== 'string') {
        this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
        this.element.setAttribute('title', '');
      }
    };
456

Mark Otto's avatar
grunt    
Mark Otto committed
457
458
    Tooltip.prototype._enter = function _enter(event, context) {
      var dataKey = this.constructor.DATA_KEY;
459

Mark Otto's avatar
grunt    
Mark Otto committed
460
      context = context || $(event.currentTarget).data(dataKey);
461

Mark Otto's avatar
grunt    
Mark Otto committed
462
463
464
465
      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
      }
466

Mark Otto's avatar
grunt    
Mark Otto committed
467
468
469
      if (event) {
        context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
      }
470

Mark Otto's avatar
grunt    
Mark Otto committed
471
472
      if ($(context.getTipElement()).hasClass(ClassName.SHOW) || context._hoverState === HoverState.SHOW) {
        context._hoverState = HoverState.SHOW;
Mark Otto's avatar
grunt    
Mark Otto committed
473
474
475
476
477
        return;
      }

      clearTimeout(context._timeout);

Mark Otto's avatar
grunt    
Mark Otto committed
478
      context._hoverState = HoverState.SHOW;
479

Mark Otto's avatar
grunt    
Mark Otto committed
480
481
482
483
484
485
      if (!context.config.delay || !context.config.delay.show) {
        context.show();
        return;
      }

      context._timeout = setTimeout(function () {
Mark Otto's avatar
grunt    
Mark Otto committed
486
        if (context._hoverState === HoverState.SHOW) {
487
488
          context.show();
        }
Mark Otto's avatar
grunt    
Mark Otto committed
489
490
      }, context.config.delay.show);
    };
491

Mark Otto's avatar
grunt    
Mark Otto committed
492
493
    Tooltip.prototype._leave = function _leave(event, context) {
      var dataKey = this.constructor.DATA_KEY;
fat's avatar
fat committed
494

Mark Otto's avatar
grunt    
Mark Otto committed
495
      context = context || $(event.currentTarget).data(dataKey);
496

Mark Otto's avatar
grunt    
Mark Otto committed
497
498
499
500
      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
      }
501

Mark Otto's avatar
grunt    
Mark Otto committed
502
503
504
      if (event) {
        context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
      }
505

Mark Otto's avatar
grunt    
Mark Otto committed
506
507
508
509
510
      if (context._isWithActiveTrigger()) {
        return;
      }

      clearTimeout(context._timeout);
511

Mark Otto's avatar
grunt    
Mark Otto committed
512
      context._hoverState = HoverState.OUT;
513

Mark Otto's avatar
grunt    
Mark Otto committed
514
515
516
517
      if (!context.config.delay || !context.config.delay.hide) {
        context.hide();
        return;
      }
518

Mark Otto's avatar
grunt    
Mark Otto committed
519
520
      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.OUT) {
521
522
          context.hide();
        }
Mark Otto's avatar
grunt    
Mark Otto committed
523
524
      }, context.config.delay.hide);
    };
525

Mark Otto's avatar
grunt    
Mark Otto committed
526
527
528
529
    Tooltip.prototype._isWithActiveTrigger = function _isWithActiveTrigger() {
      for (var trigger in this._activeTrigger) {
        if (this._activeTrigger[trigger]) {
          return true;
530
531
532
        }
      }

Mark Otto's avatar
grunt    
Mark Otto committed
533
534
535
536
537
      return false;
    };

    Tooltip.prototype._getConfig = function _getConfig(config) {
      config = $.extend({}, this.constructor.Default, $(this.element).data(), config);
fat's avatar
fat committed
538

Mark Otto's avatar
grunt    
Mark Otto committed
539
540
541
542
543
      if (config.delay && typeof config.delay === 'number') {
        config.delay = {
          show: config.delay,
          hide: config.delay
        };
544
      }
Mark Otto's avatar
grunt    
Mark Otto committed
545

Mark Otto's avatar
grunt    
Mark Otto committed
546
547
548
549
550
551
552
553
      if (config.title && typeof config.title === 'number') {
        config.title = config.title.toString();
      }

      if (config.content && typeof config.content === 'number') {
        config.content = config.content.toString();
      }

Mark Otto's avatar
grunt    
Mark Otto committed
554
555
556
557
558
559
560
561
562
563
564
565
      Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);

      return config;
    };

    Tooltip.prototype._getDelegateConfig = function _getDelegateConfig() {
      var config = {};

      if (this.config) {
        for (var key in this.config) {
          if (this.constructor.Default[key] !== this.config[key]) {
            config[key] = this.config[key];
566
567
568
          }
        }
      }
Jacob Thornton's avatar
Jacob Thornton committed
569

Mark Otto's avatar
grunt    
Mark Otto committed
570
571
      return config;
    };
Jacob Thornton's avatar
Jacob Thornton committed
572

Johann-S's avatar
build    
Johann-S committed
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
    Tooltip.prototype._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(''));
      }
    };

    Tooltip.prototype._handlePopperPlacementChange = function _handlePopperPlacementChange(data) {
      this._cleanTipClass();
      this.addAttachmentClass(this._getAttachment(data.placement));
    };

    Tooltip.prototype._fixTransition = function _fixTransition() {
      var tip = this.getTipElement();
      var initConfigAnimation = this.config.animation;
      if (tip.getAttribute('x-placement') !== null) {
        return;
      }
      $(tip).removeClass(ClassName.FADE);
      this.config.animation = false;
      this.hide();
      this.show();
      this.config.animation = initConfigAnimation;
    };

Mark Otto's avatar
grunt    
Mark Otto committed
599
    // static
Jacob Thornton's avatar
Jacob Thornton committed
600

Mark Otto's avatar
grunt    
Mark Otto committed
601
602
603
    Tooltip._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
604
        var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config;
605

Mark Otto's avatar
grunt    
Mark Otto committed
606
        if (!data && /dispose|hide/.test(config)) {
Mark Otto's avatar
grunt    
Mark Otto committed
607
608
          return;
        }
609

Mark Otto's avatar
grunt    
Mark Otto committed
610
611
612
613
614
615
616
617
        if (!data) {
          data = new Tooltip(this, _config);
          $(this).data(DATA_KEY, data);
        }

        if (typeof config === 'string') {
          if (data[config] === undefined) {
            throw new Error('No method named "' + config + '"');
Jacob Thornton's avatar
Jacob Thornton committed
618
          }
Mark Otto's avatar
grunt    
Mark Otto committed
619
620
621
622
623
624
          data[config]();
        }
      });
    };

    _createClass(Tooltip, null, [{
Jacob Thornton's avatar
Jacob Thornton committed
625
626
      key: 'VERSION',
      get: function get() {
627
628
629
630
        return VERSION;
      }
    }, {
      key: 'Default',
Jacob Thornton's avatar
Jacob Thornton committed
631
      get: function get() {
632
633
        return Default;
      }
fat's avatar
fat committed
634
635
    }, {
      key: 'NAME',
Jacob Thornton's avatar
Jacob Thornton committed
636
      get: function get() {
fat's avatar
fat committed
637
638
639
640
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
641
      get: function get() {
fat's avatar
fat committed
642
643
644
645
        return DATA_KEY;
      }
    }, {
      key: 'Event',
Jacob Thornton's avatar
Jacob Thornton committed
646
      get: function get() {
fat's avatar
fat committed
647
648
        return Event;
      }
fat's avatar
fat committed
649
650
    }, {
      key: 'EVENT_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
651
      get: function get() {
fat's avatar
fat committed
652
653
        return EVENT_KEY;
      }
fat's avatar
fat committed
654
655
    }, {
      key: 'DefaultType',
Jacob Thornton's avatar
Jacob Thornton committed
656
      get: function get() {
fat's avatar
fat committed
657
658
        return DefaultType;
      }
659
660
661
    }]);

    return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
662
663
664
665
666
667
668
  }();

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
669
670
671
672
673
674
675
676
677

  $.fn[NAME] = Tooltip._jQueryInterface;
  $.fn[NAME].Constructor = Tooltip;
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Tooltip._jQueryInterface;
  };

  return Tooltip;
Johann-S's avatar
build    
Johann-S committed
678
}(jQuery); /* global Popper */
Mark Otto's avatar
build    
Mark Otto committed
679
//# sourceMappingURL=tooltip.js.map