diff options
author | Mario <mario@mariovavti.com> | 2021-07-29 08:25:05 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-07-29 08:25:05 +0000 |
commit | d459dfac74e90c29950d49a82edc19fd913d435e (patch) | |
tree | 7bed5f2dbc318f87bbe0f4be2cde3dde09cd97c7 /vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js | |
parent | cec2f0d894b80f3affeb60cff2d4afa49a2019a8 (diff) | |
download | volse-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/dist/js/bootstrap.bundle.js')
-rw-r--r-- | vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js | 653 |
1 files changed, 337 insertions, 316 deletions
diff --git a/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js b/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js index 852fc9962..d6ce66fe7 100644 --- a/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js +++ b/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.js @@ -1,5 +1,5 @@ /*! - * Bootstrap v5.0.1 (https://getbootstrap.com/) + * Bootstrap 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) */ @@ -11,7 +11,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dom/selector-engine.js + * Bootstrap (v5.0.2): dom/selector-engine.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -82,7 +82,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): util/index.js + * Bootstrap (v5.0.2): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -204,24 +204,6 @@ 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 typeCheckConfig = (componentName, config, configTypes) => { Object.keys(configTypes).forEach(property => { const expectedTypes = configTypes[property]; @@ -235,17 +217,11 @@ }; const isVisible = element => { - if (!element) { + if (!isElement$1(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 isDisabled = element => { @@ -303,9 +279,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(); } @@ -338,63 +323,66 @@ } }; - /** - * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dom/data.js - * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) - * -------------------------------------------------------------------------- - */ - - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ - const elementMap = new Map(); - var Data = { - set(element, key, instance) { - if (!elementMap.has(element)) { - elementMap.set(element, new Map()); - } + const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => { + if (!waitForTransition) { + execute(callback); + return; + } - const instanceMap = elementMap.get(element); // make it clear we only want one instance per element - // can be removed later when multiple key/instances are fine to be used + const durationPadding = 5; + const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding; + let called = false; - if (!instanceMap.has(key) && instanceMap.size !== 0) { - // eslint-disable-next-line no-console - console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`); + const handler = ({ + target + }) => { + if (target !== transitionElement) { return; } - instanceMap.set(key, instance); - }, + called = true; + transitionElement.removeEventListener(TRANSITION_END, handler); + execute(callback); + }; - get(element, key) { - if (elementMap.has(element)) { - return elementMap.get(element).get(key) || null; + transitionElement.addEventListener(TRANSITION_END, handler); + setTimeout(() => { + if (!called) { + triggerTransitionEnd(transitionElement); } + }, emulatedDuration); + }; + /** + * Return the previous/next element of a list. + * + * @param {array} list The list of elements + * @param activeElement The active element + * @param shouldGetNext Choose to get next or previous element + * @param isCycleAllowed + * @return {Element|elem} The proper element + */ - return null; - }, - remove(element, key) { - if (!elementMap.has(element)) { - return; - } + const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => { + let index = list.indexOf(activeElement); // if the element does not exist in the list return an element depending on the direction and if cycle is allowed - const instanceMap = elementMap.get(element); - instanceMap.delete(key); // free up element references if there are no instances left for an element + if (index === -1) { + return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0]; + } - if (instanceMap.size === 0) { - elementMap.delete(element); - } + const listLength = list.length; + index += shouldGetNext ? 1 : -1; + + if (isCycleAllowed) { + index = (index + listLength) % listLength; } + return list[Math.max(0, Math.min(index, listLength - 1))]; }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dom/event-handler.js + * Bootstrap (v5.0.2): dom/event-handler.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -683,17 +671,71 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): base-component.js + * Bootstrap (v5.0.2): dom/data.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ + /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ + const elementMap = new Map(); + var Data = { + set(element, key, instance) { + if (!elementMap.has(element)) { + elementMap.set(element, new Map()); + } + + const instanceMap = elementMap.get(element); // make it clear we only want one instance per element + // can be removed later when multiple key/instances are fine to be used - const VERSION = '5.0.1'; + if (!instanceMap.has(key) && instanceMap.size !== 0) { + // eslint-disable-next-line no-console + console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`); + return; + } + + instanceMap.set(key, instance); + }, + + get(element, key) { + if (elementMap.has(element)) { + return elementMap.get(element).get(key) || null; + } + + return null; + }, + + remove(element, key) { + if (!elementMap.has(element)) { + return; + } + + const instanceMap = elementMap.get(element); + instanceMap.delete(key); // free up element references if there are no instances left for an element + + if (instanceMap.size === 0) { + elementMap.delete(element); + } + } + + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.0.2): base-component.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ + + const VERSION = '5.0.2'; class BaseComponent { constructor(element) { @@ -716,14 +758,7 @@ } _queueCallback(callback, element, isAnimated = true) { - if (!isAnimated) { - execute(callback); - return; - } - - const transitionDuration = getTransitionDurationFromElement(element); - EventHandler.one(element, 'transitionend', () => execute(callback)); - emulateTransitionEnd(element, transitionDuration); + executeAfterTransition(callback, element, isAnimated); } /** Static */ @@ -732,6 +767,10 @@ return Data.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; } @@ -752,7 +791,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): alert.js + * Bootstrap (v5.0.2): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -815,21 +854,14 @@ } _destroyElement(element) { - if (element.parentNode) { - element.parentNode.removeChild(element); - } - + element.remove(); EventHandler.trigger(element, EVENT_CLOSED); } // Static static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY$b); - - if (!data) { - data = new Alert(this); - } + const data = Alert.getOrCreateInstance(this); if (config === 'close') { data[config](this); @@ -867,7 +899,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): button.js + * Bootstrap (v5.0.2): button.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -905,11 +937,7 @@ static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY$a); - - if (!data) { - data = new Button(this); - } + const data = Button.getOrCreateInstance(this); if (config === 'toggle') { data[config](); @@ -928,12 +956,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API$6, SELECTOR_DATA_TOGGLE$5, event => { event.preventDefault(); const button = event.target.closest(SELECTOR_DATA_TOGGLE$5); - let data = Data.get(button, DATA_KEY$a); - - if (!data) { - data = new Button(button); - } - + const data = Button.getOrCreateInstance(button); data.toggle(); }); /** @@ -947,7 +970,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dom/manipulator.js + * Bootstrap (v5.0.2): dom/manipulator.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -1021,7 +1044,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): carousel.js + * Bootstrap (v5.0.2): carousel.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -1060,6 +1083,10 @@ const ORDER_PREV = 'prev'; const DIRECTION_LEFT = 'left'; const DIRECTION_RIGHT = 'right'; + const KEY_TO_DIRECTION = { + [ARROW_LEFT_KEY]: DIRECTION_RIGHT, + [ARROW_RIGHT_KEY]: DIRECTION_LEFT + }; const EVENT_SLIDE = `slide${EVENT_KEY$9}`; const EVENT_SLID = `slid${EVENT_KEY$9}`; const EVENT_KEYDOWN = `keydown${EVENT_KEY$9}`; @@ -1128,9 +1155,7 @@ next() { - if (!this._isSliding) { - this._slide(ORDER_NEXT); - } + this._slide(ORDER_NEXT); } nextWhenVisible() { @@ -1142,9 +1167,7 @@ } prev() { - if (!this._isSliding) { - this._slide(ORDER_PREV); - } + this._slide(ORDER_PREV); } pause(event) { @@ -1206,7 +1229,8 @@ _getConfig(config) { config = { ...Default$9, - ...config + ...Manipulator.getDataAttributes(this._element), + ...(typeof config === 'object' ? config : {}) }; typeCheckConfig(NAME$a, config, DefaultType$9); return config; @@ -1304,14 +1328,12 @@ return; } - if (event.key === ARROW_LEFT_KEY) { - event.preventDefault(); + const direction = KEY_TO_DIRECTION[event.key]; - this._slide(DIRECTION_RIGHT); - } else if (event.key === ARROW_RIGHT_KEY) { + if (direction) { event.preventDefault(); - this._slide(DIRECTION_LEFT); + this._slide(direction); } } @@ -1322,20 +1344,7 @@ _getItemByOrder(order, activeElement) { const isNext = order === ORDER_NEXT; - const isPrev = order === ORDER_PREV; - - const activeIndex = this._getItemIndex(activeElement); - - const lastItemIndex = this._items.length - 1; - const isGoingToWrap = isPrev && activeIndex === 0 || isNext && activeIndex === lastItemIndex; - - if (isGoingToWrap && !this._config.wrap) { - return activeElement; - } - - const delta = isPrev ? -1 : 1; - const itemIndex = (activeIndex + delta) % this._items.length; - return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]; + return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap); } _triggerSlideEvent(relatedTarget, eventDirectionName) { @@ -1408,6 +1417,10 @@ return; } + if (this._isSliding) { + return; + } + const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName); if (slideEvent.defaultPrevented) { @@ -1491,10 +1504,10 @@ static carouselInterface(element, config) { - let data = Data.get(element, DATA_KEY$9); - let _config = { ...Default$9, - ...Manipulator.getDataAttributes(element) - }; + const data = Carousel.getOrCreateInstance(element, config); + let { + _config + } = data; if (typeof config === 'object') { _config = { ..._config, @@ -1504,10 +1517,6 @@ const action = typeof config === 'string' ? config : _config.slide; - if (!data) { - data = new Carousel(element, _config); - } - if (typeof config === 'number') { data.to(config); } else if (typeof action === 'string') { @@ -1547,7 +1556,7 @@ Carousel.carouselInterface(target, config); if (slideIndex) { - Data.get(target, DATA_KEY$9).to(slideIndex); + Carousel.getInstance(target).to(slideIndex); } event.preventDefault(); @@ -1566,7 +1575,7 @@ const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE); for (let i = 0, len = carousels.length; i < len; i++) { - Carousel.carouselInterface(carousels[i], Data.get(carousels[i], DATA_KEY$9)); + Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i])); } }); /** @@ -1580,7 +1589,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): collapse.js + * Bootstrap (v5.0.2): collapse.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -1696,7 +1705,7 @@ if (actives) { const tempActiveData = actives.find(elem => container !== elem); - activesData = tempActiveData ? Data.get(tempActiveData, DATA_KEY$8) : null; + activesData = tempActiveData ? Collapse.getInstance(tempActiveData) : null; if (activesData && activesData._isTransitioning) { return; @@ -1859,7 +1868,7 @@ static collapseInterface(element, config) { - let data = Data.get(element, DATA_KEY$8); + let data = Collapse.getInstance(element); const _config = { ...Default$8, ...Manipulator.getDataAttributes(element), ...(typeof config === 'object' && config ? config : {}) @@ -1906,7 +1915,7 @@ const selector = getSelectorFromElement(this); const selectorElements = SelectorEngine.find(selector); selectorElements.forEach(element => { - const data = Data.get(element, DATA_KEY$8); + const data = Collapse.getInstance(element); let config; if (data) { @@ -3083,7 +3092,7 @@ }); } - function hide$1(_ref) { + function hide(_ref) { var state = _ref.state, name = _ref.name; var referenceRect = state.rects.reference; @@ -3112,12 +3121,12 @@ } // eslint-disable-next-line import/no-unused-modules - var hide$2 = { + var hide$1 = { name: 'hide', enabled: true, phase: 'main', requiresIfExists: ['preventOverflow'], - fn: hide$1 + fn: hide }; function distanceAndSkiddingToXY(placement, rects, offset) { @@ -3640,7 +3649,7 @@ defaultModifiers: defaultModifiers$1 }); // eslint-disable-next-line import/no-unused-modules - var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$2]; + var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1]; var createPopper = /*#__PURE__*/popperGenerator({ defaultModifiers: defaultModifiers }); // eslint-disable-next-line import/no-unused-modules @@ -3681,7 +3690,7 @@ computeStyles: computeStyles$1, eventListeners: eventListeners, flip: flip$1, - hide: hide$2, + hide: hide$1, offset: offset$1, popperOffsets: popperOffsets$1, preventOverflow: preventOverflow$1 @@ -3689,7 +3698,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dropdown.js + * Bootstrap (v5.0.2): dropdown.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -4009,38 +4018,24 @@ }; } - _selectMenuItem(event) { + _selectMenuItem({ + key, + target + }) { const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible); if (!items.length) { return; - } - - let index = items.indexOf(event.target); // Up - - if (event.key === ARROW_UP_KEY && index > 0) { - index--; - } // Down + } // if target isn't included in items (e.g. when expanding the dropdown) + // allow cycling to get the last item in case key equals ARROW_UP_KEY - if (event.key === ARROW_DOWN_KEY && index < items.length - 1) { - index++; - } // index is -1 if the first keydown is an ArrowUp - - - index = index === -1 ? 0 : index; - items[index].focus(); + getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus(); } // Static static dropdownInterface(element, config) { - let data = Data.get(element, DATA_KEY$7); - - const _config = typeof config === 'object' ? config : null; - - if (!data) { - data = new Dropdown(element, _config); - } + const data = Dropdown.getOrCreateInstance(element, config); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -4065,7 +4060,7 @@ const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE$3); for (let i = 0, len = toggles.length; i < len; i++) { - const context = Data.get(toggles[i], DATA_KEY$7); + const context = Dropdown.getInstance(toggles[i]); if (!context || context._config.autoClose === false) { continue; @@ -4138,17 +4133,19 @@ return; } - if (!isActive && (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY)) { - getToggleButton().click(); + if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) { + if (!isActive) { + getToggleButton().click(); + } + + Dropdown.getInstance(getToggleButton())._selectMenuItem(event); + return; } if (!isActive || event.key === SPACE_KEY) { Dropdown.clearMenus(); - return; } - - Dropdown.getInstance(getToggleButton())._selectMenuItem(event); } } @@ -4178,81 +4175,111 @@ /** * -------------------------------------------------------------------------- - * 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.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.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.setDataAttribute(element, styleProp, actualValue); - element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px`; - }); - }; + _setElementAttributes(selector, styleProp, callback) { + const scrollbarWidth = this.getWidth(); + + const manipulationCallBack = element => { + if (element !== this._element && window.innerWidth > element.clientWidth + scrollbarWidth) { + return; + } - const reset = () => { - _resetElementAttributes('body', 'overflow'); + this._saveInitialAttribute(element, styleProp); - _resetElementAttributes('body', 'paddingRight'); + const calculatedValue = window.getComputedStyle(element)[styleProp]; + element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px`; + }; - _resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight'); + this._applyManipulationCallback(selector, manipulationCallBack); + } - _resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight'); - }; + reset() { + this._resetElementAttributes(this._element, 'overflow'); + + 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.setDataAttribute(element, styleProp, actualValue); + } + } + + _resetElementAttributes(selector, styleProp) { + const manipulationCallBack = element => { + const value = Manipulator.getDataAttribute(element, styleProp); + + if (typeof value === 'undefined') { + element.style.removeProperty(styleProp); + } else { + Manipulator.removeDataAttribute(element, styleProp); + element.style[styleProp] = value; + } + }; - const _resetElementAttributes = (selector, styleProp) => { - SelectorEngine.find(selector).forEach(element => { - const value = Manipulator.getDataAttribute(element, styleProp); + this._applyManipulationCallback(selector, manipulationCallBack); + } - if (typeof value === 'undefined') { - element.style.removeProperty(styleProp); + _applyManipulationCallback(selector, callBack) { + if (isElement$1(selector)) { + callBack(selector); } else { - Manipulator.removeDataAttribute(element, styleProp); - element.style[styleProp] = value; + SelectorEngine.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) * -------------------------------------------------------------------------- */ @@ -4260,14 +4287,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$6 = { isVisible: 'boolean', isAnimated: 'boolean', - rootElement: 'element', + rootElement: '(element|string)', clickCallback: '(function|null)' }; const NAME$7 = 'backdrop'; @@ -4335,8 +4362,9 @@ _getConfig(config) { config = { ...Default$6, ...(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$7, config, DefaultType$6); return config; } @@ -4361,27 +4389,20 @@ EventHandler.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.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) * -------------------------------------------------------------------------- */ @@ -4441,6 +4462,7 @@ this._isShown = false; this._ignoreBackdropClick = false; this._isTransitioning = false; + this._scrollBar = new ScrollBarHelper(); } // Getters @@ -4462,20 +4484,22 @@ return; } - if (this._isAnimated()) { - this._isTransitioning = true; - } - const showEvent = EventHandler.trigger(this._element, EVENT_SHOW$3, { 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(); @@ -4497,7 +4521,7 @@ } hide(event) { - if (event) { + if (event && ['A', 'AREA'].includes(event.target.tagName)) { event.preventDefault(); } @@ -4564,7 +4588,7 @@ _getConfig(config) { config = { ...Default$5, ...Manipulator.getDataAttributes(this._element), - ...config + ...(typeof config === 'object' ? config : {}) }; typeCheckConfig(NAME$6, config, DefaultType$5); return config; @@ -4667,7 +4691,8 @@ this._resetAdjustments(); - reset(); + this._scrollBar.reset(); + EventHandler.trigger(this._element, EVENT_HIDDEN$3); }); } @@ -4704,27 +4729,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.off(this._element, 'transitionend'); - EventHandler.one(this._element, 'transitionend', () => { - this._element.classList.remove(CLASS_NAME_STATIC); + this._queueCallback(() => { + classList.remove(CLASS_NAME_STATIC); if (!isModalOverflowing) { - EventHandler.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(); } // ---------------------------------------------------------------------- @@ -4734,7 +4764,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()) { @@ -4754,7 +4786,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; @@ -4795,7 +4827,7 @@ } }); }); - const data = Modal.getInstance(target) || new Modal(target); + const data = Modal.getOrCreateInstance(target); data.toggle(this); }); /** @@ -4809,7 +4841,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): offcanvas.js + * Bootstrap (v5.0.2): offcanvas.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ @@ -4896,7 +4928,7 @@ this._backdrop.show(); if (!this._config.scroll) { - hide(); + new ScrollBarHelper().hide(); this._enforceFocusOnElement(this._element); } @@ -4949,7 +4981,7 @@ this._element.style.visibility = 'hidden'; if (!this._config.scroll) { - reset(); + new ScrollBarHelper().reset(); } EventHandler.trigger(this._element, EVENT_HIDDEN$2); @@ -5007,7 +5039,7 @@ static jQueryInterface(config) { return this.each(function () { - const data = Data.get(this, DATA_KEY$5) || new Offcanvas(this, typeof config === 'object' ? config : {}); + const data = Offcanvas.getOrCreateInstance(this, config); if (typeof config !== 'string') { return; @@ -5053,12 +5085,10 @@ Offcanvas.getInstance(allReadyOpen).hide(); } - const data = Data.get(target, DATA_KEY$5) || new Offcanvas(target); + const data = Offcanvas.getOrCreateInstance(target); data.toggle(this); }); - EventHandler.on(window, EVENT_LOAD_DATA_API$1, () => { - SelectorEngine.find(OPEN_SELECTOR).forEach(el => (Data.get(el, DATA_KEY$5) || new Offcanvas(el)).show()); - }); + EventHandler.on(window, EVENT_LOAD_DATA_API$1, () => SelectorEngine.find(OPEN_SELECTOR).forEach(el => Offcanvas.getOrCreateInstance(el).show())); /** * ------------------------------------------------------------------------ * jQuery @@ -5069,7 +5099,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): util/sanitizer.js + * Bootstrap (v5.0.2): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -5164,7 +5194,7 @@ const elName = el.nodeName.toLowerCase(); if (!allowlistKeys.includes(elName)) { - el.parentNode.removeChild(el); + el.remove(); continue; } @@ -5182,7 +5212,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): tooltip.js + * Bootstrap (v5.0.2): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -5351,8 +5381,8 @@ clearTimeout(this._timeout); EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler); - if (this.tip && this.tip.parentNode) { - this.tip.parentNode.removeChild(this.tip); + if (this.tip) { + this.tip.remove(); } if (this._popper) { @@ -5457,8 +5487,8 @@ return; } - if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { - tip.parentNode.removeChild(tip); + if (this._hoverState !== HOVER_STATE_SHOW) { + tip.remove(); } this._cleanTipClass(); @@ -5845,17 +5875,7 @@ static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY$4); - - const _config = typeof config === 'object' && config; - - if (!data && /dispose|hide/.test(config)) { - return; - } - - if (!data) { - data = new Tooltip(this, _config); - } + const data = Tooltip.getOrCreateInstance(this, config); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -5880,7 +5900,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): popover.js + * Bootstrap (v5.0.2): popover.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -5950,6 +5970,24 @@ return this.getTitle() || this._getContent(); } + getTipElement() { + if (this.tip) { + return this.tip; + } + + this.tip = super.getTipElement(); + + if (!this.getTitle()) { + SelectorEngine.findOne(SELECTOR_TITLE, this.tip).remove(); + } + + if (!this._getContent()) { + SelectorEngine.findOne(SELECTOR_CONTENT, this.tip).remove(); + } + + return this.tip; + } + setContent() { const tip = this.getTipElement(); // we use append for html objects to maintain js events @@ -5986,18 +6024,7 @@ static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY$3); - - const _config = typeof config === 'object' ? config : null; - - if (!data && /dispose|hide/.test(config)) { - return; - } - - if (!data) { - data = new Popover(this, _config); - Data.set(this, DATA_KEY$3, data); - } + const data = Popover.getOrCreateInstance(this, config); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -6022,7 +6049,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): scrollspy.js + * Bootstrap (v5.0.2): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -6237,7 +6264,7 @@ static jQueryInterface(config) { return this.each(function () { - const data = ScrollSpy.getInstance(this) || new ScrollSpy(this, typeof config === 'object' ? config : {}); + const data = ScrollSpy.getOrCreateInstance(this, config); if (typeof config !== 'string') { return; @@ -6273,7 +6300,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): tab.js + * Bootstrap (v5.0.2): tab.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -6428,7 +6455,7 @@ static jQueryInterface(config) { return this.each(function () { - const data = Data.get(this, DATA_KEY$1) || new Tab(this); + const data = Tab.getOrCreateInstance(this); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -6457,7 +6484,7 @@ return; } - const data = Data.get(this, DATA_KEY$1) || new Tab(this); + const data = Tab.getOrCreateInstance(this); data.show(); }); /** @@ -6471,7 +6498,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): toast.js + * Bootstrap (v5.0.2): toast.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -6671,13 +6698,7 @@ static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY); - - const _config = typeof config === 'object' && config; - - if (!data) { - data = new Toast(this, _config); - } + const data = Toast.getOrCreateInstance(this, config); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { @@ -6702,7 +6723,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): index.umd.js + * Bootstrap (v5.0.2): index.umd.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ |