tooltip.js 16.6 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-alpha.5): 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
17
  /**
   * Check for Tether dependency
Mark Otto's avatar
grunt    
Mark Otto committed
18
   * Tether - http://tether.io/
19
   */
XhmikosR's avatar
XhmikosR committed
20
  if (window.Tether === undefined) {
Mark Otto's avatar
grunt    
Mark Otto committed
21
    throw new Error('Bootstrap tooltips require Tether (http://tether.io/)');
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-alpha.5';
32
  var DATA_KEY = 'bs.tooltip';
fat's avatar
fat committed
33
  var EVENT_KEY = '.' + DATA_KEY;
34
35
36
37
38
39
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  var TRANSITION_DURATION = 150;
  var CLASS_PREFIX = 'bs-tether';

  var Default = {
    animation: true,
Mark Otto's avatar
grunt    
Mark Otto committed
40
    template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-inner"></div></div>',
41
42
43
44
45
    trigger: 'hover focus',
    title: '',
    delay: 0,
    html: false,
    selector: false,
fat's avatar
fat committed
46
    placement: 'top',
47
    offset: '0 0',
fat's avatar
fat committed
48
49
50
51
52
53
    constraints: []
  };

  var DefaultType = {
    animation: 'boolean',
    template: 'string',
XhmikosR's avatar
XhmikosR committed
54
    title: '(string|element|function)',
fat's avatar
fat committed
55
56
57
58
59
60
61
    trigger: 'string',
    delay: '(number|object)',
    html: 'boolean',
    selector: '(string|boolean)',
    placement: '(string|function)',
    offset: 'string',
    constraints: 'array'
62
63
  };

fat's avatar
fat committed
64
65
66
67
68
  var AttachmentMap = {
    TOP: 'bottom center',
    RIGHT: 'middle left',
    BOTTOM: 'top center',
    LEFT: 'middle right'
69
70
71
  };

  var HoverState = {
Mark Otto's avatar
grunt    
Mark Otto committed
72
    ACTIVE: 'active',
73
74
75
76
    OUT: 'out'
  };

  var Event = {
fat's avatar
fat committed
77
78
79
80
81
82
83
84
85
86
    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
87
88
89
90
  };

  var ClassName = {
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
91
    ACTIVE: 'active'
92
93
94
95
  };

  var Selector = {
    TOOLTIP: '.tooltip',
96
97
    TOOLTIP_INNER: '.tooltip-inner'
  };
98
99

  var TetherClass = {
fat's avatar
fat committed
100
101
102
103
104
105
106
107
108
    element: false,
    enabled: false
  };

  var Trigger = {
    HOVER: 'hover',
    FOCUS: 'focus',
    CLICK: 'click',
    MANUAL: 'manual'
109
110
111
112
113
114
115
116
  };

  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */

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 = {};
fat's avatar
fat committed
126
      this._tether = 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.ACTIVE)) {
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
      this.cleanupTether();
184

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

Mark Otto's avatar
grunt    
Mark Otto committed
187
      $(this.element).off(this.constructor.EVENT_KEY);
188

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

Mark Otto's avatar
grunt    
Mark Otto committed
193
194
195
196
197
      this._isEnabled = null;
      this._timeout = null;
      this._hoverState = null;
      this._activeTrigger = null;
      this._tether = null;
198

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
212
213
      if (this.isWithContent() && this._isEnabled) {
        $(this.element).trigger(showEvent);
214

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

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
227
        this.setContent();
228

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
235
        var attachment = this._getAttachment(placement);
236

Mark Otto's avatar
grunt    
Mark Otto committed
237
        $(tip).data(this.constructor.DATA_KEY, this).appendTo(document.body);
Mark Otto's avatar
Mark Otto committed
238

Mark Otto's avatar
grunt    
Mark Otto committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
        $(this.element).trigger(this.constructor.Event.INSERTED);

        this._tether = new Tether({
          attachment: attachment,
          element: tip,
          target: this.element,
          classes: TetherClass,
          classPrefix: CLASS_PREFIX,
          offset: this.config.offset,
          constraints: this.config.constraints,
          addTargetClasses: false
        });

        Util.reflow(tip);
        this._tether.position();

Mark Otto's avatar
grunt    
Mark Otto committed
255
        $(tip).addClass(ClassName.ACTIVE);
256
257

        var complete = function complete() {
Mark Otto's avatar
grunt    
Mark Otto committed
258
259
          var prevHoverState = _this._hoverState;
          _this._hoverState = null;
260

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

Mark Otto's avatar
grunt    
Mark Otto committed
263
264
          if (prevHoverState === HoverState.OUT) {
            _this._leave(null, _this);
265
266
267
          }
        };

Mark Otto's avatar
grunt    
Mark Otto committed
268
269
        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
          $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
270
271
272
          return;
        }

Mark Otto's avatar
grunt    
Mark Otto committed
273
274
275
        complete();
      }
    };
