tab.js 11.4 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap tab.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/data.js'), require('../dom/event-handler.js'), require('../dom/selector-engine.js')) :
  typeof define === 'function' && define.amd ? define(['../dom/data.js', '../dom/event-handler.js', '../dom/selector-engine.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
10
  (global = global || self, global.Tab = factory(global.Data, global.EventHandler, global.SelectorEngine));
}(this, function (Data, EventHandler, SelectorEngine) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
  Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

  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);
    }
  }

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

XhmikosR's avatar
XhmikosR committed
32
33
34
35
36
37
38
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
39
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
40

XhmikosR's avatar
XhmikosR committed
41
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
42
43
44
45
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
XhmikosR's avatar
XhmikosR committed
46
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
XhmikosR's avatar
XhmikosR committed
47
48
    }

XhmikosR's avatar
XhmikosR committed
49
50
51
52
53
54
    return selector;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  };

  var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) {
    if (!element) {
      return 0;
    } // Get transition-duration of the element


    var _window$getComputedSt = window.getComputedStyle(element),
        transitionDuration = _window$getComputedSt.transitionDuration,
        transitionDelay = _window$getComputedSt.transitionDelay;

    var floatTransitionDuration = parseFloat(transitionDuration);
    var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found

    if (!floatTransitionDuration && !floatTransitionDelay) {
      return 0;
    } // If multiple durations are defined, take the first


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
    return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
XhmikosR's avatar
XhmikosR committed
81
82
83
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent(TRANSITION_END, true, true);
    element.dispatchEvent(evt);
XhmikosR's avatar
XhmikosR committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  };

  var emulateTransitionEnd = function emulateTransitionEnd(element, duration) {
    var called = false;
    var durationPadding = 5;
    var emulatedDuration = duration + durationPadding;

    function listener() {
      called = true;
      element.removeEventListener(TRANSITION_END, listener);
    }

    element.addEventListener(TRANSITION_END, listener);
    setTimeout(function () {
      if (!called) {
        triggerTransitionEnd(element);
      }
    }, emulatedDuration);
  };

  var makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

    return [].slice.call(nodeList);
  };

  var reflow = function reflow(element) {
    return element.offsetHeight;
  };

