collapse.js 18.5 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
2
  * Bootstrap collapse.js v5.0.0-alpha1 (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 = 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
  Data = Data && Object.prototype.hasOwnProperty.call(Data, 'default') ? Data['default'] : Data;
  EventHandler = EventHandler && Object.prototype.hasOwnProperty.call(EventHandler, 'default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Object.prototype.hasOwnProperty.call(Manipulator, 'default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && Object.prototype.hasOwnProperty.call(SelectorEngine, 'default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
16

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

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

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

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

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

XhmikosR's avatar
XhmikosR committed
42
43
44
45
46
47
48
    return selector;
  };

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

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

    return null;
  };

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

  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
84
    element.dispatchEvent(new Event(TRANSITION_END));
XhmikosR's avatar
XhmikosR committed
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
116
117
118
119
120
121
122
123
124
  };

  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
125
126
127
128
129
130
131
132
133
134
135
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

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

    return null;
  };

Mark Otto's avatar
Mark Otto committed
136
137
138
139
140
141
142
143
144
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  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
145
146
147
148
149
150
151
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'collapse';
152
  var VERSION = '5.0.0-alpha1';
XhmikosR's avatar
Dist    
XhmikosR committed
153
154
155
156
157
158
159
160
161
162
163
  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
164
165
166
167
168
169
170
171
172
173
174
175
176
  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';
  var SELECTOR_DATA_TOGGLE = '[data-toggle="collapse"]';
XhmikosR's avatar
XhmikosR committed
177
178
179
180
181
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
182

XhmikosR's avatar
XhmikosR committed
183
  var Collapse = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
184
185
186
187
    function Collapse(element, config) {
      this._isTransitioning = false;
      this._element = element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
188
189
      this._triggerArray = SelectorEngine.find(SELECTOR_DATA_TOGGLE + "[href=\"#" + element.id + "\"]," + (SELECTOR_DATA_TOGGLE + "[data-target=\"#" + element.id + "\"]"));
      var toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE);
XhmikosR's avatar
Dist    
XhmikosR committed
190
191
192

      for (var i = 0, len = toggleList.length; i < len; i++) {
        var elem = toggleList[i];
XhmikosR's avatar
XhmikosR committed
193
        var selector = getSelectorFromElement(elem);
XhmikosR's avatar
XhmikosR committed
194
        var filterElement = SelectorEngine.find(selector).filter(function (foundElem) {
XhmikosR's avatar
Dist    
XhmikosR committed
195
196
          return foundElem === element;
        });
Johann-S's avatar
build    
Johann-S committed
197

XhmikosR's avatar
XhmikosR committed
198
        if (selector !== null && filterElement.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
199
          this._selector = selector;
fat's avatar
fat committed
200

XhmikosR's avatar
Dist    
XhmikosR committed
201
          this._triggerArray.push(elem);
Mark Otto's avatar
dist    
Mark Otto committed
202
        }
XhmikosR's avatar
Dist    
XhmikosR committed
203
      }
fat's avatar
fat committed
204

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

XhmikosR's avatar
Dist    
XhmikosR committed
207
208
209
      if (!this._config.parent) {
        this._addAriaAndCollapsedClass(this._element, this._triggerArray);
      }
Jacob Thornton's avatar
Jacob Thornton committed
210

XhmikosR's avatar
Dist    
XhmikosR committed
211
212
213
      if (this._config.toggle) {
        this.toggle();
      }
XhmikosR's avatar
XhmikosR committed
214
215

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
216
    } // Getters
fat's avatar
fat committed
217
218


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

XhmikosR's avatar
Dist    
XhmikosR committed
221
222
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
223
      if (this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
224
225
226
227
228
        this.hide();
      } else {
        this.show();
      }
    };
fat's avatar
fat committed
229

