aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/collapse.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-10-08 12:24:19 +0000
committerMario <mario@mariovavti.com>2021-10-08 12:24:19 +0000
commite6dac085cb1d601da1fc63bfd59d811612fa6ef4 (patch)
treef5b704b613c9c8d347857b4e7f8dd0b19cdd7df3 /vendor/twbs/bootstrap/js/dist/collapse.js
parentf5f357060bf0ebcb0b8352519375953d993437e7 (diff)
downloadvolse-hubzilla-e6dac085cb1d601da1fc63bfd59d811612fa6ef4.tar.gz
volse-hubzilla-e6dac085cb1d601da1fc63bfd59d811612fa6ef4.tar.bz2
volse-hubzilla-e6dac085cb1d601da1fc63bfd59d811612fa6ef4.zip
update composer libs
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/collapse.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/collapse.js245
1 files changed, 114 insertions, 131 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/collapse.js b/vendor/twbs/bootstrap/js/dist/collapse.js
index 5a1beb7d3..8d74e903c 100644
--- a/vendor/twbs/bootstrap/js/dist/collapse.js
+++ b/vendor/twbs/bootstrap/js/dist/collapse.js
@@ -1,21 +1,28 @@
/*!
- * Bootstrap collapse.js v5.0.2 (https://getbootstrap.com/)
+ * Bootstrap collapse.js v5.1.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/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';
+ 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';
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
+ const _interopDefaultLegacy = e => 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 BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+ const Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
+ const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
+ const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
+ const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
+ const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+
+ /**
+ * --------------------------------------------------------------------------
+ * Bootstrap (v5.1.2): util/index.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
+ * --------------------------------------------------------------------------
+ */
const toType = obj => {
if (obj === null || obj === undefined) {
@@ -83,7 +90,7 @@
}
if (typeof obj === 'string' && obj.length > 0) {
- return SelectorEngine__default['default'].findOne(obj);
+ return document.querySelector(obj);
}
return null;
@@ -100,8 +107,20 @@
}
});
};
+ /**
+ * 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 => element.offsetHeight;
+ const reflow = element => {
+ // eslint-disable-next-line no-unused-expressions
+ element.offsetHeight;
+ };
const getjQuery = () => {
const {
@@ -153,7 +172,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): collapse.js
+ * Bootstrap (v5.1.2): collapse.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -169,11 +188,11 @@
const DATA_API_KEY = '.data-api';
const Default = {
toggle: true,
- parent: ''
+ parent: null
};
const DefaultType = {
toggle: 'boolean',
- parent: '(string|element)'
+ parent: '(null|element)'
};
const EVENT_SHOW = `show${EVENT_KEY}`;
const EVENT_SHOWN = `shown${EVENT_KEY}`;
@@ -184,9 +203,11 @@
const CLASS_NAME_COLLAPSE = 'collapse';
const CLASS_NAME_COLLAPSING = 'collapsing';
const CLASS_NAME_COLLAPSED = 'collapsed';
+ const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`;
+ const CLASS_NAME_HORIZONTAL = 'collapse-horizontal';
const WIDTH = 'width';
const HEIGHT = 'height';
- const SELECTOR_ACTIVES = '.show, .collapsing';
+ const SELECTOR_ACTIVES = '.collapse.show, .collapse.collapsing';
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]';
/**
* ------------------------------------------------------------------------
@@ -194,18 +215,18 @@
* ------------------------------------------------------------------------
*/
- class Collapse extends BaseComponent__default['default'] {
+ class Collapse extends BaseComponent__default.default {
constructor(element, config) {
super(element);
this._isTransitioning = false;
this._config = this._getConfig(config);
- 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);
+ this._triggerArray = [];
+ const toggleList = SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE);
for (let i = 0, len = toggleList.length; i < len; i++) {
const elem = toggleList[i];
const selector = getSelectorFromElement(elem);
- const filterElement = SelectorEngine__default['default'].find(selector).filter(foundElem => foundElem === this._element);
+ const filterElement = SelectorEngine__default.default.find(selector).filter(foundElem => foundElem === this._element);
if (selector !== null && filterElement.length) {
this._selector = selector;
@@ -214,10 +235,10 @@
}
}
- this._parent = this._config.parent ? this._getParent() : null;
+ this._initializeChildren();
if (!this._config.parent) {
- this._addAriaAndCollapsedClass(this._element, this._triggerArray);
+ this._addAriaAndCollapsedClass(this._triggerArray, this._isShown());
}
if (this._config.toggle) {
@@ -236,7 +257,7 @@
toggle() {
- if (this._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (this._isShown()) {
this.hide();
} else {
this.show();
@@ -244,30 +265,21 @@
}
show() {
- if (this._isTransitioning || this._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (this._isTransitioning || this._isShown()) {
return;
}
- let actives;
+ let actives = [];
let activesData;
- 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;
- }
+ if (this._config.parent) {
+ const children = SelectorEngine__default.default.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent);
+ actives = SelectorEngine__default.default.find(SELECTOR_ACTIVES, this._config.parent).filter(elem => !children.includes(elem)); // remove children if greater depth
}
- const container = SelectorEngine__default['default'].findOne(this._selector);
+ const container = SelectorEngine__default.default.findOne(this._selector);
- if (actives) {
+ if (actives.length) {
const tempActiveData = actives.find(elem => container !== elem);
activesData = tempActiveData ? Collapse.getInstance(tempActiveData) : null;
@@ -276,23 +288,23 @@
}
}
- const startEvent = EventHandler__default['default'].trigger(this._element, EVENT_SHOW);
+ const startEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW);
if (startEvent.defaultPrevented) {
return;
}
- if (actives) {
- actives.forEach(elemActive => {
- if (container !== elemActive) {
- Collapse.collapseInterface(elemActive, 'hide');
- }
+ actives.forEach(elemActive => {
+ if (container !== elemActive) {
+ Collapse.getOrCreateInstance(elemActive, {
+ toggle: false
+ }).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();
@@ -302,23 +314,19 @@
this._element.style[dimension] = 0;
- if (this._triggerArray.length) {
- this._triggerArray.forEach(element => {
- element.classList.remove(CLASS_NAME_COLLAPSED);
- element.setAttribute('aria-expanded', true);
- });
- }
+ this._addAriaAndCollapsedClass(this._triggerArray, true);
- this.setTransitioning(true);
+ this._isTransitioning = 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);
+ EventHandler__default.default.trigger(this._element, EVENT_SHOWN);
};
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
@@ -330,11 +338,11 @@
}
hide() {
- if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (this._isTransitioning || !this._isShown()) {
return;
}
- const startEvent = EventHandler__default['default'].trigger(this._element, EVENT_HIDE);
+ const startEvent = EventHandler__default.default.trigger(this._element, EVENT_HIDE);
if (startEvent.defaultPrevented) {
return;
@@ -351,28 +359,25 @@
const triggerArrayLength = this._triggerArray.length;
- if (triggerArrayLength > 0) {
- for (let i = 0; i < triggerArrayLength; i++) {
- const trigger = this._triggerArray[i];
- const elem = getElementFromSelector(trigger);
+ for (let i = 0; i < triggerArrayLength; i++) {
+ const trigger = this._triggerArray[i];
+ const elem = getElementFromSelector(trigger);
- if (elem && !elem.classList.contains(CLASS_NAME_SHOW)) {
- trigger.classList.add(CLASS_NAME_COLLAPSED);
- trigger.setAttribute('aria-expanded', false);
- }
+ if (elem && !this._isShown(elem)) {
+ this._addAriaAndCollapsedClass([trigger], false);
}
}
- this.setTransitioning(true);
+ this._isTransitioning = true;
const complete = () => {
- this.setTransitioning(false);
+ this._isTransitioning = false;
this._element.classList.remove(CLASS_NAME_COLLAPSING);
this._element.classList.add(CLASS_NAME_COLLAPSE);
- EventHandler__default['default'].trigger(this._element, EVENT_HIDDEN);
+ EventHandler__default.default.trigger(this._element, EVENT_HIDDEN);
};
this._element.style[dimension] = '';
@@ -380,45 +385,47 @@
this._queueCallback(complete, this._element, true);
}
- setTransitioning(isTransitioning) {
- this._isTransitioning = isTransitioning;
+ _isShown(element = this._element) {
+ return element.classList.contains(CLASS_NAME_SHOW);
} // 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(WIDTH) ? WIDTH : HEIGHT;
+ return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT;
}
- _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 => {
+ _initializeChildren() {
+ if (!this._config.parent) {
+ return;
+ }
+
+ const children = SelectorEngine__default.default.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent);
+ SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE, this._config.parent).filter(elem => !children.includes(elem)).forEach(element => {
const selected = getElementFromSelector(element);
- this._addAriaAndCollapsedClass(selected, [element]);
+ if (selected) {
+ this._addAriaAndCollapsedClass([element], this._isShown(selected));
+ }
});
- return parent;
}
- _addAriaAndCollapsedClass(element, triggerArray) {
- if (!element || !triggerArray.length) {
+ _addAriaAndCollapsedClass(triggerArray, isOpen) {
+ if (!triggerArray.length) {
return;
}
- const isOpen = element.classList.contains(CLASS_NAME_SHOW);
triggerArray.forEach(elem => {
if (isOpen) {
elem.classList.remove(CLASS_NAME_COLLAPSED);
@@ -431,33 +438,23 @@
} // Static
- static collapseInterface(element, config) {
- let data = Collapse.getInstance(element);
- const _config = { ...Default,
- ...Manipulator__default['default'].getDataAttributes(element),
- ...(typeof config === 'object' && config ? config : {})
- };
-
- if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
- _config.toggle = false;
- }
-
- if (!data) {
- data = new Collapse(element, _config);
- }
+ static jQueryInterface(config) {
+ return this.each(function () {
+ const _config = {};
- if (typeof config === 'string') {
- if (typeof data[config] === 'undefined') {
- throw new TypeError(`No method named "${config}"`);
+ if (typeof config === 'string' && /show|hide/.test(config)) {
+ _config.toggle = false;
}
- data[config]();
- }
- }
+ const data = Collapse.getOrCreateInstance(this, _config);
- static jQueryInterface(config) {
- return this.each(function () {
- Collapse.collapseInterface(this, config);
+ if (typeof config === 'string') {
+ if (typeof data[config] === 'undefined') {
+ throw new TypeError(`No method named "${config}"`);
+ }
+
+ data[config]();
+ }
});
}
@@ -469,32 +466,18 @@
*/
- EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
+ EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
if (event.target.tagName === 'A' || event.delegateTarget && event.delegateTarget.tagName === 'A') {
event.preventDefault();
}
- const triggerData = Manipulator__default['default'].getDataAttributes(this);
const selector = getSelectorFromElement(this);
- const selectorElements = SelectorEngine__default['default'].find(selector);
+ const selectorElements = SelectorEngine__default.default.find(selector);
selectorElements.forEach(element => {
- 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);
+ Collapse.getOrCreateInstance(element, {
+ toggle: false
+ }).toggle();
});
});
/**
@@ -508,5 +491,5 @@
return Collapse;
-})));
+}));
//# sourceMappingURL=collapse.js.map