276

Mark Otto's avatar
grunt    
Mark Otto committed
277
278
    Tooltip.prototype.hide = function hide(callback) {
      var _this2 = this;
279

Mark Otto's avatar
grunt    
Mark Otto committed
280
281
282
      var tip = this.getTipElement();
      var hideEvent = $.Event(this.constructor.Event.HIDE);
      var complete = function complete() {
Mark Otto's avatar
grunt    
Mark Otto committed
283
        if (_this2._hoverState !== HoverState.ACTIVE && tip.parentNode) {
Mark Otto's avatar
grunt    
Mark Otto committed
284
          tip.parentNode.removeChild(tip);
285
286
        }

Mark Otto's avatar
grunt    
Mark Otto committed
287
288
289
        _this2.element.removeAttribute('aria-describedby');
        $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);
        _this2.cleanupTether();
290

Mark Otto's avatar
grunt    
Mark Otto committed
291
292
293
294
        if (callback) {
          callback();
        }
      };
295

Mark Otto's avatar
grunt    
Mark Otto committed
296
297
298
299
      $(this.element).trigger(hideEvent);

      if (hideEvent.isDefaultPrevented()) {
        return;
300
301
      }

Mark Otto's avatar
grunt    
Mark Otto committed
302
      $(tip).removeClass(ClassName.ACTIVE);
303

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

Mark Otto's avatar
grunt    
Mark Otto committed
306
307
308
        $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
      } else {
        complete();
309
      }
Mark Otto's avatar
grunt    
Mark Otto committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

      this._hoverState = '';
    };

    // protected

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

    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
329
      $tip.removeClass(ClassName.FADE).removeClass(ClassName.ACTIVE);
Mark Otto's avatar
grunt    
Mark Otto committed
330
331
332
333
334
335
336
337
338
339
340

      this.cleanupTether();
    };

    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
341
342
          }
        } else {
Mark Otto's avatar
grunt    
Mark Otto committed
343
          $element.text($(content).text());
XhmikosR's avatar
XhmikosR committed
344
        }
Mark Otto's avatar
grunt    
Mark Otto committed
345
346
      } else {
        $element[html ? 'html' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
347
      }
Mark Otto's avatar
grunt    
Mark Otto committed
348
    };
349

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

Mark Otto's avatar
grunt    
Mark Otto committed
353
354
      if (!title) {
        title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
355
356
      }

Mark Otto's avatar
grunt    
Mark Otto committed
357
358
      return title;
    };
359

Mark Otto's avatar
grunt    
Mark Otto committed
360
361
362
    Tooltip.prototype.cleanupTether = function cleanupTether() {
      if (this._tether) {
        this._tether.destroy();
fat's avatar
fat committed
363
      }
Mark Otto's avatar
grunt    
Mark Otto committed
364
    };
365

Mark Otto's avatar
grunt    
Mark Otto committed
366
    // private
367

Mark Otto's avatar
grunt    
Mark Otto committed
368
369
370
    Tooltip.prototype._getAttachment = function _getAttachment(placement) {
      return AttachmentMap[placement.toUpperCase()];
    };
371

Mark Otto's avatar
grunt    
Mark Otto committed
372
373
    Tooltip.prototype._setListeners = function _setListeners() {
      var _this3 = this;
374

Mark Otto's avatar
grunt    
Mark Otto committed
375
376
377
378
      var triggers = this.config.trigger.split(' ');

      triggers.forEach(function (trigger) {
        if (trigger === 'click') {
Mark Otto's avatar
grunt    
Mark Otto committed
379
380
381
          $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, function (event) {
            return _this3.toggle(event);
          });
Mark Otto's avatar
grunt    
Mark Otto committed
382
383
384
385
        } 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
386
387
388
389
390
          $(_this3.element).on(eventIn, _this3.config.selector, function (event) {
            return _this3._enter(event);
          }).on(eventOut, _this3.config.selector, function (event) {
            return _this3._leave(event);
          });
391
        }
Mark Otto's avatar
grunt    
Mark Otto committed
392
393
394
395
396
397
398
399
400
      });

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

Mark Otto's avatar
grunt    
Mark Otto committed
404
405
406
407
408
409
410
    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', '');
      }
    };
411

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
417
418
419
420
      if (!context) {
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
        $(event.currentTarget).data(dataKey, context);
      }
421

Mark Otto's avatar
grunt    
Mark Otto committed
422
423
424
      if (event) {
        context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
      }
425

Mark Otto's avatar
grunt    
Mark Otto committed
426
427
      if ($(context.getTipElement()).hasClass(ClassName.ACTIVE) || context._hoverState === HoverState.ACTIVE) {
        context._hoverState = HoverState.ACTIVE;
Mark Otto's avatar
grunt    
Mark Otto committed
428
429
430
431
432
        return;
      }

      clearTimeout(context._timeout);