XhmikosR's avatar
Dist    
XhmikosR committed
230
231
    _proto.show = function show() {
      var _this = this;
fat's avatar
fat committed
232

XhmikosR's avatar
XhmikosR committed
233
      if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
234
235
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
236

XhmikosR's avatar
Dist    
XhmikosR committed
237
238
      var actives;
      var activesData;
fat's avatar
fat committed
239

XhmikosR's avatar
Dist    
XhmikosR committed
240
      if (this._parent) {
XhmikosR's avatar
XhmikosR committed
241
        actives = SelectorEngine.find(SELECTOR_ACTIVES, this._parent).filter(function (elem) {
XhmikosR's avatar
Dist    
XhmikosR committed
242
243
          if (typeof _this._config.parent === 'string') {
            return elem.getAttribute('data-parent') === _this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
244
          }
fat's avatar
fat committed
245

XhmikosR's avatar
XhmikosR committed
246
          return elem.classList.contains(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
Dist    
XhmikosR committed
247
        });
fat's avatar
fat committed
248

XhmikosR's avatar
Dist    
XhmikosR committed
249
250
        if (actives.length === 0) {
          actives = null;
Mark Otto's avatar
dist    
Mark Otto committed
251
        }
XhmikosR's avatar
Dist    
XhmikosR committed
252
      }
fat's avatar
fat committed
253

XhmikosR's avatar
XhmikosR committed
254
255
      var container = SelectorEngine.findOne(this._selector);

XhmikosR's avatar
Dist    
XhmikosR committed
256
      if (actives) {
XhmikosR's avatar
XhmikosR committed
257
258
259
260
        var tempActiveData = actives.filter(function (elem) {
          return container !== elem;
        });
        activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY) : null;
fat's avatar
fat committed
261

XhmikosR's avatar
Dist    
XhmikosR committed
262
        if (activesData && activesData._isTransitioning) {
Mark Otto's avatar
dist    
Mark Otto committed
263
264
          return;
        }
XhmikosR's avatar
Dist    
XhmikosR committed
265
      }
fat's avatar
fat committed
266

XhmikosR's avatar
XhmikosR committed
267
      var startEvent = EventHandler.trigger(this._element, EVENT_SHOW);
fat's avatar
fat committed
268

XhmikosR's avatar
XhmikosR committed
269
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
270
271
        return;
      }
fat's avatar
fat committed
272

XhmikosR's avatar
Dist    
XhmikosR committed
273
      if (actives) {
XhmikosR's avatar
XhmikosR committed
274
275
        actives.forEach(function (elemActive) {
          if (container !== elemActive) {
XhmikosR's avatar
XhmikosR committed
276
            Collapse.collapseInterface(elemActive, 'hide');
XhmikosR's avatar
XhmikosR committed
277
          }
fat's avatar
fat committed
278

XhmikosR's avatar
XhmikosR committed
279
280
281
282
          if (!activesData) {
            Data.setData(elemActive, DATA_KEY, null);
          }
        });
XhmikosR's avatar
Dist    
XhmikosR committed
283
      }
fat's avatar
fat committed
284

XhmikosR's avatar
Dist    
XhmikosR committed
285
286
      var dimension = this._getDimension();

XhmikosR's avatar
XhmikosR committed
287
      this._element.classList.remove(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
288

XhmikosR's avatar
XhmikosR committed
289
      this._element.classList.add(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
290

XhmikosR's avatar
Dist    
XhmikosR committed
291
292
293
      this._element.style[dimension] = 0;

      if (this._triggerArray.length) {
XhmikosR's avatar
XhmikosR committed
294
        this._triggerArray.forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
295
          element.classList.remove(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
296
297
          element.setAttribute('aria-expanded', true);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
298
      }
fat's avatar
fat committed
299

XhmikosR's avatar
Dist    
XhmikosR committed
300
      this.setTransitioning(true);
fat's avatar
fat committed
301

XhmikosR's avatar
Dist    
XhmikosR committed
302
      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
303
        _this._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
304

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
309
        _this.setTransitioning(false);
fat's avatar
fat committed
310

XhmikosR's avatar
XhmikosR committed
311
        EventHandler.trigger(_this._element, EVENT_SHOWN);
Mark Otto's avatar
dist    
Mark Otto committed
312
      };
fat's avatar
fat committed
313

XhmikosR's avatar
Dist    
XhmikosR committed
314
315
      var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
      var scrollSize = "scroll" + capitalizedDimension;
XhmikosR's avatar
XhmikosR committed
316
317
318
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
319
320
      this._element.style[dimension] = this._element[scrollSize] + "px";
    };
fat's avatar
fat committed
321

XhmikosR's avatar
Dist    
XhmikosR committed
322
323
    _proto.hide = function hide() {
      var _this2 = this;
fat's avatar
fat committed
324

XhmikosR's avatar
XhmikosR committed
325
      if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
326
327
        return;
      }
fat's avatar
fat committed
328

XhmikosR's avatar
XhmikosR committed
329
      var startEvent = EventHandler.trigger(this._element, EVENT_HIDE);
fat's avatar
fat committed
330

XhmikosR's avatar
XhmikosR committed
331
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
332
333
334
335
        return;
      }

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

