collapse.js 18.8 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
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) {
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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

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

  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;
  }
Mark Otto's avatar
dist    
Mark Otto committed
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  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 _objectSpread2(target) {
Mark Otto's avatar
dist    
Mark Otto committed
63
64
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
Mark Otto's avatar
dist    
Mark Otto committed
65

66
      if (i % 2) {
XhmikosR's avatar
XhmikosR committed
67
        ownKeys(Object(source), true).forEach(function (key) {
68
69
70
71
72
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
XhmikosR's avatar
XhmikosR committed
73
        ownKeys(Object(source)).forEach(function (key) {
74
75
          Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
Mark Otto's avatar
dist    
Mark Otto committed
76
77
      }
    }
Mark Otto's avatar
dist    
Mark Otto committed
78

Mark Otto's avatar
dist    
Mark Otto committed
79
80
    return target;
  }
fat's avatar
fat committed
81

XhmikosR's avatar
XhmikosR committed
82
83
  /**
   * --------------------------------------------------------------------------
84
   * Bootstrap (v5.0.0-alpha1): util/index.js
XhmikosR's avatar
XhmikosR committed
85
86
87
88
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
89
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
90
91

  var toType = function toType(obj) {
XhmikosR's avatar
XhmikosR committed
92
93
94
95
    if (obj === null || obj === undefined) {
      return "" + obj;
    }

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

XhmikosR's avatar
XhmikosR committed
99
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
100
101
102
103
    var selector = element.getAttribute('data-target');

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

XhmikosR's avatar
XhmikosR committed
107
108
109
110
111
112
113
    return selector;
  };

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

    if (selector) {
XhmikosR's avatar
XhmikosR committed
114
115
      return document.querySelector(selector) ? selector : null;
    }
XhmikosR's avatar
XhmikosR committed
116
117
118
119
120
121
122

    return null;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  };

  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
149
    element.dispatchEvent(new Event(TRANSITION_END));
XhmikosR's avatar
XhmikosR committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  };

  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
190
191
192
193
194
195
196
197
198
199
200
  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
201
202
203
204
205
206
207
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'collapse';
208
  var VERSION = '5.0.0-alpha1';
XhmikosR's avatar
Dist    
XhmikosR committed
209
210
211
212
213
214
215
216
217
218
219
  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
220
221
222
223
224
225
226
227
228
229
230
231
232
  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
233
234
235
236
237
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
238

XhmikosR's avatar
XhmikosR committed
239
  var Collapse = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
240
241
242
243
    function Collapse(element, config) {
      this._isTransitioning = false;
      this._element = element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
244
245
      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
246
247
248

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

XhmikosR's avatar
XhmikosR committed
254
        if (selector !== null && filterElement.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
255
          this._selector = selector;
fat's avatar
fat committed
256

XhmikosR's avatar
Dist    
XhmikosR committed
257
          this._triggerArray.push(elem);
Mark Otto's avatar
dist    
Mark Otto committed
258
        }
XhmikosR's avatar
Dist    
XhmikosR committed
259
      }
fat's avatar
fat committed
260

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

XhmikosR's avatar
Dist    
XhmikosR committed
263
264
265
      if (!this._config.parent) {
        this._addAriaAndCollapsedClass(this._element, this._triggerArray);
      }
Jacob Thornton's avatar
Jacob Thornton committed
266

XhmikosR's avatar
Dist    
XhmikosR committed
267
268
269
      if (this._config.toggle) {
        this.toggle();
      }
XhmikosR's avatar
XhmikosR committed
270
271

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
272
    } // Getters
fat's avatar
fat committed
273
274


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

XhmikosR's avatar
Dist    
XhmikosR committed
277
278
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
279
      if (this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
280
281
282
283
284
        this.hide();
      } else {
        this.show();
      }
    };
fat's avatar
fat committed
285

XhmikosR's avatar
Dist    
XhmikosR committed
286
287
    _proto.show = function show() {
      var _this = this;
fat's avatar
fat committed
288

XhmikosR's avatar
XhmikosR committed
289
      if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
290
291
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
292

XhmikosR's avatar
Dist    
XhmikosR committed
293
294
      var actives;
      var activesData;
fat's avatar
fat committed
295

XhmikosR's avatar
Dist    
XhmikosR committed
296
      if (this._parent) {
XhmikosR's avatar
XhmikosR committed
297
        actives = SelectorEngine.find(SELECTOR_ACTIVES, this._parent).filter(function (elem) {
XhmikosR's avatar
Dist    
XhmikosR committed
298
299
          if (typeof _this._config.parent === 'string') {
            return elem.getAttribute('data-parent') === _this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
300
          }
fat's avatar
fat committed
301

XhmikosR's avatar
XhmikosR committed
302
          return elem.classList.contains(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
Dist    
XhmikosR committed
303
        });
fat's avatar
fat committed
304

XhmikosR's avatar
Dist    
XhmikosR committed
305
306
        if (actives.length === 0) {
          actives = null;
Mark Otto's avatar
dist    
Mark Otto committed
307
        }
XhmikosR's avatar
Dist    
XhmikosR committed
308
      }
fat's avatar
fat committed
309

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

XhmikosR's avatar
Dist    
XhmikosR committed
312
      if (actives) {
XhmikosR's avatar
XhmikosR committed
313
314
315
316
        var tempActiveData = actives.filter(function (elem) {
          return container !== elem;
        });
        activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY) : null;
fat's avatar
fat committed
317

XhmikosR's avatar
Dist    
XhmikosR committed
318
        if (activesData && activesData._isTransitioning) {
Mark Otto's avatar
dist    
Mark Otto committed
319
320
          return;
        }
XhmikosR's avatar
Dist    
XhmikosR committed
321
      }
fat's avatar
fat committed
322

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

XhmikosR's avatar
XhmikosR committed
325
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
326
327
        return;
      }
fat's avatar
fat committed
328

XhmikosR's avatar
Dist    
XhmikosR committed
329
      if (actives) {
XhmikosR's avatar
XhmikosR committed
330
331
        actives.forEach(function (elemActive) {
          if (container !== elemActive) {
XhmikosR's avatar
XhmikosR committed
332
            Collapse.collapseInterface(elemActive, 'hide');
XhmikosR's avatar
XhmikosR committed
333
          }
fat's avatar
fat committed
334

XhmikosR's avatar
XhmikosR committed
335
336
337
338
          if (!activesData) {
            Data.setData(elemActive, DATA_KEY, null);
          }
        });
XhmikosR's avatar
Dist    
XhmikosR committed
339
      }
fat's avatar
fat committed
340

XhmikosR's avatar
Dist    
XhmikosR committed
341
342
      var dimension = this._getDimension();

XhmikosR's avatar
XhmikosR committed
343
      this._element.classList.remove(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
344

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

XhmikosR's avatar
Dist    
XhmikosR committed
347
348
349
      this._element.style[dimension] = 0;

      if (this._triggerArray.length) {
XhmikosR's avatar
XhmikosR committed
350
        this._triggerArray.forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
351
          element.classList.remove(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
352
353
          element.setAttribute('aria-expanded', true);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
354
      }
fat's avatar
fat committed
355

XhmikosR's avatar
Dist    
XhmikosR committed
356
      this.setTransitioning(true);
fat's avatar
fat committed
357

XhmikosR's avatar
Dist    
XhmikosR committed
358
      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
359
        _this._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
360

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
365
        _this.setTransitioning(false);
fat's avatar
fat committed
366

XhmikosR's avatar
XhmikosR committed
367
        EventHandler.trigger(_this._element, EVENT_SHOWN);
Mark Otto's avatar
dist    
Mark Otto committed
368
      };
fat's avatar
fat committed
369

XhmikosR's avatar
Dist    
XhmikosR committed
370
371
      var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
      var scrollSize = "scroll" + capitalizedDimension;
XhmikosR's avatar
XhmikosR committed
372
373
374
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
375
376
      this._element.style[dimension] = this._element[scrollSize] + "px";
    };
fat's avatar
fat committed
377

XhmikosR's avatar
Dist    
XhmikosR committed
378
379
    _proto.hide = function hide() {
      var _this2 = this;
fat's avatar
fat committed
380

XhmikosR's avatar
XhmikosR committed
381
      if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
382
383
        return;
      }
fat's avatar
fat committed
384

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

XhmikosR's avatar
XhmikosR committed
387
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
388
389
390
391
        return;
      }

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

XhmikosR's avatar
Dist    
XhmikosR committed
393
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
394
395
      reflow(this._element);

XhmikosR's avatar
XhmikosR committed
396
      this._element.classList.add(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
397

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

XhmikosR's avatar
Dist    
XhmikosR committed
400
      var triggerArrayLength = this._triggerArray.length;
fat's avatar
fat committed
401

XhmikosR's avatar
Dist    
XhmikosR committed
402
403
404
      if (triggerArrayLength > 0) {
        for (var i = 0; i < triggerArrayLength; i++) {
          var trigger = this._triggerArray[i];
XhmikosR's avatar
XhmikosR committed
405
          var elem = getElementFromSelector(trigger);
fat's avatar
fat committed
406

XhmikosR's avatar
XhmikosR committed
407
408
          if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) {
            trigger.classList.add(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
409
            trigger.setAttribute('aria-expanded', false);
Mark Otto's avatar
dist    
Mark Otto committed
410
411
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
412
      }
fat's avatar
fat committed
413

XhmikosR's avatar
Dist    
XhmikosR committed
414
      this.setTransitioning(true);
fat's avatar
fat committed
415

XhmikosR's avatar
Dist    
XhmikosR committed
416
417
      var complete = function complete() {
        _this2.setTransitioning(false);
fat's avatar
fat committed
418

XhmikosR's avatar
XhmikosR committed
419
        _this2._element.classList.remove(CLASS_NAME_COLLAPSING);
XhmikosR's avatar
XhmikosR committed
420

XhmikosR's avatar
XhmikosR committed
421
        _this2._element.classList.add(CLASS_NAME_COLLAPSE);
XhmikosR's avatar
XhmikosR committed
422

XhmikosR's avatar
XhmikosR committed
423
        EventHandler.trigger(_this2._element, EVENT_HIDDEN);
Mark Otto's avatar
dist    
Mark Otto committed
424
      };
Mark Otto's avatar
grunt    
Mark Otto committed
425

XhmikosR's avatar
Dist    
XhmikosR committed
426
      this._element.style[dimension] = '';
XhmikosR's avatar
XhmikosR committed
427
428
429
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
430
    };
Mark Otto's avatar
grunt    
Mark Otto committed
431

XhmikosR's avatar
Dist    
XhmikosR committed
432
433
434
    _proto.setTransitioning = function setTransitioning(isTransitioning) {
      this._isTransitioning = isTransitioning;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
435

XhmikosR's avatar
Dist    
XhmikosR committed
436
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
437
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
438
439
440
441
442
      this._config = null;
      this._parent = null;
      this._element = null;
      this._triggerArray = null;
      this._isTransitioning = null;
Mark Otto's avatar
Mark Otto committed
443
444
    } // Private
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
445

XhmikosR's avatar
Dist    
XhmikosR committed
446
    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
447
      config = _objectSpread2(_objectSpread2({}, Default), config);
XhmikosR's avatar
Dist    
XhmikosR committed
448
      config.toggle = Boolean(config.toggle); // Coerce string values
Mark Otto's avatar
dist    
Mark Otto committed
449

XhmikosR's avatar
XhmikosR committed
450
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
451
452
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
453

XhmikosR's avatar
Dist    
XhmikosR committed
454
    _proto._getDimension = function _getDimension() {
XhmikosR's avatar
XhmikosR committed
455
      var hasWidth = this._element.classList.contains(WIDTH);
XhmikosR's avatar
XhmikosR committed
456

XhmikosR's avatar
XhmikosR committed
457
      return hasWidth ? WIDTH : HEIGHT;
XhmikosR's avatar
Dist    
XhmikosR committed
458
    };
Mark Otto's avatar
dist    
Mark Otto committed
459

XhmikosR's avatar
Dist    
XhmikosR committed
460
461
    _proto._getParent = function _getParent() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
462

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

XhmikosR's avatar
Dist.    
XhmikosR committed
465
466
467
468
      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
469
        }
XhmikosR's avatar
Dist    
XhmikosR committed
470
      } else {
XhmikosR's avatar
Dist.    
XhmikosR committed
471
        parent = SelectorEngine.findOne(parent);
XhmikosR's avatar
Dist    
XhmikosR committed
472
      }
fat's avatar
fat committed
473

XhmikosR's avatar
XhmikosR committed
474
475
      var selector = SELECTOR_DATA_TOGGLE + "[data-parent=\"" + parent + "\"]";
      SelectorEngine.find(selector, parent).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
476
        var selected = getElementFromSelector(element);
477
478

        _this3._addAriaAndCollapsedClass(selected, [element]);
XhmikosR's avatar
Dist    
XhmikosR committed
479
480
481
      });
      return parent;
    };
fat's avatar
fat committed
482

XhmikosR's avatar
Dist    
XhmikosR committed
483
    _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) {
XhmikosR's avatar
XhmikosR committed
484
      if (element) {
XhmikosR's avatar
XhmikosR committed
485
        var isOpen = element.classList.contains(CLASS_NAME_SHOW);
XhmikosR's avatar
XhmikosR committed
486
487
488

        if (triggerArray.length) {
          triggerArray.forEach(function (elem) {
XhmikosR's avatar
Dist.    
XhmikosR committed
489
            if (isOpen) {
XhmikosR's avatar
XhmikosR committed
490
              elem.classList.remove(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
Dist.    
XhmikosR committed
491
            } else {
XhmikosR's avatar
XhmikosR committed
492
              elem.classList.add(CLASS_NAME_COLLAPSED);
XhmikosR's avatar
XhmikosR committed
493
            }
Mark Otto's avatar
grunt    
Mark Otto committed
494

XhmikosR's avatar
XhmikosR committed
495
496
497
            elem.setAttribute('aria-expanded', isOpen);
          });
        }
XhmikosR's avatar
Dist    
XhmikosR committed
498
      }
Mark Otto's avatar
Mark Otto committed
499
500
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
501

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

XhmikosR's avatar
XhmikosR committed
505
      var _config = _objectSpread2(_objectSpread2(_objectSpread2({}, Default), Manipulator.getDataAttributes(element)), typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist    
Mark Otto committed
506

XhmikosR's avatar
XhmikosR committed
507
      if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
XhmikosR's avatar
XhmikosR committed
508
509
510
511
512
513
        _config.toggle = false;
      }

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

XhmikosR's avatar
XhmikosR committed
515
516
      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
517
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
518
        }
Mark Otto's avatar
dist    
Mark Otto committed
519

XhmikosR's avatar
XhmikosR committed
520
521
522
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
523

XhmikosR's avatar
XhmikosR committed
524
    Collapse.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
525
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
526
        Collapse.collapseInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
527
528
      });
    };
fat's avatar
fat committed
529

XhmikosR's avatar
XhmikosR committed
530
    Collapse.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
531
532
533
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
534
535
536
537
538
539
540
541
542
543
544
    _createClass(Collapse, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);
fat's avatar
fat committed
545

XhmikosR's avatar
Dist    
XhmikosR committed
546
547
548
549
550
551
552
    return Collapse;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
Mark Otto's avatar
dist    
Mark Otto committed
553

fat's avatar
fat committed
554

XhmikosR's avatar
XhmikosR committed
555
  EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
556
    // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
XhmikosR's avatar
XhmikosR committed
557
    if (event.target.tagName === 'A') {
XhmikosR's avatar
Dist    
XhmikosR committed
558
559
      event.preventDefault();
    }
Mark Otto's avatar
dist    
Mark Otto committed
560

XhmikosR's avatar
XhmikosR committed
561
562
    var triggerData = Manipulator.getDataAttributes(this);
    var selector = getSelectorFromElement(this);
XhmikosR's avatar
XhmikosR committed
563
    var selectorElements = SelectorEngine.find(selector);
XhmikosR's avatar
XhmikosR committed
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
    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
579

XhmikosR's avatar
XhmikosR committed
580
      Collapse.collapseInterface(element, config);
XhmikosR's avatar
Dist    
XhmikosR committed
581
582
    });
  });
XhmikosR's avatar
XhmikosR committed
583
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
584
585
586
587
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
588
   * add .collapse to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
589
   */
fat's avatar
fat committed
590

591
592
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
593
594
595
596
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Collapse.jQueryInterface;
    $.fn[NAME].Constructor = Collapse;
Mark Otto's avatar
dist    
Mark Otto committed
597

XhmikosR's avatar
XhmikosR committed
598
599
600
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Collapse.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
601
602
    };
  }
fat's avatar
fat committed
603
604

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

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