XhmikosR's avatar
XhmikosR committed
116
117
118
119
120
121
122
123
124
125
126
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

    if (jQuery && !document.body.hasAttribute('data-no-jquery')) {
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
Dist    
XhmikosR committed
127
128
129
130
131
132
133
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'tab';
XhmikosR's avatar
XhmikosR committed
134
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
135
136
137
  var DATA_KEY = 'bs.tab';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
XhmikosR's avatar
XhmikosR committed
138
  var Event = {
XhmikosR's avatar
Dist    
XhmikosR committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    HIDE: "hide" + EVENT_KEY,
    HIDDEN: "hidden" + EVENT_KEY,
    SHOW: "show" + EVENT_KEY,
    SHOWN: "shown" + EVENT_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
    DROPDOWN_MENU: 'dropdown-menu',
    ACTIVE: 'active',
    DISABLED: 'disabled',
    FADE: 'fade',
    SHOW: 'show'
  };
  var Selector = {
    DROPDOWN: '.dropdown',
    NAV_LIST_GROUP: '.nav, .list-group',
    ACTIVE: '.active',
XhmikosR's avatar
XhmikosR committed
156
    ACTIVE_UL: ':scope > li > .active',
XhmikosR's avatar
Dist    
XhmikosR committed
157
158
    DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"], [data-toggle="list"]',
    DROPDOWN_TOGGLE: '.dropdown-toggle',
XhmikosR's avatar
XhmikosR committed
159
    DROPDOWN_ACTIVE_CHILD: ':scope > .dropdown-menu .active'
Mark Otto's avatar
dist    
Mark Otto committed
160
161
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
162
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
163
164
     * ------------------------------------------------------------------------
     */
fat's avatar
tab es6  
fat committed
165

XhmikosR's avatar
Dist    
XhmikosR committed
166
  };
fat's avatar
tab es6  
fat committed
167

XhmikosR's avatar
Dist    
XhmikosR committed
168
169
170
171
172
  var Tab =
  /*#__PURE__*/
  function () {
    function Tab(element) {
      this._element = element;
XhmikosR's avatar
XhmikosR committed
173
      Data.setData(this._element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
174
    } // Getters
Jacob Thornton's avatar
Jacob Thornton committed
175

fat's avatar
tab es6  
fat committed
176

XhmikosR's avatar
Dist    
XhmikosR committed
177
    var _proto = Tab.prototype;
fat's avatar
tab es6  
fat committed
178

XhmikosR's avatar
Dist    
XhmikosR committed
179
180
181
    // Public
    _proto.show = function show() {
      var _this = this;
fat's avatar
tab es6  
fat committed
182

XhmikosR's avatar
XhmikosR committed
183
      if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(ClassName.ACTIVE) || this._element.classList.contains(ClassName.DISABLED)) {
XhmikosR's avatar
Dist    
XhmikosR committed
184
185
        return;
      }
fat's avatar
tab es6  
fat committed
186

XhmikosR's avatar
Dist    
XhmikosR committed
187
      var previous;
XhmikosR's avatar
XhmikosR committed
188
      var target = getElementFromSelector(this._element);
XhmikosR's avatar
XhmikosR committed
189
      var listElement = SelectorEngine.closest(this._element, Selector.NAV_LIST_GROUP);
fat's avatar
tab es6  
fat committed
190

XhmikosR's avatar
Dist    
XhmikosR committed
191
      if (listElement) {
XhmikosR's avatar
Dist    
XhmikosR committed
192
        var itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? Selector.ACTIVE_UL : Selector.ACTIVE;
XhmikosR's avatar
XhmikosR committed
193
        previous = makeArray(SelectorEngine.find(itemSelector, listElement));
XhmikosR's avatar
Dist    
XhmikosR committed
194
195
        previous = previous[previous.length - 1];
      }
fat's avatar
tab es6  
fat committed
196

XhmikosR's avatar
XhmikosR committed
197
      var hideEvent = null;
fat's avatar
tab es6  
fat committed
198

XhmikosR's avatar
Dist    
XhmikosR committed
199
      if (previous) {
XhmikosR's avatar
XhmikosR committed
200
        hideEvent = EventHandler.trigger(previous, Event.HIDE, {
XhmikosR's avatar
XhmikosR committed
201
202
          relatedTarget: this._element
        });
XhmikosR's avatar
Dist    
XhmikosR committed
203
      }
fat's avatar
tab es6  
fat committed
204

XhmikosR's avatar
XhmikosR committed
205
      var showEvent = EventHandler.trigger(this._element, Event.SHOW, {
XhmikosR's avatar
XhmikosR committed
206
207
        relatedTarget: previous
      });
fat's avatar
tab es6  
fat committed
208

XhmikosR's avatar
XhmikosR committed
209
      if (showEvent.defaultPrevented || hideEvent !== null && hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
210
211
        return;
      }
fat's avatar
tab es6  
fat committed
212

XhmikosR's avatar
Dist    
XhmikosR committed
213
214
215
      this._activate(this._element, listElement);

      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
216
        EventHandler.trigger(previous, Event.HIDDEN, {
XhmikosR's avatar
Dist    
XhmikosR committed
217
218
          relatedTarget: _this._element
        });
XhmikosR's avatar
XhmikosR committed
219
        EventHandler.trigger(_this._element, Event.SHOWN, {
XhmikosR's avatar
Dist    
XhmikosR committed
220
221
          relatedTarget: previous
        });
Mark Otto's avatar
dist    
Mark Otto committed
222
223
      };

XhmikosR's avatar
Dist    
XhmikosR committed
224
225
226
227
228
229
      if (target) {
        this._activate(target, target.parentNode, complete);
      } else {
        complete();
      }
    };
fat's avatar
tab es6  
fat committed
230

XhmikosR's avatar
Dist    
XhmikosR committed
231
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
232
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
233
      this._element = null;
Mark Otto's avatar
Mark Otto committed
234
235
    } // Private
    ;
Mark Otto's avatar
dist    
Mark Otto committed
236

