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) {
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
10
  (global = global || self, global.Collapse = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
}(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
    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"]'
Mark Otto's avatar
dist    
Mark Otto committed
246
247
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
248
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
249
250
     * ------------------------------------------------------------------------
     */
Mark Otto's avatar
dist    
Mark Otto committed
251

XhmikosR's avatar
Dist    
XhmikosR committed
252
253
254
255
256
257
258
259
260
  };

  var Collapse =
  /*#__PURE__*/
  function () {
    function Collapse(element, config) {
      this._isTransitioning = false;
      this._element = element;
      this._config = this._getConfig(config);
XhmikosR's avatar
XhmikosR committed
261
262
      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
263
264
265

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
412
      this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + "px";
XhmikosR's avatar
XhmikosR committed
413
414
415
416
417
418
419
420
      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
421
      var triggerArrayLength = this._triggerArray.length;
fat's avatar
fat committed
422

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

XhmikosR's avatar
XhmikosR committed
428
429
430
          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
431
432
          }
        }
XhmikosR's avatar
Dist    
XhmikosR committed
433
      }
fat's avatar
fat committed
434

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

XhmikosR's avatar
XhmikosR committed
528
529
530
531
532
533
534
      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
535

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

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

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

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

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

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

fat's avatar
fat committed
575

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

XhmikosR's avatar
XhmikosR committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
    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
600

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

612
613
  /* istanbul ignore if */

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

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

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

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