1 | /*!
|
---|
2 | * Bootstrap collapse.js v5.1.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
7 | 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'), require('./base-component.js')) :
|
---|
8 | typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
|
---|
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
|
---|
10 | })(this, (function (Data, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
|
---|
11 |
|
---|
12 | const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
---|
13 |
|
---|
14 | const Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
|
---|
15 | const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
---|
16 | const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
---|
17 | const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
---|
18 | const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * --------------------------------------------------------------------------
|
---|
22 | * Bootstrap (v5.1.3): util/index.js
|
---|
23 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
24 | * --------------------------------------------------------------------------
|
---|
25 | */
|
---|
26 |
|
---|
27 | const toType = obj => {
|
---|
28 | if (obj === null || obj === undefined) {
|
---|
29 | return `${obj}`;
|
---|
30 | }
|
---|
31 |
|
---|
32 | return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
|
---|
33 | };
|
---|
34 |
|
---|
35 | const getSelector = element => {
|
---|
36 | let selector = element.getAttribute('data-bs-target');
|
---|
37 |
|
---|
38 | if (!selector || selector === '#') {
|
---|
39 | let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
|
---|
40 | // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
|
---|
41 | // `document.querySelector` will rightfully complain it is invalid.
|
---|
42 | // See https://github.com/twbs/bootstrap/issues/32273
|
---|
43 |
|
---|
44 | if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
|
---|
45 | return null;
|
---|
46 | } // Just in case some CMS puts out a full URL with the anchor appended
|
---|
47 |
|
---|
48 |
|
---|
49 | if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
|
---|
50 | hrefAttr = `#${hrefAttr.split('#')[1]}`;
|
---|
51 | }
|
---|
52 |
|
---|
53 | selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | return selector;
|
---|
57 | };
|
---|
58 |
|
---|
59 | const getSelectorFromElement = element => {
|
---|
60 | const selector = getSelector(element);
|
---|
61 |
|
---|
62 | if (selector) {
|
---|
63 | return document.querySelector(selector) ? selector : null;
|
---|
64 | }
|
---|
65 |
|
---|
66 | return null;
|
---|
67 | };
|
---|
68 |
|
---|
69 | const getElementFromSelector = element => {
|
---|
70 | const selector = getSelector(element);
|
---|
71 | return selector ? document.querySelector(selector) : null;
|
---|
72 | };
|
---|
73 |
|
---|
74 | const isElement = obj => {
|
---|
75 | if (!obj || typeof obj !== 'object') {
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | if (typeof obj.jquery !== 'undefined') {
|
---|
80 | obj = obj[0];
|
---|
81 | }
|
---|
82 |
|
---|
83 | return typeof obj.nodeType !== 'undefined';
|
---|
84 | };
|
---|
85 |
|
---|
86 | const getElement = obj => {
|
---|
87 | if (isElement(obj)) {
|
---|
88 | // it's a jQuery object or a node element
|
---|
89 | return obj.jquery ? obj[0] : obj;
|
---|
90 | }
|
---|
91 |
|
---|
92 | if (typeof obj === 'string' && obj.length > 0) {
|
---|
93 | return document.querySelector(obj);
|
---|
94 | }
|
---|
95 |
|
---|
96 | return null;
|
---|
97 | };
|
---|
98 |
|
---|
99 | const typeCheckConfig = (componentName, config, configTypes) => {
|
---|
100 | Object.keys(configTypes).forEach(property => {
|
---|
101 | const expectedTypes = configTypes[property];
|
---|
102 | const value = config[property];
|
---|
103 | const valueType = value && isElement(value) ? 'element' : toType(value);
|
---|
104 |
|
---|
105 | if (!new RegExp(expectedTypes).test(valueType)) {
|
---|
106 | throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
|
---|
107 | }
|
---|
108 | });
|
---|
109 | };
|
---|
110 | /**
|
---|
111 | * Trick to restart an element's animation
|
---|
112 | *
|
---|
113 | * @param {HTMLElement} element
|
---|
114 | * @return void
|
---|
115 | *
|
---|
116 | * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
|
---|
117 | */
|
---|
118 |
|
---|
119 |
|
---|
120 | const reflow = element => {
|
---|
121 | // eslint-disable-next-line no-unused-expressions
|
---|
122 | element.offsetHeight;
|
---|
123 | };
|
---|
124 |
|
---|
125 | const getjQuery = () => {
|
---|
126 | const {
|
---|
127 | jQuery
|
---|
128 | } = window;
|
---|
129 |
|
---|
130 | if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
---|
131 | return jQuery;
|
---|
132 | }
|
---|
133 |
|
---|
134 | return null;
|
---|
135 | };
|
---|
136 |
|
---|
137 | const DOMContentLoadedCallbacks = [];
|
---|
138 |
|
---|
139 | const onDOMContentLoaded = callback => {
|
---|
140 | if (document.readyState === 'loading') {
|
---|
141 | // add listener on the first call when the document is in loading state
|
---|
142 | if (!DOMContentLoadedCallbacks.length) {
|
---|
143 | document.addEventListener('DOMContentLoaded', () => {
|
---|
144 | DOMContentLoadedCallbacks.forEach(callback => callback());
|
---|
145 | });
|
---|
146 | }
|
---|
147 |
|
---|
148 | DOMContentLoadedCallbacks.push(callback);
|
---|
149 | } else {
|
---|
150 | callback();
|
---|
151 | }
|
---|
152 | };
|
---|
153 |
|
---|
154 | const defineJQueryPlugin = plugin => {
|
---|
155 | onDOMContentLoaded(() => {
|
---|
156 | const $ = getjQuery();
|
---|
157 | /* istanbul ignore if */
|
---|
158 |
|
---|
159 | if ($) {
|
---|
160 | const name = plugin.NAME;
|
---|
161 | const JQUERY_NO_CONFLICT = $.fn[name];
|
---|
162 | $.fn[name] = plugin.jQueryInterface;
|
---|
163 | $.fn[name].Constructor = plugin;
|
---|
164 |
|
---|
165 | $.fn[name].noConflict = () => {
|
---|
166 | $.fn[name] = JQUERY_NO_CONFLICT;
|
---|
167 | return plugin.jQueryInterface;
|
---|
168 | };
|
---|
169 | }
|
---|
170 | });
|
---|
171 | };
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * --------------------------------------------------------------------------
|
---|
175 | * Bootstrap (v5.1.3): collapse.js
|
---|
176 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
177 | * --------------------------------------------------------------------------
|
---|
178 | */
|
---|
179 | /**
|
---|
180 | * ------------------------------------------------------------------------
|
---|
181 | * Constants
|
---|
182 | * ------------------------------------------------------------------------
|
---|
183 | */
|
---|
184 |
|
---|
185 | const NAME = 'collapse';
|
---|
186 | const DATA_KEY = 'bs.collapse';
|
---|
187 | const EVENT_KEY = `.${DATA_KEY}`;
|
---|
188 | const DATA_API_KEY = '.data-api';
|
---|
189 | const Default = {
|
---|
190 | toggle: true,
|
---|
191 | parent: null
|
---|
192 | };
|
---|
193 | const DefaultType = {
|
---|
194 | toggle: 'boolean',
|
---|
195 | parent: '(null|element)'
|
---|
196 | };
|
---|
197 | const EVENT_SHOW = `show${EVENT_KEY}`;
|
---|
198 | const EVENT_SHOWN = `shown${EVENT_KEY}`;
|
---|
199 | const EVENT_HIDE = `hide${EVENT_KEY}`;
|
---|
200 | const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
|
---|
201 | const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
|
---|
202 | const CLASS_NAME_SHOW = 'show';
|
---|
203 | const CLASS_NAME_COLLAPSE = 'collapse';
|
---|
204 | const CLASS_NAME_COLLAPSING = 'collapsing';
|
---|
205 | const CLASS_NAME_COLLAPSED = 'collapsed';
|
---|
206 | const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`;
|
---|
207 | const CLASS_NAME_HORIZONTAL = 'collapse-horizontal';
|
---|
208 | const WIDTH = 'width';
|
---|
209 | const HEIGHT = 'height';
|
---|
210 | const SELECTOR_ACTIVES = '.collapse.show, .collapse.collapsing';
|
---|
211 | const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]';
|
---|
212 | /**
|
---|
213 | * ------------------------------------------------------------------------
|
---|
214 | * Class Definition
|
---|
215 | * ------------------------------------------------------------------------
|
---|
216 | */
|
---|
217 |
|
---|
218 | class Collapse extends BaseComponent__default.default {
|
---|
219 | constructor(element, config) {
|
---|
220 | super(element);
|
---|
221 | this._isTransitioning = false;
|
---|
222 | this._config = this._getConfig(config);
|
---|
223 | this._triggerArray = [];
|
---|
224 | const toggleList = SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE);
|
---|
225 |
|
---|
226 | for (let i = 0, len = toggleList.length; i < len; i++) {
|
---|
227 | const elem = toggleList[i];
|
---|
228 | const selector = getSelectorFromElement(elem);
|
---|
229 | const filterElement = SelectorEngine__default.default.find(selector).filter(foundElem => foundElem === this._element);
|
---|
230 |
|
---|
231 | if (selector !== null && filterElement.length) {
|
---|
232 | this._selector = selector;
|
---|
233 |
|
---|
234 | this._triggerArray.push(elem);
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | this._initializeChildren();
|
---|
239 |
|
---|
240 | if (!this._config.parent) {
|
---|
241 | this._addAriaAndCollapsedClass(this._triggerArray, this._isShown());
|
---|
242 | }
|
---|
243 |
|
---|
244 | if (this._config.toggle) {
|
---|
245 | this.toggle();
|
---|
246 | }
|
---|
247 | } // Getters
|
---|
248 |
|
---|
249 |
|
---|
250 | static get Default() {
|
---|
251 | return Default;
|
---|
252 | }
|
---|
253 |
|
---|
254 | static get NAME() {
|
---|
255 | return NAME;
|
---|
256 | } // Public
|
---|
257 |
|
---|
258 |
|
---|
259 | toggle() {
|
---|
260 | if (this._isShown()) {
|
---|
261 | this.hide();
|
---|
262 | } else {
|
---|
263 | this.show();
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | show() {
|
---|
268 | if (this._isTransitioning || this._isShown()) {
|
---|
269 | return;
|
---|
270 | }
|
---|
271 |
|
---|
272 | let actives = [];
|
---|
273 | let activesData;
|
---|
274 |
|
---|
275 | if (this._config.parent) {
|
---|
276 | const children = SelectorEngine__default.default.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent);
|
---|
277 | actives = SelectorEngine__default.default.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem)); // remove children if greater depth
|
---|
278 | }
|
---|
279 |
|
---|
280 | const container = SelectorEngine__default.default.findOne(this._selector);
|
---|
281 |
|
---|
282 | if (actives.length) {
|
---|
283 | const tempActiveData = actives.find(elem => container !== elem);
|
---|
284 | activesData = tempActiveData ? Collapse.getInstance(tempActiveData) : null;
|
---|
285 |
|
---|
286 | if (activesData && activesData._isTransitioning) {
|
---|
287 | return;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | const startEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW);
|
---|
292 |
|
---|
293 | if (startEvent.defaultPrevented) {
|
---|
294 | return;
|
---|
295 | }
|
---|
296 |
|
---|
297 | actives.forEach(elemActive => {
|
---|
298 | if (container !== elemActive) {
|
---|
299 | Collapse.getOrCreateInstance(elemActive, {
|
---|
300 | toggle: false
|
---|
301 | }).hide();
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (!activesData) {
|
---|
305 | Data__default.default.set(elemActive, DATA_KEY, null);
|
---|
306 | }
|
---|
307 | });
|
---|
308 |
|
---|
309 | const dimension = this._getDimension();
|
---|
310 |
|
---|
311 | this._element.classList.remove(CLASS_NAME_COLLAPSE);
|
---|
312 |
|
---|
313 | this._element.classList.add(CLASS_NAME_COLLAPSING);
|
---|
314 |
|
---|
315 | this._element.style[dimension] = 0;
|
---|
316 |
|
---|
317 | this._addAriaAndCollapsedClass(this._triggerArray, true);
|
---|
318 |
|
---|
319 | this._isTransitioning = true;
|
---|
320 |
|
---|
321 | const complete = () => {
|
---|
322 | this._isTransitioning = false;
|
---|
323 |
|
---|
324 | this._element.classList.remove(CLASS_NAME_COLLAPSING);
|
---|
325 |
|
---|
326 | this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
|
---|
327 |
|
---|
328 | this._element.style[dimension] = '';
|
---|
329 | EventHandler__default.default.trigger(this._element, EVENT_SHOWN);
|
---|
330 | };
|
---|
331 |
|
---|
332 | const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
|
---|
333 | const scrollSize = `scroll${capitalizedDimension}`;
|
---|
334 |
|
---|
335 | this._queueCallback(complete, this._element, true);
|
---|
336 |
|
---|
337 | this._element.style[dimension] = `${this._element[scrollSize]}px`;
|
---|
338 | }
|
---|
339 |
|
---|
340 | hide() {
|
---|
341 | if (this._isTransitioning || !this._isShown()) {
|
---|
342 | return;
|
---|
343 | }
|
---|
344 |
|
---|
345 | const startEvent = EventHandler__default.default.trigger(this._element, EVENT_HIDE);
|
---|
346 |
|
---|
347 | if (startEvent.defaultPrevented) {
|
---|
348 | return;
|
---|
349 | }
|
---|
350 |
|
---|
351 | const dimension = this._getDimension();
|
---|
352 |
|
---|
353 | this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`;
|
---|
354 | reflow(this._element);
|
---|
355 |
|
---|
356 | this._element.classList.add(CLASS_NAME_COLLAPSING);
|
---|
357 |
|
---|
358 | this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
|
---|
359 |
|
---|
360 | const triggerArrayLength = this._triggerArray.length;
|
---|
361 |
|
---|
362 | for (let i = 0; i < triggerArrayLength; i++) {
|
---|
363 | const trigger = this._triggerArray[i];
|
---|
364 | const elem = getElementFromSelector(trigger);
|
---|
365 |
|
---|
366 | if (elem && !this._isShown(elem)) {
|
---|
367 | this._addAriaAndCollapsedClass([trigger], false);
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 | this._isTransitioning = true;
|
---|
372 |
|
---|
373 | const complete = () => {
|
---|
374 | this._isTransitioning = false;
|
---|
375 |
|
---|
376 | this._element.classList.remove(CLASS_NAME_COLLAPSING);
|
---|
377 |
|
---|
378 | this._element.classList.add(CLASS_NAME_COLLAPSE);
|
---|
379 |
|
---|
380 | EventHandler__default.default.trigger(this._element, EVENT_HIDDEN);
|
---|
381 | };
|
---|
382 |
|
---|
383 | this._element.style[dimension] = '';
|
---|
384 |
|
---|
385 | this._queueCallback(complete, this._element, true);
|
---|
386 | }
|
---|
387 |
|
---|
388 | _isShown(element = this._element) {
|
---|
389 | return element.classList.contains(CLASS_NAME_SHOW);
|
---|
390 | } // Private
|
---|
391 |
|
---|
392 |
|
---|
393 | _getConfig(config) {
|
---|
394 | config = { ...Default,
|
---|
395 | ...Manipulator__default.default.getDataAttributes(this._element),
|
---|
396 | ...config
|
---|
397 | };
|
---|
398 | config.toggle = Boolean(config.toggle); // Coerce string values
|
---|
399 |
|
---|
400 | config.parent = getElement(config.parent);
|
---|
401 | typeCheckConfig(NAME, config, DefaultType);
|
---|
402 | return config;
|
---|
403 | }
|
---|
404 |
|
---|
405 | _getDimension() {
|
---|
406 | return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT;
|
---|
407 | }
|
---|
408 |
|
---|
409 | _initializeChildren() {
|
---|
410 | if (!this._config.parent) {
|
---|
411 | return;
|
---|
412 | }
|
---|
413 |
|
---|
414 | const children = SelectorEngine__default.default.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent);
|
---|
415 | SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem)).forEach(element => {
|
---|
416 | const selected = getElementFromSelector(element);
|
---|
417 |
|
---|
418 | if (selected) {
|
---|
419 | this._addAriaAndCollapsedClass([element], this._isShown(selected));
|
---|
420 | }
|
---|
421 | });
|
---|
422 | }
|
---|
423 |
|
---|
424 | _addAriaAndCollapsedClass(triggerArray, isOpen) {
|
---|
425 | if (!triggerArray.length) {
|
---|
426 | return;
|
---|
427 | }
|
---|
428 |
|
---|
429 | triggerArray.forEach(elem => {
|
---|
430 | if (isOpen) {
|
---|
431 | elem.classList.remove(CLASS_NAME_COLLAPSED);
|
---|
432 | } else {
|
---|
433 | elem.classList.add(CLASS_NAME_COLLAPSED);
|
---|
434 | }
|
---|
435 |
|
---|
436 | elem.setAttribute('aria-expanded', isOpen);
|
---|
437 | });
|
---|
438 | } // Static
|
---|
439 |
|
---|
440 |
|
---|
441 | static jQueryInterface(config) {
|
---|
442 | return this.each(function () {
|
---|
443 | const _config = {};
|
---|
444 |
|
---|
445 | if (typeof config === 'string' && /show|hide/.test(config)) {
|
---|
446 | _config.toggle = false;
|
---|
447 | }
|
---|
448 |
|
---|
449 | const data = Collapse.getOrCreateInstance(this, _config);
|
---|
450 |
|
---|
451 | if (typeof config === 'string') {
|
---|
452 | if (typeof data[config] === 'undefined') {
|
---|
453 | throw new TypeError(`No method named "${config}"`);
|
---|
454 | }
|
---|
455 |
|
---|
456 | data[config]();
|
---|
457 | }
|
---|
458 | });
|
---|
459 | }
|
---|
460 |
|
---|
461 | }
|
---|
462 | /**
|
---|
463 | * ------------------------------------------------------------------------
|
---|
464 | * Data Api implementation
|
---|
465 | * ------------------------------------------------------------------------
|
---|
466 | */
|
---|
467 |
|
---|
468 |
|
---|
469 | EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
---|
470 | // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
|
---|
471 | if (event.target.tagName === 'A' || event.delegateTarget && event.delegateTarget.tagName === 'A') {
|
---|
472 | event.preventDefault();
|
---|
473 | }
|
---|
474 |
|
---|
475 | const selector = getSelectorFromElement(this);
|
---|
476 | const selectorElements = SelectorEngine__default.default.find(selector);
|
---|
477 | selectorElements.forEach(element => {
|
---|
478 | Collapse.getOrCreateInstance(element, {
|
---|
479 | toggle: false
|
---|
480 | }).toggle();
|
---|
481 | });
|
---|
482 | });
|
---|
483 | /**
|
---|
484 | * ------------------------------------------------------------------------
|
---|
485 | * jQuery
|
---|
486 | * ------------------------------------------------------------------------
|
---|
487 | * add .Collapse to jQuery only if jQuery is present
|
---|
488 | */
|
---|
489 |
|
---|
490 | defineJQueryPlugin(Collapse);
|
---|
491 |
|
---|
492 | return Collapse;
|
---|
493 |
|
---|
494 | }));
|
---|
495 | //# sourceMappingURL=collapse.js.map
|
---|