collapse.js 18.9 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap collapse.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
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 && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('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
67
68
69
70
71
72
73
74
75
      if (i % 2) {
        ownKeys(source, true).forEach(function (key) {
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
        ownKeys(source).forEach(function (key) {
          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
85
86
87
88
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
89
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
90
91
92
93
94

  var toType = function toType(obj) {
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

XhmikosR's avatar
XhmikosR committed
95
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
96
97
98
99
    var selector = element.getAttribute('data-target');

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

XhmikosR's avatar
XhmikosR committed
103
104
105
106
107
108
109
    return selector;
  };

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

    if (selector) {
XhmikosR's avatar
XhmikosR committed
110
111
      return document.querySelector(selector) ? selector : null;
    }
XhmikosR's avatar
XhmikosR committed
112
113
114
115
116
117
118

    return null;
  };

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

  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
145
146
147
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent(TRANSITION_END, true, true);
    element.dispatchEvent(evt);
XhmikosR's avatar
XhmikosR committed
148
149
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
190
191
192
193
194
195
  };

  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 makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

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

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

XhmikosR's avatar
XhmikosR committed
196
197
198
199
200
201
202
203
204
205
206
  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
207
208
209
210
211
212
213
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'collapse';
XhmikosR's avatar
XhmikosR committed
214
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
215
216
217
218
219
220
221
222
223
224
225
  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
226
  var Event = {
XhmikosR's avatar
Dist    
XhmikosR committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    SHOW: "show" + EVENT_KEY,
    SHOWN: "shown" + EVENT_KEY,
    HIDE: "hide" + EVENT_KEY,
    HIDDEN: "hidden" + EVENT_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
    SHOW: 'show',
    COLLAPSE: 'collapse',
    COLLAPSING: 'collapsing',
    COLLAPSED: 'collapsed'
  };
  var Dimension = {
    WIDTH: 'width',
    HEIGHT: 'height'
  };
  var Selector = {
    ACTIVES: '.show, .collapsing',
    DATA_TOGGLE: '[data-toggle="collapse"]'
  };
XhmikosR's avatar
XhmikosR committed
247
248
249
250
251
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
252
253
254
255
256
257
258
259

  var Collapse =
  /*#__PURE__*/
  function () {
    function Collapse(element, config) {
      this._isTransitioning = false;
      this._element = element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
260
261
      this._triggerArray = makeArray(SelectorEngine.find("[data-toggle=\"collapse\"][href=\"#" + element.id + "\"]," + ("[data-toggle=\"collapse\"][data-target=\"#" + element.id + "\"]")));
      var toggleList = makeArray(SelectorEngine.find(Selector.DATA_TOGGLE));
XhmikosR's avatar
Dist    
XhmikosR committed
262
263
264

      for (var i = 0, len = toggleList.length; i < len; i++) {
        var elem = toggleList[i];
XhmikosR's avatar
XhmikosR committed
265
266
        var selector = getSelectorFromElement(elem);
        var filterElement = makeArray(SelectorEngine.find(selector)).filter(function (foundElem) {
XhmikosR's avatar
Dist    
XhmikosR committed
267
268
          return foundElem === element;
        });
Johann-S's avatar
build    
Johann-S committed
269

XhmikosR's avatar
XhmikosR committed
270
        if (selector !== null && filterElement.length) {
XhmikosR's avatar
Dist    
XhmikosR committed
271
          this._selector = selector;
fat's avatar
fat committed
272

XhmikosR's avatar
Dist    
XhmikosR committed
273
          this._triggerArray.push(elem);
Mark Otto's avatar
dist    
Mark Otto committed
274
        }
XhmikosR's avatar
Dist    
XhmikosR committed
275
      }
fat's avatar
fat committed
276

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

XhmikosR's avatar
Dist    
XhmikosR committed
279
280
281
      if (!this._config.parent) {
        this._addAriaAndCollapsedClass(this._element, this._triggerArray);
      }
Jacob Thornton's avatar
Jacob Thornton committed
282

XhmikosR's avatar
Dist    
XhmikosR committed
283
284
285
      if (this._config.toggle) {
        this.toggle();
      }
XhmikosR's avatar
XhmikosR committed
286
287

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
288
    } // Getters
fat's avatar
fat committed
289
290


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

XhmikosR's avatar
Dist    
XhmikosR committed
293
294
    // Public
    _proto.toggle = function toggle() {
XhmikosR's avatar
XhmikosR committed
295
      if (this._element.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
296
297
298
299
300
        this.hide();
      } else {
        this.show();
      }
    };
fat's avatar
fat committed
301

XhmikosR's avatar
Dist    
XhmikosR committed
302
303
    _proto.show = function show() {
      var _this = this;
fat's avatar
fat committed
304

XhmikosR's avatar
XhmikosR committed
305
      if (this._isTransitioning || this._element.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
306
307
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
308

XhmikosR's avatar
Dist    
XhmikosR committed
309
310
      var actives;
      var activesData;
fat's avatar
fat committed
311

XhmikosR's avatar
Dist    
XhmikosR committed
312
      if (this._parent) {
XhmikosR's avatar
XhmikosR committed
313
        actives = makeArray(SelectorEngine.find(Selector.ACTIVES, this._parent)).filter(function (elem) {
XhmikosR's avatar
Dist    
XhmikosR committed
314
315
          if (typeof _this._config.parent === 'string') {
            return elem.getAttribute('data-parent') === _this._config.parent;
Mark Otto's avatar
dist    
Mark Otto committed
316
          }
fat's avatar
fat committed
317

XhmikosR's avatar
Dist    
XhmikosR committed
318
319
          return elem.classList.contains(ClassName.COLLAPSE);
        });
fat's avatar
fat committed
320

XhmikosR's avatar
Dist    
XhmikosR committed
321
322
        if (actives.length === 0) {
          actives = null;
Mark Otto's avatar
dist    
Mark Otto committed
323
        }
XhmikosR's avatar
Dist    
XhmikosR committed
324
      }
fat's avatar
fat committed
325

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

XhmikosR's avatar
Dist    
XhmikosR committed
328
      if (actives) {
XhmikosR's avatar
XhmikosR committed
329
330
331
332
        var tempActiveData = actives.filter(function (elem) {
          return container !== elem;
        });
        activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY) : null;
fat's avatar
fat committed
333

XhmikosR's avatar
Dist    
XhmikosR committed
334
        if (activesData && activesData._isTransitioning) {
Mark Otto's avatar
dist    
Mark Otto committed
335
336
          return;
        }
XhmikosR's avatar
Dist    
XhmikosR committed
337
      }
fat's avatar
fat committed
338

XhmikosR's avatar
XhmikosR committed
339
      var startEvent = EventHandler.trigger(this._element, Event.SHOW);
fat's avatar
fat committed
340

XhmikosR's avatar
XhmikosR committed
341
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
342
343
        return;
      }
fat's avatar
fat committed
344

XhmikosR's avatar
Dist    
XhmikosR committed
345
      if (actives) {
XhmikosR's avatar
XhmikosR committed
346
347
        actives.forEach(function (elemActive) {
          if (container !== elemActive) {
XhmikosR's avatar
XhmikosR committed
348
            Collapse.collapseInterface(elemActive, 'hide');
XhmikosR's avatar
XhmikosR committed
349
          }
fat's avatar
fat committed
350

XhmikosR's avatar
XhmikosR committed
351
352
353
354
          if (!activesData) {
            Data.setData(elemActive, DATA_KEY, null);
          }
        });
XhmikosR's avatar
Dist    
XhmikosR committed
355
      }
fat's avatar
fat committed
356

XhmikosR's avatar
Dist    
XhmikosR committed
357
358
      var dimension = this._getDimension();

XhmikosR's avatar
XhmikosR committed
359
360
361
362
      this._element.classList.remove(ClassName.COLLAPSE);

      this._element.classList.add(ClassName.COLLAPSING);

XhmikosR's avatar
Dist    
XhmikosR committed
363
364
365
      this._element.style[dimension] = 0;

      if (this._triggerArray.length) {
XhmikosR's avatar
XhmikosR committed
366
367
368
369
        this._triggerArray.forEach(function (element) {
          element.classList.remove(ClassName.COLLAPSED);
          element.setAttribute('aria-expanded', true);
        });
XhmikosR's avatar
Dist    
XhmikosR committed
370
      }
fat's avatar
fat committed
371

XhmikosR's avatar
Dist    
XhmikosR committed
372
      this.setTransitioning(true);
fat's avatar
fat committed
373

XhmikosR's avatar
Dist    
XhmikosR committed
374
      var complete = function complete() {
XhmikosR's avatar
XhmikosR committed
375
376
377
378
379
380
        _this._element.classList.remove(ClassName.COLLAPSING);

        _this._element.classList.add(ClassName.COLLAPSE);

        _this._element.classList.add(ClassName.SHOW);

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

XhmikosR's avatar
Dist    
XhmikosR committed
383
        _this.setTransitioning(false);
fat's avatar
fat committed
384

XhmikosR's avatar
XhmikosR committed
385
        EventHandler.trigger(_this._element, Event.SHOWN);
Mark Otto's avatar
dist    
Mark Otto committed
386
      };
fat's avatar
fat committed
387

XhmikosR's avatar
Dist    
XhmikosR committed
388
389
      var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
      var scrollSize = "scroll" + capitalizedDimension;
XhmikosR's avatar
XhmikosR committed
390
391
392
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
393
394
      this._element.style[dimension] = this._element[scrollSize] + "px";
    };
fat's avatar
fat committed
395

XhmikosR's avatar
Dist    
XhmikosR committed
396
397
    _proto.hide = function hide() {
      var _this2 = this;
fat's avatar
fat committed
398

XhmikosR's avatar
XhmikosR committed
399
      if (this._isTransitioning || !this._element.classList.contains(ClassName.SHOW)) {
XhmikosR's avatar
Dist    
XhmikosR committed
400
401
        return;
      }
fat's avatar
fat committed
402

XhmikosR's avatar
XhmikosR committed
403
      var startEvent = EventHandler.trigger(this._element, Event.HIDE);
fat's avatar
fat committed
404

XhmikosR's avatar
XhmikosR committed
405
      if (startEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
406
407
408
409
        return;
      }

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

XhmikosR's avatar
Dist    
XhmikosR committed
411
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
412
413
414
415
416
417
418
419
      reflow(this._element);

      this._element.classList.add(ClassName.COLLAPSING);

      this._element.classList.remove(ClassName.COLLAPSE);

      this._element.classList.remove(ClassName.SHOW);

XhmikosR's avatar
Dist    
XhmikosR committed
420
      var triggerArrayLength = this._triggerArray.length;
fat's avatar
fat committed
421

XhmikosR's avatar
Dist    
XhmikosR committed
422
423
424
      if (triggerArrayLength > 0) {
        for (var i = 0; i < triggerArrayLength; i++) {
          var trigger = this._triggerArray[i];
XhmikosR's avatar
XhmikosR committed
425
          var elem = getElementFromSelector(trigger);
fat's avatar
fat committed
426

XhmikosR's avatar
XhmikosR committed
427
428
429
          if (elem && !elem.classList.contains(ClassName.SHOW)) {
            trigger.classList.add(ClassName.COLLAPSED);
            trigger.setAttribute('aria-expanded', false);
Mark Otto's avatar
dist    
Mark Otto committed
430
431
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
432
      }
fat's avatar
fat committed
433

XhmikosR's avatar
Dist    
XhmikosR committed
434
      this.setTransitioning(true);
fat's avatar
fat committed
435

XhmikosR's avatar
Dist    
XhmikosR committed
436
437
      var complete = function complete() {
        _this2.setTransitioning(false);
fat's avatar
fat committed
438

XhmikosR's avatar
XhmikosR committed
439
440
441
442
        _this2._element.classList.remove(ClassName.COLLAPSING);

        _this2._element.classList.add(ClassName.COLLAPSE);

XhmikosR's avatar
XhmikosR committed
443
        EventHandler.trigger(_this2._element, Event.HIDDEN);
Mark Otto's avatar
dist    
Mark Otto committed
444
      };
Mark Otto's avatar
grunt    
Mark Otto committed
445

XhmikosR's avatar
Dist    
XhmikosR committed
446
      this._element.style[dimension] = '';
XhmikosR's avatar
XhmikosR committed
447
448
449
      var transitionDuration = getTransitionDurationFromElement(this._element);
      EventHandler.one(this._element, TRANSITION_END, complete);
      emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
450
    };
Mark Otto's avatar
grunt    
Mark Otto committed
451

XhmikosR's avatar
Dist    
XhmikosR committed
452
453
454
    _proto.setTransitioning = function setTransitioning(isTransitioning) {
      this._isTransitioning = isTransitioning;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
455

XhmikosR's avatar
Dist    
XhmikosR committed
456
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
457
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
458
459
460
461
462
      this._config = null;
      this._parent = null;
      this._element = null;
      this._triggerArray = null;
      this._isTransitioning = null;
Mark Otto's avatar
Mark Otto committed
463
464
    } // Private
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
465

XhmikosR's avatar
Dist    
XhmikosR committed
466
    _proto._getConfig = function _getConfig(config) {
467
      config = _objectSpread2({}, Default, {}, config);
XhmikosR's avatar
Dist    
XhmikosR committed
468
      config.toggle = Boolean(config.toggle); // Coerce string values
Mark Otto's avatar
dist    
Mark Otto committed
469

XhmikosR's avatar
XhmikosR committed
470
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
471
472
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
473

XhmikosR's avatar
Dist    
XhmikosR committed
474
    _proto._getDimension = function _getDimension() {
XhmikosR's avatar
XhmikosR committed
475
476
      var hasWidth = this._element.classList.contains(Dimension.WIDTH);

XhmikosR's avatar
Dist    
XhmikosR committed
477
478
      return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT;
    };
Mark Otto's avatar
dist    
Mark Otto committed
479

XhmikosR's avatar
Dist    
XhmikosR committed
480
481
    _proto._getParent = function _getParent() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
482

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

XhmikosR's avatar
Dist.    
XhmikosR committed
485
486
487
488
      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
489
        }
XhmikosR's avatar
Dist    
XhmikosR committed
490
      } else {
XhmikosR's avatar
Dist.    
XhmikosR committed
491
        parent = SelectorEngine.findOne(parent);
XhmikosR's avatar
Dist    
XhmikosR committed
492
      }
fat's avatar
fat committed
493

XhmikosR's avatar
Dist.    
XhmikosR committed
494
      var selector = "[data-toggle=\"collapse\"][data-parent=\"" + parent + "\"]";
XhmikosR's avatar
XhmikosR committed
495
      makeArray(SelectorEngine.find(selector, parent)).forEach(function (element) {
XhmikosR's avatar
XhmikosR committed
496
        var selected = getElementFromSelector(element);
497
498

        _this3._addAriaAndCollapsedClass(selected, [element]);
XhmikosR's avatar
Dist    
XhmikosR committed
499
500
501
      });
      return parent;
    };
fat's avatar
fat committed
502

XhmikosR's avatar
Dist    
XhmikosR committed
503
    _proto._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) {
XhmikosR's avatar
XhmikosR committed
504
505
506
507
508
      if (element) {
        var isOpen = element.classList.contains(ClassName.SHOW);

        if (triggerArray.length) {
          triggerArray.forEach(function (elem) {
XhmikosR's avatar
Dist.    
XhmikosR committed
509
            if (isOpen) {
XhmikosR's avatar
XhmikosR committed
510
              elem.classList.remove(ClassName.COLLAPSED);
XhmikosR's avatar
Dist.    
XhmikosR committed
511
512
            } else {
              elem.classList.add(ClassName.COLLAPSED);
XhmikosR's avatar
XhmikosR committed
513
            }
Mark Otto's avatar
grunt    
Mark Otto committed
514

XhmikosR's avatar
XhmikosR committed
515
516
517
            elem.setAttribute('aria-expanded', isOpen);
          });
        }
XhmikosR's avatar
Dist    
XhmikosR committed
518
      }
Mark Otto's avatar
Mark Otto committed
519
520
    } // Static
    ;
Mark Otto's avatar
dist    
Mark Otto committed
521

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

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

XhmikosR's avatar
XhmikosR committed
527
528
529
530
531
532
533
      if (!data && _config.toggle && /show|hide/.test(config)) {
        _config.toggle = false;
      }

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

XhmikosR's avatar
XhmikosR committed
535
536
      if (typeof config === 'string') {
        if (typeof data[config] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
537
          throw new TypeError("No method named \"" + config + "\"");
XhmikosR's avatar
Dist    
XhmikosR committed
538
        }
Mark Otto's avatar
dist    
Mark Otto committed
539

XhmikosR's avatar
XhmikosR committed
540
541
542
        data[config]();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
543

XhmikosR's avatar
XhmikosR committed
544
    Collapse.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
545
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
546
        Collapse.collapseInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
547
548
      });
    };
fat's avatar
fat committed
549

XhmikosR's avatar
XhmikosR committed
550
    Collapse.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
551
552
553
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
554
555
556
557
558
559
560
561
562
563
564
    _createClass(Collapse, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);
fat's avatar
fat committed
565

XhmikosR's avatar
Dist    
XhmikosR committed
566
567
568
569
570
571
572
    return Collapse;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
Mark Otto's avatar
dist    
Mark Otto committed
573

fat's avatar
fat committed
574

XhmikosR's avatar
XhmikosR committed
575
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
576
    // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
XhmikosR's avatar
XhmikosR committed
577
    if (event.target.tagName === 'A') {
XhmikosR's avatar
Dist    
XhmikosR committed
578
579
      event.preventDefault();
    }
Mark Otto's avatar
dist    
Mark Otto committed
580

XhmikosR's avatar
XhmikosR committed
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
    var triggerData = Manipulator.getDataAttributes(this);
    var selector = getSelectorFromElement(this);
    var selectorElements = makeArray(SelectorEngine.find(selector));
    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
599

XhmikosR's avatar
XhmikosR committed
600
      Collapse.collapseInterface(element, config);
XhmikosR's avatar
Dist    
XhmikosR committed
601
602
    });
  });
XhmikosR's avatar
XhmikosR committed
603
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
604
605
606
607
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
608
   * add .collapse to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
609
   */
fat's avatar
fat committed
610

611
612
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
613
614
615
616
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Collapse.jQueryInterface;
    $.fn[NAME].Constructor = Collapse;
Mark Otto's avatar
dist    
Mark Otto committed
617

XhmikosR's avatar
XhmikosR committed
618
619
620
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Collapse.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
621
622
    };
  }
fat's avatar
fat committed
623
624

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

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