aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/modal.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
committerMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
commitd459dfac74e90c29950d49a82edc19fd913d435e (patch)
tree7bed5f2dbc318f87bbe0f4be2cde3dde09cd97c7 /vendor/twbs/bootstrap/js/dist/modal.js
parentcec2f0d894b80f3affeb60cff2d4afa49a2019a8 (diff)
downloadvolse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.gz
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.bz2
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.zip
update to bootstrap 5.0.2
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/modal.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/modal.js279
1 files changed, 171 insertions, 108 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/modal.js b/vendor/twbs/bootstrap/js/dist/modal.js
index b59ebe883..f26ae4c2c 100644
--- a/vendor/twbs/bootstrap/js/dist/modal.js
+++ b/vendor/twbs/bootstrap/js/dist/modal.js
@@ -1,5 +1,5 @@
/*!
- * Bootstrap modal.js v5.0.1 (https://getbootstrap.com/)
+ * Bootstrap modal.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)
*/
@@ -95,22 +95,17 @@
return typeof obj.nodeType !== 'undefined';
};
- const emulateTransitionEnd = (element, duration) => {
- let called = false;
- const durationPadding = 5;
- const emulatedDuration = duration + durationPadding;
+ const getElement = obj => {
+ if (isElement(obj)) {
+ // it's a jQuery object or a node element
+ return obj.jquery ? obj[0] : obj;
+ }
- function listener() {
- called = true;
- element.removeEventListener(TRANSITION_END, listener);
+ if (typeof obj === 'string' && obj.length > 0) {
+ return SelectorEngine__default['default'].findOne(obj);
}
- element.addEventListener(TRANSITION_END, listener);
- setTimeout(() => {
- if (!called) {
- triggerTransitionEnd(element);
- }
- }, emulatedDuration);
+ return null;
};
const typeCheckConfig = (componentName, config, configTypes) => {
@@ -126,17 +121,11 @@
};
const isVisible = element => {
- if (!element) {
+ if (!isElement(element) || element.getClientRects().length === 0) {
return false;
}
- if (element.style && element.parentNode && element.parentNode.style) {
- const elementStyle = getComputedStyle(element);
- const parentNodeStyle = getComputedStyle(element.parentNode);
- return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
- }
-
- return false;
+ return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
};
const reflow = element => element.offsetHeight;
@@ -153,9 +142,18 @@
return null;
};
+ const DOMContentLoadedCallbacks = [];
+
const onDOMContentLoaded = callback => {
if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', callback);
+ // add listener on the first call when the document is in loading state
+ if (!DOMContentLoadedCallbacks.length) {
+ document.addEventListener('DOMContentLoaded', () => {
+ DOMContentLoadedCallbacks.forEach(callback => callback());
+ });
+ }
+
+ DOMContentLoadedCallbacks.push(callback);
} else {
callback();
}
@@ -188,83 +186,143 @@
}
};
+ 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): util/scrollBar.js
+ * Bootstrap (v5.0.2): util/scrollBar.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
const SELECTOR_STICKY_CONTENT = '.sticky-top';
- const getWidth = () => {
- // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes
- const documentWidth = document.documentElement.clientWidth;
- return Math.abs(window.innerWidth - documentWidth);
- };
+ class ScrollBarHelper {
+ constructor() {
+ this._element = document.body;
+ }
- const hide = (width = getWidth()) => {
- _disableOverFlow(); // give padding to element to balances the hidden scrollbar width
+ getWidth() {
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes
+ const documentWidth = document.documentElement.clientWidth;
+ return Math.abs(window.innerWidth - documentWidth);
+ }
+ hide() {
+ const width = this.getWidth();
- _setElementAttributes('body', 'paddingRight', calculatedValue => calculatedValue + width); // trick: We adjust positive paddingRight and negative marginRight to sticky-top elements, to keep shown fullwidth
+ this._disableOverFlow(); // give padding to element to balance the hidden scrollbar width
- _setElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight', calculatedValue => calculatedValue + width);
+ this._setElementAttributes(this._element, 'paddingRight', calculatedValue => calculatedValue + width); // trick: We adjust positive paddingRight and negative marginRight to sticky-top elements to keep showing fullwidth
- _setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - width);
- };
- const _disableOverFlow = () => {
- const actualValue = document.body.style.overflow;
+ this._setElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight', calculatedValue => calculatedValue + width);
- if (actualValue) {
- Manipulator__default['default'].setDataAttribute(document.body, 'overflow', actualValue);
+ this._setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - width);
}
- document.body.style.overflow = 'hidden';
- };
+ _disableOverFlow() {
+ this._saveInitialAttribute(this._element, 'overflow');
- const _setElementAttributes = (selector, styleProp, callback) => {
- const scrollbarWidth = getWidth();
- SelectorEngine__default['default'].find(selector).forEach(element => {
- if (element !== document.body && window.innerWidth > element.clientWidth + scrollbarWidth) {
- return;
- }
+ this._element.style.overflow = 'hidden';
+ }
- const actualValue = element.style[styleProp];
- const calculatedValue = window.getComputedStyle(element)[styleProp];
- Manipulator__default['default'].setDataAttribute(element, styleProp, actualValue);
- element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px`;
- });
- };
+ _setElementAttributes(selector, styleProp, callback) {
+ const scrollbarWidth = this.getWidth();
- const reset = () => {
- _resetElementAttributes('body', 'overflow');
+ const manipulationCallBack = element => {
+ if (element !== this._element && window.innerWidth > element.clientWidth + scrollbarWidth) {
+ return;
+ }
- _resetElementAttributes('body', 'paddingRight');
+ this._saveInitialAttribute(element, styleProp);
- _resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight');
+ const calculatedValue = window.getComputedStyle(element)[styleProp];
+ element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px`;
+ };
- _resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight');
- };
+ this._applyManipulationCallback(selector, manipulationCallBack);
+ }
- const _resetElementAttributes = (selector, styleProp) => {
- SelectorEngine__default['default'].find(selector).forEach(element => {
- const value = Manipulator__default['default'].getDataAttribute(element, styleProp);
+ reset() {
+ this._resetElementAttributes(this._element, 'overflow');
- if (typeof value === 'undefined') {
- element.style.removeProperty(styleProp);
+ this._resetElementAttributes(this._element, 'paddingRight');
+
+ this._resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight');
+
+ this._resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight');
+ }
+
+ _saveInitialAttribute(element, styleProp) {
+ const actualValue = element.style[styleProp];
+
+ if (actualValue) {
+ Manipulator__default['default'].setDataAttribute(element, styleProp, actualValue);
+ }
+ }
+
+ _resetElementAttributes(selector, styleProp) {
+ const manipulationCallBack = element => {
+ const value = Manipulator__default['default'].getDataAttribute(element, styleProp);
+
+ if (typeof value === 'undefined') {
+ element.style.removeProperty(styleProp);
+ } else {
+ Manipulator__default['default'].removeDataAttribute(element, styleProp);
+ element.style[styleProp] = value;
+ }
+ };
+
+ this._applyManipulationCallback(selector, manipulationCallBack);
+ }
+
+ _applyManipulationCallback(selector, callBack) {
+ if (isElement(selector)) {
+ callBack(selector);
} else {
- Manipulator__default['default'].removeDataAttribute(element, styleProp);
- element.style[styleProp] = value;
+ SelectorEngine__default['default'].find(selector, this._element).forEach(callBack);
}
- });
- };
+ }
+
+ isOverflowing() {
+ return this.getWidth() > 0;
+ }
+
+ }
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.1): util/backdrop.js
+ * Bootstrap (v5.0.2): util/backdrop.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -272,14 +330,14 @@
isVisible: true,
// if false, we use the backdrop helper without adding any element to the dom
isAnimated: false,
- rootElement: document.body,
+ rootElement: 'body',
// give the choice to place backdrop under different elements
clickCallback: null
};
const DefaultType$1 = {
isVisible: 'boolean',
isAnimated: 'boolean',
- rootElement: 'element',
+ rootElement: '(element|string)',
clickCallback: '(function|null)'
};
const NAME$1 = 'backdrop';
@@ -347,8 +405,9 @@
_getConfig(config) {
config = { ...Default$1,
...(typeof config === 'object' ? config : {})
- };
- config.rootElement = config.rootElement || document.body;
+ }; // use getElement() with the default "body" to get a fresh Element on each instantiation
+
+ config.rootElement = getElement(config.rootElement);
typeCheckConfig(NAME$1, config, DefaultType$1);
return config;
}
@@ -373,27 +432,20 @@
EventHandler__default['default'].off(this._element, EVENT_MOUSEDOWN);
- this._getElement().parentNode.removeChild(this._element);
+ this._element.remove();
this._isAppended = false;
}
_emulateAnimation(callback) {
- if (!this._config.isAnimated) {
- execute(callback);
- return;
- }
-
- const backdropTransitionDuration = getTransitionDurationFromElement(this._getElement());
- EventHandler__default['default'].one(this._getElement(), 'transitionend', () => execute(callback));
- emulateTransitionEnd(this._getElement(), backdropTransitionDuration);
+ executeAfterTransition(callback, this._getElement(), this._config.isAnimated);
}
}
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.1): modal.js
+ * Bootstrap (v5.0.2): modal.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -453,6 +505,7 @@
this._isShown = false;
this._ignoreBackdropClick = false;
this._isTransitioning = false;
+ this._scrollBar = new ScrollBarHelper();
} // Getters
@@ -474,20 +527,22 @@
return;
}
- if (this._isAnimated()) {
- this._isTransitioning = true;
- }
-
const showEvent = EventHandler__default['default'].trigger(this._element, EVENT_SHOW, {
relatedTarget
});
- if (this._isShown || showEvent.defaultPrevented) {
+ if (showEvent.defaultPrevented) {
return;
}
this._isShown = true;
- hide();
+
+ if (this._isAnimated()) {
+ this._isTransitioning = true;
+ }
+
+ this._scrollBar.hide();
+
document.body.classList.add(CLASS_NAME_OPEN);
this._adjustDialog();
@@ -509,7 +564,7 @@
}
hide(event) {
- if (event) {
+ if (event && ['A', 'AREA'].includes(event.target.tagName)) {
event.preventDefault();
}
@@ -576,7 +631,7 @@
_getConfig(config) {
config = { ...Default,
...Manipulator__default['default'].getDataAttributes(this._element),
- ...config
+ ...(typeof config === 'object' ? config : {})
};
typeCheckConfig(NAME, config, DefaultType);
return config;
@@ -679,7 +734,8 @@
this._resetAdjustments();
- reset();
+ this._scrollBar.reset();
+
EventHandler__default['default'].trigger(this._element, EVENT_HIDDEN);
});
}
@@ -716,27 +772,32 @@
return;
}
- const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
+ const {
+ classList,
+ scrollHeight,
+ style
+ } = this._element;
+ const isModalOverflowing = scrollHeight > document.documentElement.clientHeight; // return if the following background transition hasn't yet completed
+
+ if (!isModalOverflowing && style.overflowY === 'hidden' || classList.contains(CLASS_NAME_STATIC)) {
+ return;
+ }
if (!isModalOverflowing) {
- this._element.style.overflowY = 'hidden';
+ style.overflowY = 'hidden';
}
- this._element.classList.add(CLASS_NAME_STATIC);
+ classList.add(CLASS_NAME_STATIC);
- const modalTransitionDuration = getTransitionDurationFromElement(this._dialog);
- EventHandler__default['default'].off(this._element, 'transitionend');
- EventHandler__default['default'].one(this._element, 'transitionend', () => {
- this._element.classList.remove(CLASS_NAME_STATIC);
+ this._queueCallback(() => {
+ classList.remove(CLASS_NAME_STATIC);
if (!isModalOverflowing) {
- EventHandler__default['default'].one(this._element, 'transitionend', () => {
- this._element.style.overflowY = '';
- });
- emulateTransitionEnd(this._element, modalTransitionDuration);
+ this._queueCallback(() => {
+ style.overflowY = '';
+ }, this._dialog);
}
- });
- emulateTransitionEnd(this._element, modalTransitionDuration);
+ }, this._dialog);
this._element.focus();
} // ----------------------------------------------------------------------
@@ -746,7 +807,9 @@
_adjustDialog() {
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
- const scrollbarWidth = getWidth();
+
+ const scrollbarWidth = this._scrollBar.getWidth();
+
const isBodyOverflowing = scrollbarWidth > 0;
if (!isBodyOverflowing && isModalOverflowing && !isRTL() || isBodyOverflowing && !isModalOverflowing && isRTL()) {
@@ -766,7 +829,7 @@
static jQueryInterface(config, relatedTarget) {
return this.each(function () {
- const data = Modal.getInstance(this) || new Modal(this, typeof config === 'object' ? config : {});
+ const data = Modal.getOrCreateInstance(this, config);
if (typeof config !== 'string') {
return;
@@ -807,7 +870,7 @@
}
});
});
- const data = Modal.getInstance(target) || new Modal(target);
+ const data = Modal.getOrCreateInstance(target);
data.toggle(this);
});
/**