XhmikosR's avatar
Dist    
XhmikosR committed
337
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
338
339
      reflow(this._element);

XhmikosR's avatar
XhmikosR committed
340
      this._element.classList.add(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
341

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

XhmikosR's avatar
Dist    
XhmikosR committed
344
      var triggerArrayLength = this._triggerArray.length;
fat's avatar
fat committed
345

XhmikosR's avatar
Dist    
XhmikosR committed
346
347
348
      if (triggerArrayLength > 0) {
        for (var i = 0; i < triggerArrayLength; i++) {
          var trigger = this._triggerArray[i];
XhmikosR's avatar
XhmikosR committed
349
          var elem = getElementFromSelector(trigger);
fat's avatar
fat committed
350

XhmikosR's avatar
XhmikosR committed
351
352
          if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) {
            trigger.classList.add(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
353
            trigger.setAttribute('aria-expanded', false);
Mark Otto's avatar
dist    
Mark Otto committed
354
355
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
356
      }
fat's avatar
fat committed
357

XhmikosR's avatar
Dist    
XhmikosR committed
358
      this.setTransitioning(true);
fat's avatar
fat committed
359

XhmikosR's avatar
Dist    
XhmikosR committed
360
361
      var complete = function complete() {
        _this2.setTransitioning(false);
fat's avatar
fat committed
362

XhmikosR's avatar
XhmikosR committed
363
        _this2._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
364

XhmikosR's avatar
XhmikosR committed
365
        _this2._element.classList.add(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
366

XhmikosR's avatar
XhmikosR committed
367
        EventHandler.trigger(_this2._element, EVENT_HIDDEN);
Mark Otto's avatar
dist    
Mark Otto committed
368
      };
Mark Otto's avatar
grunt    
Mark Otto committed
369

XhmikosR's avatar
Dist    
XhmikosR committed
370
      this._element.style[dimension] = '';
XhmikosR's avatar
XhmikosR committed
371
372
373
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
374
    };
Mark Otto's avatar
grunt    
Mark Otto committed
375

XhmikosR's avatar
Dist    
XhmikosR committed
376
377
378
    _proto.setTransitioning = function setTransitioning(isTransitioning) {
      this._isTransitioning = isTransitioning;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
379

XhmikosR's avatar
Dist    
XhmikosR committed
380
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
381
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
382
383
384
385
386
      this._config = null;
      this._parent = null;
      this._element = null;
      this._triggerArray = null;
      this._isTransitioning = null;
Mark Otto's avatar
Mark Otto committed
387
388
    } // Private
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
389

XhmikosR's avatar
Dist    
XhmikosR committed
390
    _proto._getConfig = function _getConfig(config) {
Mark Otto's avatar
Mark Otto committed
391
      config = _objectSpread(_objectSpread({}, Default), config);
XhmikosR's avatar
Dist    
XhmikosR committed
392
      config.toggle = Boolean(config.toggle); // Coerce string values
Mark Otto's avatar
dist    
Mark Otto committed
393

XhmikosR's avatar
XhmikosR committed
394
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
395
396
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
397

XhmikosR's avatar
Dist    
XhmikosR committed
398
    _proto._getDimension = function _getDimension() {
XhmikosR's avatar
XhmikosR committed
399
      var hasWidth = this._element.classList.contains(WIDTH);
XhmikosR's avatar
XhmikosR committed
400

XhmikosR's avatar
XhmikosR committed
401
      return hasWidth ? WIDTH : HEIGHT;
XhmikosR's avatar
Dist    
XhmikosR committed
402
    };
Mark Otto's avatar
dist    
Mark Otto committed
403

XhmikosR's avatar
Dist    
XhmikosR committed
404
405
    _proto._getParent = function _getParent() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
406

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

XhmikosR's avatar
Dist.    
XhmikosR committed
409
410
411
412
      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
413
        }
XhmikosR's avatar
Dist    
XhmikosR committed
414
      } else {
XhmikosR's avatar
Dist.    
XhmikosR committed
415
        parent = SelectorEngine.findOne(parent);
XhmikosR's avatar
Dist    
XhmikosR committed
416
      }
fat's avatar
fat committed
417

XhmikosR's avatar
XhmikosR committed
418
419
      var selector = SELECTOR_DATA_TOGGLE + "[data-parent=\"" + parent + "\"]";
      SelectorEngine.find(selector, parent).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
420
        var selected = getElementFromSelector(element);
421
422

        _this3._addAriaAndCollapsedClass(selected, [element]);
XhmikosR's avatar
Dist    
XhmikosR committed
423
424
425
      });
      return parent;
    };