XhmikosR's avatar
Dist    
XhmikosR committed
237
238
    _proto._activate = function _activate(element, container, callback) {
      var _this2 = this;
fat's avatar
tab es6  
fat committed
239

XhmikosR's avatar
XhmikosR committed
240
      var activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? SelectorEngine.find(Selector.ACTIVE_UL, container) : SelectorEngine.children(container, Selector.ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
241
      var active = activeElements[0];
XhmikosR's avatar
XhmikosR committed
242
      var isTransitioning = callback && active && active.classList.contains(ClassName.FADE);
Mark Otto's avatar
grunt    
Mark Otto committed
243

XhmikosR's avatar
Dist    
XhmikosR committed
244
245
      var complete = function complete() {
        return _this2._transitionComplete(element, active, callback);
Mark Otto's avatar
dist    
Mark Otto committed
246
      };
fat's avatar
tab es6  
fat committed
247

XhmikosR's avatar
Dist    
XhmikosR committed
248
      if (active && isTransitioning) {
XhmikosR's avatar
XhmikosR committed
249
250
251
252
        var transitionDuration = getTransitionDurationFromElement(active);
        active.classList.remove(ClassName.SHOW);
        EventHandler.one(active, TRANSITION_END, complete);
        emulateTransitionEnd(active, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
253
254
255
256
      } else {
        complete();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
257

XhmikosR's avatar
Dist    
XhmikosR committed
258
259
    _proto._transitionComplete = function _transitionComplete(element, active, callback) {
      if (active) {
XhmikosR's avatar
XhmikosR committed
260
261
        active.classList.remove(ClassName.ACTIVE);
        var dropdownChild = SelectorEngine.findOne(Selector.DROPDOWN_ACTIVE_CHILD, active.parentNode);
fat's avatar
tab es6  
fat committed
262

XhmikosR's avatar
Dist    
XhmikosR committed
263
        if (dropdownChild) {
XhmikosR's avatar
XhmikosR committed
264
          dropdownChild.classList.remove(ClassName.ACTIVE);
Mark Otto's avatar
dist    
Mark Otto committed
265
        }
fat's avatar
tab es6  
fat committed
266

XhmikosR's avatar
Dist    
XhmikosR committed
267
268
        if (active.getAttribute('role') === 'tab') {
          active.setAttribute('aria-selected', false);
Mark Otto's avatar
dist    
Mark Otto committed
269
        }
XhmikosR's avatar
Dist    
XhmikosR committed
270
      }
fat's avatar
tab es6  
fat committed
271

XhmikosR's avatar
XhmikosR committed
272
      element.classList.add(ClassName.ACTIVE);
fat's avatar
tab es6  
fat committed
273

XhmikosR's avatar
Dist    
XhmikosR committed
274
275
276
      if (element.getAttribute('role') === 'tab') {
        element.setAttribute('aria-selected', true);
      }
fat's avatar
tab es6  
fat committed
277

XhmikosR's avatar
XhmikosR committed
278
      reflow(element);
Mark Otto's avatar
Mark Otto committed
279
280
281
282

      if (element.classList.contains(ClassName.FADE)) {
        element.classList.add(ClassName.SHOW);
      }
fat's avatar
tab es6  
fat committed
283

XhmikosR's avatar
XhmikosR committed
284
285
      if (element.parentNode && element.parentNode.classList.contains(ClassName.DROPDOWN_MENU)) {
        var dropdownElement = SelectorEngine.closest(element, Selector.DROPDOWN);
fat's avatar
tab es6  
fat committed
286

XhmikosR's avatar
Dist    
XhmikosR committed
287
        if (dropdownElement) {
XhmikosR's avatar
XhmikosR committed
288
289
290
          makeArray(SelectorEngine.find(Selector.DROPDOWN_TOGGLE)).forEach(function (dropdown) {
            return dropdown.classList.add(ClassName.ACTIVE);
          });
Mark Otto's avatar
dist    
Mark Otto committed
291
        }
Mark Otto's avatar
grunt    
Mark Otto committed
292

XhmikosR's avatar
Dist    
XhmikosR committed
293
294
        element.setAttribute('aria-expanded', true);
      }
Mark Otto's avatar
dist    
Mark Otto committed
295

XhmikosR's avatar
Dist    
XhmikosR committed
296
297
298
      if (callback) {
        callback();
      }
Mark Otto's avatar
Mark Otto committed
299
300
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
301

XhmikosR's avatar
XhmikosR committed
302
    Tab.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
Dist    
XhmikosR committed
303
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
304
        var data = Data.getData(this, DATA_KEY) || new Tab(this);
Mark Otto's avatar
dist    
Mark Otto committed
305

XhmikosR's avatar
Dist    
XhmikosR committed
306
307
308
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
309
          }
Mark Otto's avatar
dist    
Mark Otto committed
310

XhmikosR's avatar
Dist    
XhmikosR committed
311
          data[config]();
Mark Otto's avatar
dist    
Mark Otto committed
312
        }
XhmikosR's avatar
Dist    
XhmikosR committed
313
314
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
315

XhmikosR's avatar
XhmikosR committed
316
    Tab.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
317
318
319
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
320
321
322
323
324
325
    _createClass(Tab, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }]);
fat's avatar
tab es6  
fat committed
326

XhmikosR's avatar
Dist    
XhmikosR committed
327
328
329
330
331
332
333
    return Tab;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
fat's avatar
tab es6  
fat committed
334

Mark Otto's avatar
dist    
Mark Otto committed
335

XhmikosR's avatar
XhmikosR committed
336
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
337
    event.preventDefault();
XhmikosR's avatar
XhmikosR committed
338
339
    var data = Data.getData(this, DATA_KEY) || new Tab(this);
    data.show();
XhmikosR's avatar
Dist    
XhmikosR committed
340
  });
XhmikosR's avatar
XhmikosR committed
341
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
342
343
344
345
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
346
   * add .tab to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
347
   */
fat's avatar
tab es6  
fat committed
348

349
350
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
351
352
353
354
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Tab.jQueryInterface;
    $.fn[NAME].Constructor = Tab;
Mark Otto's avatar
dist    
Mark Otto committed
355

XhmikosR's avatar
XhmikosR committed
356
357
358
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Tab.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
359
360
    };
  }
fat's avatar
tab es6  
fat committed
361
362

  return Tab;
Mark Otto's avatar
dist    
Mark Otto committed
363

Mark Otto's avatar
Mark Otto committed
364
}));
Mark Otto's avatar
dist    
Mark Otto committed
365
//# sourceMappingURL=tab.js.map