Mark Otto's avatar
grunt    
Mark Otto committed
433
      context._hoverState = HoverState.ACTIVE;
434

Mark Otto's avatar
grunt    
Mark Otto committed
435
436
437
438
439
440
      if (!context.config.delay || !context.config.delay.show) {
        context.show();
        return;
      }

      context._timeout = setTimeout(function () {
Mark Otto's avatar
grunt    
Mark Otto committed
441
        if (context._hoverState === HoverState.ACTIVE) {
442
443
          context.show();
        }
Mark Otto's avatar
grunt    
Mark Otto committed
444
445
      }, context.config.delay.show);
    };
446

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

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
461
462
463
464
465
      if (context._isWithActiveTrigger()) {
        return;
      }

      clearTimeout(context._timeout);
466

Mark Otto's avatar
grunt    
Mark Otto committed
467
      context._hoverState = HoverState.OUT;
468

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

Mark Otto's avatar
grunt    
Mark Otto committed
474
475
      context._timeout = setTimeout(function () {
        if (context._hoverState === HoverState.OUT) {
476
477
          context.hide();
        }
Mark Otto's avatar
grunt    
Mark Otto committed
478
479
      }, context.config.delay.hide);
    };
480

Mark Otto's avatar
grunt    
Mark Otto committed
481
482
483
484
    Tooltip.prototype._isWithActiveTrigger = function _isWithActiveTrigger() {
      for (var trigger in this._activeTrigger) {
        if (this._activeTrigger[trigger]) {
          return true;
485
486
487
        }
      }

Mark Otto's avatar
grunt    
Mark Otto committed
488
489
490
491
492
      return false;
    };

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

Mark Otto's avatar
grunt    
Mark Otto committed
494
495
496
497
498
      if (config.delay && typeof config.delay === 'number') {
        config.delay = {
          show: config.delay,
          hide: config.delay
        };
499
      }
Mark Otto's avatar
grunt    
Mark Otto committed
500
501
502
503
504
505
506
507
508
509
510
511
512

      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];
513
514
515
          }
        }
      }
Jacob Thornton's avatar
Jacob Thornton committed
516

Mark Otto's avatar
grunt    
Mark Otto committed
517
518
      return config;
    };
Jacob Thornton's avatar
Jacob Thornton committed
519

Mark Otto's avatar
grunt    
Mark Otto committed
520
    // static
Jacob Thornton's avatar
Jacob Thornton committed
521

Mark Otto's avatar
grunt    
Mark Otto committed
522
523
524
    Tooltip._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
525
        var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config;
526

Mark Otto's avatar
grunt    
Mark Otto committed
527
        if (!data && /dispose|hide/.test(config)) {
Mark Otto's avatar
grunt    
Mark Otto committed
528
529
          return;
        }
530

Mark Otto's avatar
grunt    
Mark Otto committed
531
532
533
534
535
536
537
538
        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
539
          }
Mark Otto's avatar
grunt    
Mark Otto committed
540
541
542
543
544
545
          data[config]();
        }
      });
    };

    _createClass(Tooltip, null, [{
Jacob Thornton's avatar
Jacob Thornton committed
546
547
      key: 'VERSION',
      get: function get() {
548
549
550
551
        return VERSION;
      }
    }, {
      key: 'Default',
Jacob Thornton's avatar
Jacob Thornton committed
552
      get: function get() {
553
554
        return Default;
      }
fat's avatar
fat committed
555
556
    }, {
      key: 'NAME',
Jacob Thornton's avatar
Jacob Thornton committed
557
      get: function get() {
fat's avatar
fat committed
558
559
560
561
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
562
      get: function get() {
fat's avatar
fat committed
563
564
565
566
        return DATA_KEY;
      }
    }, {
      key: 'Event',
Jacob Thornton's avatar
Jacob Thornton committed
567
      get: function get() {
fat's avatar
fat committed
568
569
        return Event;
      }
fat's avatar
fat committed
570
571
    }, {
      key: 'EVENT_KEY',
Jacob Thornton's avatar
Jacob Thornton committed
572
      get: function get() {
fat's avatar
fat committed
573
574
        return EVENT_KEY;
      }
fat's avatar
fat committed
575
576
    }, {
      key: 'DefaultType',
Jacob Thornton's avatar
Jacob Thornton committed
577
      get: function get() {
fat's avatar
fat committed
578
579
        return DefaultType;
      }
580
581
582
    }]);

    return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
583
584
585
586
587
588
589
  }();

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
590
591
592
593
594
595
596
597
598

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

  return Tooltip;
Mark Otto's avatar
grunt    
Mark Otto committed
599
}(jQuery); /* global Tether */
Jacob Thornton's avatar
Jacob Thornton committed
600
//# sourceMappingURL=tooltip.js.map