fat's avatar
fat committed
426

XhmikosR's avatar
Dist    
XhmikosR committed
427
    _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) {
XhmikosR's avatar
XhmikosR committed
428
      if (element) {
XhmikosR's avatar
XhmikosR committed
429
        var isOpen = element.classList.contains(CLASS_NAME_SHOW);
XhmikosR's avatar
XhmikosR committed
430
431
432

        if (triggerArray.length) {
          triggerArray.forEach(function (elem) {
XhmikosR's avatar
Dist.    
XhmikosR committed
433
            if (isOpen) {
XhmikosR's avatar
XhmikosR committed
434
              elem.classList.remove(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
Dist.    
XhmikosR committed
435
            } else {
XhmikosR's avatar
XhmikosR committed
436
              elem.classList.add(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
437
            }
Mark Otto's avatar
grunt    
Mark Otto committed
438

XhmikosR's avatar
XhmikosR committed
439
440
441
            elem.setAttribute('aria-expanded', isOpen);
          });
        }
XhmikosR's avatar
Dist    
XhmikosR committed
442
      }
Mark Otto's avatar
Mark Otto committed
443
444
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
445

XhmikosR's avatar
XhmikosR committed
446
    Collapse.collapseInterface = function collapseInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
447
      var data = Data.getData(element, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
448

Mark Otto's avatar
Mark Otto committed
449
      var _config = _objectSpread(_objectSpread(_objectSpread({}, Default), Manipulator.getDataAttributes(element)), typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist    
Mark Otto committed
450

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

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

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

XhmikosR's avatar
XhmikosR committed
464
465
466
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
467

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

XhmikosR's avatar
XhmikosR committed
474
    Collapse.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
475
476
477
      return Data.getData(element, DATA_KEY);
    };

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

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

fat's avatar
fat committed
498

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

XhmikosR's avatar
XhmikosR committed
505
506
    var triggerData = Manipulator.getDataAttributes(this);
    var selector = getSelectorFromElement(this);
XhmikosR's avatar
XhmikosR committed
507
    var selectorElements = SelectorEngine.find(selector);
XhmikosR's avatar
XhmikosR committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
    selectorElements.forEach(function (element) {
      var data = Data.getData(element, DATA_KEY);
      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
523

XhmikosR's avatar
XhmikosR committed
524
      Collapse.collapseInterface(element, config);
XhmikosR's avatar
Dist    
XhmikosR committed
525
526
    });
  });
XhmikosR's avatar
XhmikosR committed
527
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
528
529
530
531
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
532
   * add .collapse to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
533
   */
fat's avatar
fat committed
534

535
536
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
537
538
539
540
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Collapse.jQueryInterface;
    $.fn[NAME].Constructor = Collapse;
Mark Otto's avatar
dist    
Mark Otto committed
541

XhmikosR's avatar
XhmikosR committed
542
543
544
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Collapse.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
545
546
    };
  }
fat's avatar
fat committed
547
548

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

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