mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 22:56:46 +02:00
67
js/dist/base-component.js
vendored
67
js/dist/base-component.js
vendored
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Bootstrap base-component.js v5.0.1 (https://getbootstrap.com/)
|
||||
* Bootstrap base-component.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)
|
||||
*/
|
||||
@@ -70,33 +70,45 @@
|
||||
return null;
|
||||
};
|
||||
|
||||
const emulateTransitionEnd = (element, duration) => {
|
||||
let called = false;
|
||||
const durationPadding = 5;
|
||||
const emulatedDuration = duration + durationPadding;
|
||||
|
||||
function listener() {
|
||||
called = true;
|
||||
element.removeEventListener(TRANSITION_END, listener);
|
||||
}
|
||||
|
||||
element.addEventListener(TRANSITION_END, listener);
|
||||
setTimeout(() => {
|
||||
if (!called) {
|
||||
triggerTransitionEnd(element);
|
||||
}
|
||||
}, emulatedDuration);
|
||||
};
|
||||
|
||||
const execute = callback => {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
|
||||
if (!waitForTransition) {
|
||||
execute(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
const durationPadding = 5;
|
||||
const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
|
||||
let called = false;
|
||||
|
||||
const handler = ({
|
||||
target
|
||||
}) => {
|
||||
if (target !== transitionElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
called = true;
|
||||
transitionElement.removeEventListener(TRANSITION_END, handler);
|
||||
execute(callback);
|
||||
};
|
||||
|
||||
transitionElement.addEventListener(TRANSITION_END, handler);
|
||||
setTimeout(() => {
|
||||
if (!called) {
|
||||
triggerTransitionEnd(transitionElement);
|
||||
}
|
||||
}, emulatedDuration);
|
||||
};
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.1): base-component.js
|
||||
* Bootstrap (v5.0.2): base-component.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -106,7 +118,7 @@
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const VERSION = '5.0.1';
|
||||
const VERSION = '5.0.2';
|
||||
|
||||
class BaseComponent {
|
||||
constructor(element) {
|
||||
@@ -129,14 +141,7 @@
|
||||
}
|
||||
|
||||
_queueCallback(callback, element, isAnimated = true) {
|
||||
if (!isAnimated) {
|
||||
execute(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
const transitionDuration = getTransitionDurationFromElement(element);
|
||||
EventHandler__default['default'].one(element, 'transitionend', () => execute(callback));
|
||||
emulateTransitionEnd(element, transitionDuration);
|
||||
executeAfterTransition(callback, element, isAnimated);
|
||||
}
|
||||
/** Static */
|
||||
|
||||
@@ -145,6 +150,10 @@
|
||||
return Data__default['default'].get(element, this.DATA_KEY);
|
||||
}
|
||||
|
||||
static getOrCreateInstance(element, config = {}) {
|
||||
return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null);
|
||||
}
|
||||
|
||||
static get VERSION() {
|
||||
return VERSION;
|
||||
}
|
||||
|
Reference in New Issue
Block a user