aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/collapse.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/collapse.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/collapse.js212
1 files changed, 115 insertions, 97 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/collapse.js b/vendor/twbs/bootstrap/js/dist/collapse.js
index b096eac3f..5a1beb7d3 100644
--- a/vendor/twbs/bootstrap/js/dist/collapse.js
+++ b/vendor/twbs/bootstrap/js/dist/collapse.js
@@ -1,29 +1,22 @@
/*!
- * Bootstrap collapse.js v5.1.1 (https://getbootstrap.com/)
+ * Bootstrap collapse.js v5.0.2 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
(function (global, factory) {
- 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')) :
- typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
-}(this, (function (Data, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/selector-engine.js'), require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
+ typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './dom/data', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.SelectorEngine, global.Data, global.EventHandler, global.Manipulator, global.Base));
+}(this, (function (SelectorEngine, Data, EventHandler, Manipulator, BaseComponent) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
+ var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
- var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
- /**
- * --------------------------------------------------------------------------
- * Bootstrap (v5.1.1): util/index.js
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
- * --------------------------------------------------------------------------
- */
-
const toType = obj => {
if (obj === null || obj === undefined) {
return `${obj}`;
@@ -90,7 +83,7 @@
}
if (typeof obj === 'string' && obj.length > 0) {
- return document.querySelector(obj);
+ return SelectorEngine__default['default'].findOne(obj);
}
return null;
@@ -107,20 +100,8 @@
}
});
};
- /**
- * Trick to restart an element's animation
- *
- * @param {HTMLElement} element
- * @return void
- *
- * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
- */
-
- const reflow = element => {
- // eslint-disable-next-line no-unused-expressions
- element.offsetHeight;
- };
+ const reflow = element => element.offsetHeight;
const getjQuery = () => {
const {
@@ -172,7 +153,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.1.1): collapse.js
+ * Bootstrap (v5.0.2): collapse.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -188,11 +169,11 @@
const DATA_API_KEY = '.data-api';
const Default = {
toggle: true,
- parent: null
+ parent: ''
};
const DefaultType = {
toggle: 'boolean',
- parent: '(null|element)'
+ parent: '(string|element)'
};
const EVENT_SHOW = `show${EVENT_KEY}`;
const EVENT_SHOWN = `shown${EVENT_KEY}`;
@@ -203,10 +184,9 @@
const CLASS_NAME_COLLAPSE = 'collapse';
const CLASS_NAME_COLLAPSING = 'collapsing';
const CLASS_NAME_COLLAPSED = 'collapsed';
- const CLASS_NAME_HORIZONTAL = 'collapse-horizontal';
const WIDTH = 'width';
const HEIGHT = 'height';
- const SELECTOR_ACTIVES = '.collapse.show, .collapse.collapsing';
+ const SELECTOR_ACTIVES = '.show, .collapsing';
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]';
/**
* ------------------------------------------------------------------------
@@ -219,7 +199,7 @@
super(element);
this._isTransitioning = false;
this._config = this._getConfig(config);
- this._triggerArray = [];
+ this._triggerArray = SelectorEngine__default['default'].find(`${SELECTOR_DATA_TOGGLE}[href="#${this._element.id}"],` + `${SELECTOR_DATA_TOGGLE}[data-bs-target="#${this._element.id}"]`);
const toggleList = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE);
for (let i = 0, len = toggleList.length; i < len; i++) {
@@ -234,10 +214,10 @@
}
}
- this._initializeChildren();
+ this._parent = this._config.parent ? this._getParent() : null;
if (!this._config.parent) {
- this._addAriaAndCollapsedClass(this._triggerArray, this._isShown());
+ this._addAriaAndCollapsedClass(this._element, this._triggerArray);
}
if (this._config.toggle) {
@@ -256,7 +236,7 @@
toggle() {
- if (this._isShown()) {
+ if (this._element.classList.contains(CLASS_NAME_SHOW)) {
this.hide();
} else {
this.show();
@@ -264,21 +244,30 @@
}
show() {
- if (this._isTransitioning || this._isShown()) {
+ if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) {
return;
}
- let actives = [];
+ let actives;
let activesData;
- if (this._config.parent) {
- const children = SelectorEngine__default['default'].find(`.${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`, this._config.parent);
- actives = SelectorEngine__default['default'].find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem)); // remove children if greater depth
+ if (this._parent) {
+ actives = SelectorEngine__default['default'].find(SELECTOR_ACTIVES, this._parent).filter(elem => {
+ if (typeof this._config.parent === 'string') {
+ return elem.getAttribute('data-bs-parent') === this._config.parent;
+ }
+
+ return elem.classList.contains(CLASS_NAME_COLLAPSE);
+ });
+
+ if (actives.length === 0) {
+ actives = null;
+ }
}
const container = SelectorEngine__default['default'].findOne(this._selector);
- if (actives.length) {
+ if (actives) {
const tempActiveData = actives.find(elem => container !== elem);
activesData = tempActiveData ? Collapse.getInstance(tempActiveData) : null;
@@ -293,17 +282,17 @@
return;
}
- actives.forEach(elemActive => {
- if (container !== elemActive) {
- Collapse.getOrCreateInstance(elemActive, {
- toggle: false
- }).hide();
- }
+ if (actives) {
+ actives.forEach(elemActive => {
+ if (container !== elemActive) {
+ Collapse.collapseInterface(elemActive, 'hide');
+ }
- if (!activesData) {
- Data__default['default'].set(elemActive, DATA_KEY, null);
- }
- });
+ if (!activesData) {
+ Data__default['default'].set(elemActive, DATA_KEY, null);
+ }
+ });
+ }
const dimension = this._getDimension();
@@ -313,18 +302,22 @@
this._element.style[dimension] = 0;
- this._addAriaAndCollapsedClass(this._triggerArray, true);
+ if (this._triggerArray.length) {
+ this._triggerArray.forEach(element => {
+ element.classList.remove(CLASS_NAME_COLLAPSED);
+ element.setAttribute('aria-expanded', true);
+ });
+ }
- this._isTransitioning = true;
+ this.setTransitioning(true);
const complete = () => {
- this._isTransitioning = false;
-
this._element.classList.remove(CLASS_NAME_COLLAPSING);
this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
this._element.style[dimension] = '';
+ this.setTransitioning(false);
EventHandler__default['default'].trigger(this._element, EVENT_SHOWN);
};
@@ -337,7 +330,7 @@
}
hide() {
- if (this._isTransitioning || !this._isShown()) {
+ if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) {
return;
}
@@ -358,19 +351,22 @@
const triggerArrayLength = this._triggerArray.length;
- for (let i = 0; i < triggerArrayLength; i++) {
- const trigger = this._triggerArray[i];
- const elem = getElementFromSelector(trigger);
+ if (triggerArrayLength > 0) {
+ for (let i = 0; i < triggerArrayLength; i++) {
+ const trigger = this._triggerArray[i];
+ const elem = getElementFromSelector(trigger);
- if (elem && !this._isShown(elem)) {
- this._addAriaAndCollapsedClass([trigger], false);
+ if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) {
+ trigger.classList.add(CLASS_NAME_COLLAPSED);
+ trigger.setAttribute('aria-expanded', false);
+ }
}
}
- this._isTransitioning = true;
+ this.setTransitioning(true);
const complete = () => {
- this._isTransitioning = false;
+ this.setTransitioning(false);
this._element.classList.remove(CLASS_NAME_COLLAPSING);
@@ -384,47 +380,45 @@
this._queueCallback(complete, this._element, true);
}
- _isShown(element = this._element) {
- return element.classList.contains(CLASS_NAME_SHOW);
+ setTransitioning(isTransitioning) {
+ this._isTransitioning = isTransitioning;
} // Private
_getConfig(config) {
config = { ...Default,
- ...Manipulator__default['default'].getDataAttributes(this._element),
...config
};
config.toggle = Boolean(config.toggle); // Coerce string values
- config.parent = getElement(config.parent);
typeCheckConfig(NAME, config, DefaultType);
return config;
}
_getDimension() {
- return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT;
+ return this._element.classList.contains(WIDTH) ? WIDTH : HEIGHT;
}
- _initializeChildren() {
- if (!this._config.parent) {
- return;
- }
-
- const children = SelectorEngine__default['default'].find(`.${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`, this._config.parent);
- SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem)).forEach(element => {
+ _getParent() {
+ let {
+ parent
+ } = this._config;
+ parent = getElement(parent);
+ const selector = `${SELECTOR_DATA_TOGGLE}[data-bs-parent="${parent}"]`;
+ SelectorEngine__default['default'].find(selector, parent).forEach(element => {
const selected = getElementFromSelector(element);
- if (selected) {
- this._addAriaAndCollapsedClass([element], this._isShown(selected));
- }
+ this._addAriaAndCollapsedClass(selected, [element]);
});
+ return parent;
}
- _addAriaAndCollapsedClass(triggerArray, isOpen) {
- if (!triggerArray.length) {
+ _addAriaAndCollapsedClass(element, triggerArray) {
+ if (!element || !triggerArray.length) {
return;
}
+ const isOpen = element.classList.contains(CLASS_NAME_SHOW);
triggerArray.forEach(elem => {
if (isOpen) {
elem.classList.remove(CLASS_NAME_COLLAPSED);
@@ -437,23 +431,33 @@
} // Static
- static jQueryInterface(config) {
- return this.each(function () {
- const _config = {};
-
- if (typeof config === 'string' && /show|hide/.test(config)) {
- _config.toggle = false;
- }
+ static collapseInterface(element, config) {
+ let data = Collapse.getInstance(element);
+ const _config = { ...Default,
+ ...Manipulator__default['default'].getDataAttributes(element),
+ ...(typeof config === 'object' && config ? config : {})
+ };
- const data = Collapse.getOrCreateInstance(this, _config);
+ if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
+ _config.toggle = false;
+ }
- if (typeof config === 'string') {
- if (typeof data[config] === 'undefined') {
- throw new TypeError(`No method named "${config}"`);
- }
+ if (!data) {
+ data = new Collapse(element, _config);
+ }
- data[config]();
+ if (typeof config === 'string') {
+ if (typeof data[config] === 'undefined') {
+ throw new TypeError(`No method named "${config}"`);
}
+
+ data[config]();
+ }
+ }
+
+ static jQueryInterface(config) {
+ return this.each(function () {
+ Collapse.collapseInterface(this, config);
});
}
@@ -471,12 +475,26 @@
event.preventDefault();
}
+ const triggerData = Manipulator__default['default'].getDataAttributes(this);
const selector = getSelectorFromElement(this);
const selectorElements = SelectorEngine__default['default'].find(selector);
selectorElements.forEach(element => {
- Collapse.getOrCreateInstance(element, {
- toggle: false
- }).toggle();
+ const data = Collapse.getInstance(element);
+ let 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;
+ }
+
+ Collapse.collapseInterface(element, config);
});
});
/**