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

XhmikosR's avatar
XhmikosR committed
12
13
14
15
16
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
  var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
  var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
  var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
Mark Otto's avatar
dist    
Mark Otto committed
18

XhmikosR's avatar
XhmikosR committed
19
20
  /**
   * --------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
21
   * Bootstrap (v5.0.0-alpha3): util/index.js
XhmikosR's avatar
XhmikosR committed
22
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
23
24
25
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
26
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
27
28

  var toType = function toType(obj) {
XhmikosR's avatar
XhmikosR committed
29
30
31
32
    if (obj === null || obj === undefined) {
      return "" + obj;
    }

XhmikosR's avatar
XhmikosR committed
33
34
35
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

XhmikosR's avatar
XhmikosR committed
36
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
37
    var selector = element.getAttribute('data-bs-target');
XhmikosR's avatar
XhmikosR committed
38
39
40

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

XhmikosR's avatar
XhmikosR committed
44
45
46
47
48
49
50
    return selector;
  };

  var getSelectorFromElement = function getSelectorFromElement(element) {
    var selector = getSelector(element);

    if (selector) {
XhmikosR's avatar
XhmikosR committed
51
52
      return document.querySelector(selector) ? selector : null;
    }
XhmikosR's avatar
XhmikosR committed
53
54
55
56
57
58
59

    return null;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
60
61
62
63
64
65
66
67
68
69
70
71
  };

  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;

XhmikosR's avatar
XhmikosR committed
72
73
    var floatTransitionDuration = Number.parseFloat(transitionDuration);
    var floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
XhmikosR's avatar
XhmikosR committed
74
75
76
77
78
79
80
81

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


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
XhmikosR's avatar
XhmikosR committed
82
    return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
XhmikosR's avatar
XhmikosR committed
83
84
85
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
XhmikosR's avatar
XhmikosR committed
86
    element.dispatchEvent(new Event(TRANSITION_END));
XhmikosR's avatar
XhmikosR committed
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
116
117
118
119
120
121
122
123
124
125
126
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  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 typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

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

XhmikosR's avatar
XhmikosR committed
127
128
129
130
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

XhmikosR's avatar
XhmikosR committed
131
    if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
XhmikosR's avatar
XhmikosR committed
132
133
134
135
136
137
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
XhmikosR committed
138
139
140
141
142
143
144
145
  var onDOMContentLoaded = function onDOMContentLoaded(callback) {
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', callback);
    } else {
      callback();
    }
  };

XhmikosR's avatar
XhmikosR committed
146
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
Mark Otto's avatar
Mark Otto committed
147
148
149
150

  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; }
XhmikosR's avatar
Dist    
XhmikosR committed
151
152
153
154
155
156
157
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'collapse';
XhmikosR's avatar
XhmikosR committed
158
  var VERSION = '5.0.0-alpha3';
XhmikosR's avatar
Dist    
XhmikosR committed
159
160
161
162
163
164
165
166
167
168
169
  var DATA_KEY = 'bs.collapse';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var Default = {
    toggle: true,
    parent: ''
  };
  var DefaultType = {
    toggle: 'boolean',
    parent: '(string|element)'
  };
XhmikosR's avatar
XhmikosR committed
170
171
172
173
174
175
176
177
178
179
180
181
  var EVENT_SHOW = "show" + EVENT_KEY;
  var EVENT_SHOWN = "shown" + EVENT_KEY;
  var EVENT_HIDE = "hide" + EVENT_KEY;
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
  var CLASS_NAME_SHOW = 'show';
  var CLASS_NAME_COLLAPSE = 'collapse';
  var CLASS_NAME_COLLAPSING = 'collapsing';
  var CLASS_NAME_COLLAPSED = 'collapsed';
  var WIDTH = 'width';
  var HEIGHT = 'height';
  var SELECTOR_ACTIVES = '.show, .collapsing';
XhmikosR's avatar
XhmikosR committed
182
  var SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]';
XhmikosR's avatar
XhmikosR committed
183
184
185
186
187
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
188

XhmikosR's avatar
XhmikosR committed
189
  var Collapse = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
190
191
192
193
    function Collapse(element, config) {
      this._isTransitioning = false;
      this._element = element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
194
      this._triggerArray = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE + "[href=\"#" + element.id + "\"]," + (SELECTOR_DATA_TOGGLE + "[data-bs-target=\"#" + element.id + "\"]"));
XhmikosR's avatar
XhmikosR committed
195
      var toggleList = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE);
XhmikosR's avatar
Dist    
XhmikosR committed
196
197
198

      for (var i = 0, len = toggleList.length; i < len; i++) {
        var elem = toggleList[i];
XhmikosR's avatar
XhmikosR committed
199
        var selector = getSelectorFromElement(elem);
XhmikosR's avatar
XhmikosR committed
200
        var filterElement = SelectorEngine__default['default'].find(selector).filter(function (foundElem) {
XhmikosR's avatar
Dist    
XhmikosR committed
201
202
          return foundElem === element;
        });
Johann-S's avatar
build    
Johann-S committed
203

XhmikosR's avatar
XhmikosR committed
204
        if (selector !== null && filterElement.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
205
          this._selector = selector;
fat's avatar
fat committed
206

XhmikosR's avatar
Dist    
XhmikosR committed
207
          this._triggerArray.push(elem);
Mark Otto's avatar
dist    
Mark Otto committed
208
        }
XhmikosR's avatar
Dist    
XhmikosR committed
209
      }
fat's avatar
fat committed
210

XhmikosR's avatar
Dist    
XhmikosR committed
211
      this._parent = this._config.parent ? this._getParent() : null;
fat's avatar
fat committed
212

XhmikosR's avatar
Dist    
XhmikosR committed
213
214
215
      if (!this._config.parent) {
        this._addAriaAndCollapsedClass(this._element, this._triggerArray);
      }
Jacob Thornton's avatar
Jacob Thornton committed
216

XhmikosR's avatar
Dist    
XhmikosR committed
217
218
219
      if (this._config.toggle) {
        this.toggle();
      }
XhmikosR's avatar
XhmikosR committed
220

XhmikosR's avatar
XhmikosR committed
221
      Data__default['default'].setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
222
    } // Getters
fat's avatar
fat committed
223
224


XhmikosR's avatar
Dist    
XhmikosR committed
225
    var _proto = Collapse.prototype;
Mark Otto's avatar
grunt    
Mark Otto committed
226

XhmikosR's avatar
Dist    
XhmikosR committed
227
228
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
229
      if (this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
230
231
232
233
234
        this.hide();
      } else {
        this.show();
      }
    };
fat's avatar
fat committed
235

XhmikosR's avatar
Dist    
XhmikosR committed
236
237
    _proto.show = function show() {
      var _this = this;
fat's avatar
fat committed
238

XhmikosR's avatar
XhmikosR committed
239
      if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
240
241
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
242

XhmikosR's avatar
Dist    
XhmikosR committed
243
244
      var actives;
      var activesData;
fat's avatar
fat committed
245

XhmikosR's avatar
Dist    
XhmikosR committed
246
      if (this._parent) {
XhmikosR's avatar
XhmikosR committed
247
        actives = SelectorEngine__default['default'].find(SELECTOR_ACTIVES, this._parent).filter(function (elem) {
XhmikosR's avatar
Dist    
XhmikosR committed
248
          if (typeof _this._config.parent === 'string') {
XhmikosR's avatar
XhmikosR committed
249
            return elem.getAttribute('data-bs-parent') === _this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
250
          }
fat's avatar
fat committed
251

XhmikosR's avatar
XhmikosR committed
252
          return elem.classList.contains(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
Dist    
XhmikosR committed
253
        });
fat's avatar
fat committed
254

XhmikosR's avatar
Dist    
XhmikosR committed
255
256
        if (actives.length === 0) {
          actives = null;
Mark Otto's avatar
dist    
Mark Otto committed
257
        }
XhmikosR's avatar
Dist    
XhmikosR committed
258
      }
fat's avatar
fat committed
259

XhmikosR's avatar
XhmikosR committed
260
      var container = SelectorEngine__default['default'].findOne(this._selector);
XhmikosR's avatar
XhmikosR committed
261

XhmikosR's avatar
Dist    
XhmikosR committed
262
      if (actives) {
XhmikosR's avatar
XhmikosR committed
263
        var tempActiveData = actives.find(function (elem) {
XhmikosR's avatar
XhmikosR committed
264
265
          return container !== elem;
        });
XhmikosR's avatar
XhmikosR committed
266
        activesData = tempActiveData ? Data__default['default'].getData(tempActiveData, DATA_KEY) : null;
fat's avatar
fat committed
267

XhmikosR's avatar
Dist    
XhmikosR committed
268
        if (activesData && activesData._isTransitioning) {
Mark Otto's avatar
dist    
Mark Otto committed
269
270
          return;
        }
XhmikosR's avatar
Dist    
XhmikosR committed
271
      }
fat's avatar
fat committed
272

XhmikosR's avatar
XhmikosR committed
273
      var startEvent = EventHandler__default['default'].trigger(this._element, EVENT_SHOW);
fat's avatar
fat committed
274

XhmikosR's avatar
XhmikosR committed
275
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
276
277
        return;
      }
fat's avatar
fat committed
278

XhmikosR's avatar
Dist    
XhmikosR committed
279
      if (actives) {
XhmikosR's avatar
XhmikosR committed
280
281
        actives.forEach(function (elemActive) {
          if (container !== elemActive) {
XhmikosR's avatar
XhmikosR committed
282
            Collapse.collapseInterface(elemActive, 'hide');
XhmikosR's avatar
XhmikosR committed
283
          }
fat's avatar
fat committed
284

XhmikosR's avatar
XhmikosR committed
285
          if (!activesData) {
XhmikosR's avatar
XhmikosR committed
286
            Data__default['default'].setData(elemActive, DATA_KEY, null);
XhmikosR's avatar
XhmikosR committed
287
288
          }
        });
XhmikosR's avatar
Dist    
XhmikosR committed
289
      }
fat's avatar
fat committed
290

XhmikosR's avatar
Dist    
XhmikosR committed
291
292
      var dimension = this._getDimension();

XhmikosR's avatar
XhmikosR committed
293
      this._element.classList.remove(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
294

XhmikosR's avatar
XhmikosR committed
295
      this._element.classList.add(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
296

XhmikosR's avatar
Dist    
XhmikosR committed
297
298
299
      this._element.style[dimension] = 0;

      if (this._triggerArray.length) {
XhmikosR's avatar
XhmikosR committed
300
        this._triggerArray.forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
301
          element.classList.remove(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
302
303
          element.setAttribute('aria-expanded', true);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
304
      }
fat's avatar
fat committed
305

XhmikosR's avatar
Dist    
XhmikosR committed
306
      this.setTransitioning(true);
fat's avatar
fat committed
307

XhmikosR's avatar
Dist    
XhmikosR committed
308
      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
309
        _this._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
310

XhmikosR's avatar
XhmikosR committed
311
        _this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
XhmikosR's avatar
XhmikosR committed
312

XhmikosR's avatar
Dist    
XhmikosR committed
313
        _this._element.style[dimension] = '';
fat's avatar
fat committed
314

XhmikosR's avatar
Dist    
XhmikosR committed
315
        _this.setTransitioning(false);
fat's avatar
fat committed
316

XhmikosR's avatar
XhmikosR committed
317
        EventHandler__default['default'].trigger(_this._element, EVENT_SHOWN);
Mark Otto's avatar
dist    
Mark Otto committed
318
      };
fat's avatar
fat committed
319

XhmikosR's avatar
Dist    
XhmikosR committed
320
321
      var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
      var scrollSize = "scroll" + capitalizedDimension;
XhmikosR's avatar
XhmikosR committed
322
      var transitionDuration = getTransitionDurationFromElement(this._element);
XhmikosR's avatar
XhmikosR committed
323
      EventHandler__default['default'].one(this._element, TRANSITION_END, complete);
XhmikosR's avatar
XhmikosR committed
324
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
325
326
      this._element.style[dimension] = this._element[scrollSize] + "px";
    };
fat's avatar
fat committed
327

XhmikosR's avatar
Dist    
XhmikosR committed
328
329
    _proto.hide = function hide() {
      var _this2 = this;
fat's avatar
fat committed
330

XhmikosR's avatar
XhmikosR committed
331
      if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
332
333
        return;
      }
fat's avatar
fat committed
334

XhmikosR's avatar
XhmikosR committed
335
      var startEvent = EventHandler__default['default'].trigger(this._element, EVENT_HIDE);
fat's avatar
fat committed
336

XhmikosR's avatar
XhmikosR committed
337
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
338
339
340
341
        return;
      }

      var dimension = this._getDimension();
fat's avatar
fat committed
342

XhmikosR's avatar
Dist    
XhmikosR committed
343
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
344
345
      reflow(this._element);

XhmikosR's avatar
XhmikosR committed
346
      this._element.classList.add(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
347

XhmikosR's avatar
XhmikosR committed
348
      this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
XhmikosR's avatar
XhmikosR committed
349

XhmikosR's avatar
Dist    
XhmikosR committed
350
      var triggerArrayLength = this._triggerArray.length;
fat's avatar
fat committed
351

XhmikosR's avatar
Dist    
XhmikosR committed
352
353
354
      if (triggerArrayLength > 0) {
        for (var i = 0; i < triggerArrayLength; i++) {
          var trigger = this._triggerArray[i];
XhmikosR's avatar
XhmikosR committed
355
          var elem = getElementFromSelector(trigger);
fat's avatar
fat committed
356

XhmikosR's avatar
XhmikosR committed
357
358
          if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) {
            trigger.classList.add(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
359
            trigger.setAttribute('aria-expanded', false);
Mark Otto's avatar
dist    
Mark Otto committed
360
361
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
362
      }
fat's avatar
fat committed
363

XhmikosR's avatar
Dist    
XhmikosR committed
364
      this.setTransitioning(true);
fat's avatar
fat committed
365

XhmikosR's avatar
Dist    
XhmikosR committed
366
367
      var complete = function complete() {
        _this2.setTransitioning(false);
fat's avatar
fat committed
368

XhmikosR's avatar
XhmikosR committed
369
        _this2._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
370

XhmikosR's avatar
XhmikosR committed
371
        _this2._element.classList.add(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
372

XhmikosR's avatar
XhmikosR committed
373
        EventHandler__default['default'].trigger(_this2._element, EVENT_HIDDEN);
Mark Otto's avatar
dist    
Mark Otto committed
374
      };
Mark Otto's avatar
grunt    
Mark Otto committed
375

XhmikosR's avatar
Dist    
XhmikosR committed
376
      this._element.style[dimension] = '';
XhmikosR's avatar
XhmikosR committed
377
      var transitionDuration = getTransitionDurationFromElement(this._element);
XhmikosR's avatar
XhmikosR committed
378
      EventHandler__default['default'].one(this._element, TRANSITION_END, complete);
XhmikosR's avatar
XhmikosR committed
379
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
380
    };
Mark Otto's avatar
grunt    
Mark Otto committed
381

XhmikosR's avatar
Dist    
XhmikosR committed
382
383
384
    _proto.setTransitioning = function setTransitioning(isTransitioning) {
      this._isTransitioning = isTransitioning;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
385

XhmikosR's avatar
Dist    
XhmikosR committed
386
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
387
      Data__default['default'].removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
388
389
390
391
392
      this._config = null;
      this._parent = null;
      this._element = null;
      this._triggerArray = null;
      this._isTransitioning = null;
Mark Otto's avatar
Mark Otto committed
393
394
    } // Private
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
395

XhmikosR's avatar
Dist    
XhmikosR committed
396
    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
397
      config = _extends({}, Default, config);
XhmikosR's avatar
Dist    
XhmikosR committed
398
      config.toggle = Boolean(config.toggle); // Coerce string values
Mark Otto's avatar
dist    
Mark Otto committed
399

XhmikosR's avatar
XhmikosR committed
400
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
401
402
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
403

XhmikosR's avatar
Dist    
XhmikosR committed
404
    _proto._getDimension = function _getDimension() {
XhmikosR's avatar
XhmikosR committed
405
      return this._element.classList.contains(WIDTH) ? WIDTH : HEIGHT;
XhmikosR's avatar
Dist    
XhmikosR committed
406
    };
Mark Otto's avatar
dist    
Mark Otto committed
407

XhmikosR's avatar
Dist    
XhmikosR committed
408
409
    _proto._getParent = function _getParent() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
410

XhmikosR's avatar
Dist.    
XhmikosR committed
411
      var parent = this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
412

XhmikosR's avatar
Dist.    
XhmikosR committed
413
414
415
416
      if (isElement(parent)) {
        // it's a jQuery object
        if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') {
          parent = parent[0];
fat's avatar
fat committed
417
        }
XhmikosR's avatar
Dist    
XhmikosR committed
418
      } else {
XhmikosR's avatar
XhmikosR committed
419
        parent = SelectorEngine__default['default'].findOne(parent);
XhmikosR's avatar
Dist    
XhmikosR committed
420
      }
fat's avatar
fat committed
421

XhmikosR's avatar
XhmikosR committed
422
      var selector = SELECTOR_DATA_TOGGLE + "[data-bs-parent=\"" + parent + "\"]";
XhmikosR's avatar
XhmikosR committed
423
      SelectorEngine__default['default'].find(selector, parent).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
424
        var selected = getElementFromSelector(element);
425
426

        _this3._addAriaAndCollapsedClass(selected, [element]);
XhmikosR's avatar
Dist    
XhmikosR committed
427
428
429
      });
      return parent;
    };
fat's avatar
fat committed
430

XhmikosR's avatar
Dist    
XhmikosR committed
431
    _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) {
XhmikosR's avatar
XhmikosR committed
432
433
      if (!element || !triggerArray.length) {
        return;
XhmikosR's avatar
Dist    
XhmikosR committed
434
      }
XhmikosR's avatar
XhmikosR committed
435
436
437
438
439
440
441
442
443
444
445

      var isOpen = element.classList.contains(CLASS_NAME_SHOW);
      triggerArray.forEach(function (elem) {
        if (isOpen) {
          elem.classList.remove(CLASS_NAME_COLLAPSED);
        } else {
          elem.classList.add(CLASS_NAME_COLLAPSED);
        }

        elem.setAttribute('aria-expanded', isOpen);
      });
Mark Otto's avatar
Mark Otto committed
446
447
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
448

XhmikosR's avatar
XhmikosR committed
449
    Collapse.collapseInterface = function collapseInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
450
      var data = Data__default['default'].getData(element, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
451

XhmikosR's avatar
XhmikosR committed
452
      var _config = _extends({}, Default, Manipulator__default['default'].getDataAttributes(element), typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist    
Mark Otto committed
453

XhmikosR's avatar
XhmikosR committed
454
      if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
XhmikosR's avatar
XhmikosR committed
455
456
457
458
459
460
        _config.toggle = false;
      }

      if (!data) {
        data = new Collapse(element, _config);
      }
Mark Otto's avatar
dist    
Mark Otto committed
461

XhmikosR's avatar
XhmikosR committed
462
463
      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
464
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
465
        }
Mark Otto's avatar
dist    
Mark Otto committed
466

XhmikosR's avatar
XhmikosR committed
467
468
469
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
470

XhmikosR's avatar
XhmikosR committed
471
    Collapse.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
472
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
473
        Collapse.collapseInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
474
475
      });
    };
fat's avatar
fat committed
476

XhmikosR's avatar
XhmikosR committed
477
    Collapse.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
478
      return Data__default['default'].getData(element, DATA_KEY);
XhmikosR's avatar
XhmikosR committed
479
480
    };

XhmikosR's avatar
Dist    
XhmikosR committed
481
482
483
484
485
486
487
488
489
490
491
    _createClass(Collapse, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);
fat's avatar
fat committed
492

XhmikosR's avatar
Dist    
XhmikosR committed
493
494
495
496
497
498
499
    return Collapse;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
Mark Otto's avatar
dist    
Mark Otto committed
500

fat's avatar
fat committed
501

XhmikosR's avatar
XhmikosR committed
502
  EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
503
    // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
XhmikosR's avatar
XhmikosR committed
504
    if (event.target.tagName === 'A') {
XhmikosR's avatar
Dist    
XhmikosR committed
505
506
      event.preventDefault();
    }
Mark Otto's avatar
dist    
Mark Otto committed
507

XhmikosR's avatar
XhmikosR committed
508
    var triggerData = Manipulator__default['default'].getDataAttributes(this);
XhmikosR's avatar
XhmikosR committed
509
    var selector = getSelectorFromElement(this);
XhmikosR's avatar
XhmikosR committed
510
    var selectorElements = SelectorEngine__default['default'].find(selector);
XhmikosR's avatar
XhmikosR committed
511
    selectorElements.forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
512
      var data = Data__default['default'].getData(element, DATA_KEY);
XhmikosR's avatar
XhmikosR committed
513
514
515
516
517
518
519
520
521
522
523
524
525
      var config;

      if (data) {
        // update parent attribute
        if (data._parent === null && typeof triggerData.parent === 'string') {
          data._config.parent = triggerData.parent;
          data._parent = data._getParent();
        }

        config = 'toggle';
      } else {
        config = triggerData;
      }
Mark Otto's avatar
dist    
Mark Otto committed
526

XhmikosR's avatar
XhmikosR committed
527
      Collapse.collapseInterface(element, config);
XhmikosR's avatar
Dist    
XhmikosR committed
528
529
530
531
532
533
    });
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
534
   * add .Collapse to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
535
   */
fat's avatar
fat committed
536

XhmikosR's avatar
XhmikosR committed
537
538
539
  onDOMContentLoaded(function () {
    var $ = getjQuery();
    /* istanbul ignore if */
540

XhmikosR's avatar
XhmikosR committed
541
542
543
544
    if ($) {
      var JQUERY_NO_CONFLICT = $.fn[NAME];
      $.fn[NAME] = Collapse.jQueryInterface;
      $.fn[NAME].Constructor = Collapse;
Mark Otto's avatar
dist    
Mark Otto committed
545

XhmikosR's avatar
XhmikosR committed
546
547
548
549
550
551
      $.fn[NAME].noConflict = function () {
        $.fn[NAME] = JQUERY_NO_CONFLICT;
        return Collapse.jQueryInterface;
      };
    }
  });
fat's avatar
fat committed
552
553

  return Collapse;
Mark Otto's avatar
dist    
Mark Otto committed
554

XhmikosR's avatar
XhmikosR committed
555
})));
Mark Otto's avatar
dist    
Mark Otto committed
556
//# sourceMappingURL=collapse.js.map