mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-15 01:55:46 +02:00
126
js/dist/collapse.js
vendored
126
js/dist/collapse.js
vendored
@@ -1,31 +1,22 @@
|
||||
/*!
|
||||
* Bootstrap collapse.js v5.0.0 (https://getbootstrap.com/)
|
||||
* Bootstrap collapse.js v5.0.1 (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.0.0): util/index.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
const MILLISECONDS_MULTIPLIER = 1000;
|
||||
const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||
|
||||
const toType = obj => {
|
||||
if (obj === null || obj === undefined) {
|
||||
return `${obj}`;
|
||||
@@ -73,51 +64,29 @@
|
||||
return selector ? document.querySelector(selector) : null;
|
||||
};
|
||||
|
||||
const getTransitionDurationFromElement = element => {
|
||||
if (!element) {
|
||||
return 0;
|
||||
} // Get transition-duration of the element
|
||||
|
||||
|
||||
let {
|
||||
transitionDuration,
|
||||
transitionDelay
|
||||
} = window.getComputedStyle(element);
|
||||
const floatTransitionDuration = Number.parseFloat(transitionDuration);
|
||||
const floatTransitionDelay = Number.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 (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
|
||||
};
|
||||
|
||||
const triggerTransitionEnd = element => {
|
||||
element.dispatchEvent(new Event(TRANSITION_END));
|
||||
};
|
||||
|
||||
const isElement = obj => (obj[0] || obj).nodeType;
|
||||
|
||||
const emulateTransitionEnd = (element, duration) => {
|
||||
let called = false;
|
||||
const durationPadding = 5;
|
||||
const emulatedDuration = duration + durationPadding;
|
||||
|
||||
function listener() {
|
||||
called = true;
|
||||
element.removeEventListener(TRANSITION_END, listener);
|
||||
const isElement = obj => {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
element.addEventListener(TRANSITION_END, listener);
|
||||
setTimeout(() => {
|
||||
if (!called) {
|
||||
triggerTransitionEnd(element);
|
||||
}
|
||||
}, emulatedDuration);
|
||||
if (typeof obj.jquery !== 'undefined') {
|
||||
obj = obj[0];
|
||||
}
|
||||
|
||||
return typeof obj.nodeType !== 'undefined';
|
||||
};
|
||||
|
||||
const getElement = obj => {
|
||||
if (isElement(obj)) {
|
||||
// it's a jQuery object or a node element
|
||||
return obj.jquery ? obj[0] : obj;
|
||||
}
|
||||
|
||||
if (typeof obj === 'string' && obj.length > 0) {
|
||||
return SelectorEngine__default['default'].findOne(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const typeCheckConfig = (componentName, config, configTypes) => {
|
||||
@@ -154,12 +123,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
const defineJQueryPlugin = (name, plugin) => {
|
||||
const defineJQueryPlugin = plugin => {
|
||||
onDOMContentLoaded(() => {
|
||||
const $ = getjQuery();
|
||||
/* istanbul ignore if */
|
||||
|
||||
if ($) {
|
||||
const name = plugin.NAME;
|
||||
const JQUERY_NO_CONFLICT = $.fn[name];
|
||||
$.fn[name] = plugin.jQueryInterface;
|
||||
$.fn[name].Constructor = plugin;
|
||||
@@ -174,7 +144,7 @@
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): collapse.js
|
||||
* Bootstrap (v5.0.1): collapse.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -251,8 +221,8 @@
|
||||
return Default;
|
||||
}
|
||||
|
||||
static get DATA_KEY() {
|
||||
return DATA_KEY;
|
||||
static get NAME() {
|
||||
return NAME;
|
||||
} // Public
|
||||
|
||||
|
||||
@@ -344,9 +314,9 @@
|
||||
|
||||
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
|
||||
const scrollSize = `scroll${capitalizedDimension}`;
|
||||
const transitionDuration = getTransitionDurationFromElement(this._element);
|
||||
EventHandler__default['default'].one(this._element, 'transitionend', complete);
|
||||
emulateTransitionEnd(this._element, transitionDuration);
|
||||
|
||||
this._queueCallback(complete, this._element, true);
|
||||
|
||||
this._element.style[dimension] = `${this._element[scrollSize]}px`;
|
||||
}
|
||||
|
||||
@@ -397,21 +367,12 @@
|
||||
};
|
||||
|
||||
this._element.style[dimension] = '';
|
||||
const transitionDuration = getTransitionDurationFromElement(this._element);
|
||||
EventHandler__default['default'].one(this._element, 'transitionend', complete);
|
||||
emulateTransitionEnd(this._element, transitionDuration);
|
||||
|
||||
this._queueCallback(complete, this._element, true);
|
||||
}
|
||||
|
||||
setTransitioning(isTransitioning) {
|
||||
this._isTransitioning = isTransitioning;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
super.dispose();
|
||||
this._config = null;
|
||||
this._parent = null;
|
||||
this._triggerArray = null;
|
||||
this._isTransitioning = null;
|
||||
} // Private
|
||||
|
||||
|
||||
@@ -433,16 +394,7 @@
|
||||
let {
|
||||
parent
|
||||
} = this._config;
|
||||
|
||||
if (isElement(parent)) {
|
||||
// it's a jQuery object
|
||||
if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') {
|
||||
parent = parent[0];
|
||||
}
|
||||
} else {
|
||||
parent = SelectorEngine__default['default'].findOne(parent);
|
||||
}
|
||||
|
||||
parent = getElement(parent);
|
||||
const selector = `${SELECTOR_DATA_TOGGLE}[data-bs-parent="${parent}"]`;
|
||||
SelectorEngine__default['default'].find(selector, parent).forEach(element => {
|
||||
const selected = getElementFromSelector(element);
|
||||
@@ -543,7 +495,7 @@
|
||||
* add .Collapse to jQuery only if jQuery is present
|
||||
*/
|
||||
|
||||
defineJQueryPlugin(NAME, Collapse);
|
||||
defineJQueryPlugin(Collapse);
|
||||
|
||||
return Collapse;
|
||||
|
||||
|
Reference in New Issue
Block a user