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.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.js')
-rw-r--r-- | vendor/twbs/bootstrap/dist/js/bootstrap.js | 643 |
1 files changed, 332 insertions, 311 deletions
diff --git a/vendor/twbs/bootstrap/dist/js/bootstrap.js b/vendor/twbs/bootstrap/dist/js/bootstrap.js index ec15092b7..200fd9631 100644 --- a/vendor/twbs/bootstrap/dist/js/bootstrap.js +++ b/vendor/twbs/bootstrap/dist/js/bootstrap.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) */ @@ -33,7 +33,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) * -------------------------------------------------------------------------- */ @@ -104,7 +104,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) * -------------------------------------------------------------------------- */ @@ -226,24 +226,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]; @@ -257,17 +239,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 isDisabled = element => { @@ -325,9 +301,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(); } @@ -360,63 +345,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) * -------------------------------------------------------------------------- */ @@ -705,17 +693,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) { @@ -738,14 +780,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 */ @@ -754,6 +789,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; } @@ -774,7 +813,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): alert.js + * Bootstrap (v5.0.2): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -837,21 +876,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); @@ -889,7 +921,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): button.js + * Bootstrap (v5.0.2): button.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -927,11 +959,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](); @@ -950,12 +978,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(); }); /** @@ -969,7 +992,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) * -------------------------------------------------------------------------- */ @@ -1043,7 +1066,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): carousel.js + * Bootstrap (v5.0.2): carousel.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -1082,6 +1105,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}`; @@ -1150,9 +1177,7 @@ next() { - if (!this._isSliding) { - this._slide(ORDER_NEXT); - } + this._slide(ORDER_NEXT); } nextWhenVisible() { @@ -1164,9 +1189,7 @@ } prev() { - if (!this._isSliding) { - this._slide(ORDER_PREV); - } + this._slide(ORDER_PREV); } pause(event) { @@ -1228,7 +1251,8 @@ _getConfig(config) { config = { ...Default$9, - ...config + ...Manipulator.getDataAttributes(this._element), + ...(typeof config === 'object' ? config : {}) }; typeCheckConfig(NAME$a, config, DefaultType$9); return config; @@ -1326,14 +1350,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); } } @@ -1344,20 +1366,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) { @@ -1430,6 +1439,10 @@ return; } + if (this._isSliding) { + return; + } + const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName); if (slideEvent.defaultPrevented) { @@ -1513,10 +1526,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, @@ -1526,10 +1539,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') { @@ -1569,7 +1578,7 @@ Carousel.carouselInterface(target, config); if (slideIndex) { - Data.get(target, DATA_KEY$9).to(slideIndex); + Carousel.getInstance(target).to(slideIndex); } event.preventDefault(); @@ -1588,7 +1597,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])); } }); /** @@ -1602,7 +1611,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): collapse.js + * Bootstrap (v5.0.2): collapse.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -1718,7 +1727,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; @@ -1881,7 +1890,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 : {}) @@ -1928,7 +1937,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) { @@ -1957,7 +1966,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): dropdown.js + * Bootstrap (v5.0.2): dropdown.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -2277,38 +2286,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') { @@ -2333,7 +2328,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; @@ -2406,17 +2401,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); } } @@ -2446,81 +2443,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(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) * -------------------------------------------------------------------------- */ @@ -2528,14 +2555,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'; @@ -2603,8 +2630,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; } @@ -2629,27 +2657,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) * -------------------------------------------------------------------------- */ @@ -2709,6 +2730,7 @@ this._isShown = false; this._ignoreBackdropClick = false; this._isTransitioning = false; + this._scrollBar = new ScrollBarHelper(); } // Getters @@ -2730,20 +2752,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(); @@ -2765,7 +2789,7 @@ } hide(event) { - if (event) { + if (event && ['A', 'AREA'].includes(event.target.tagName)) { event.preventDefault(); } @@ -2832,7 +2856,7 @@ _getConfig(config) { config = { ...Default$5, ...Manipulator.getDataAttributes(this._element), - ...config + ...(typeof config === 'object' ? config : {}) }; typeCheckConfig(NAME$6, config, DefaultType$5); return config; @@ -2935,7 +2959,8 @@ this._resetAdjustments(); - reset(); + this._scrollBar.reset(); + EventHandler.trigger(this._element, EVENT_HIDDEN$3); }); } @@ -2972,27 +2997,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(); } // ---------------------------------------------------------------------- @@ -3002,7 +3032,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()) { @@ -3022,7 +3054,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; @@ -3063,7 +3095,7 @@ } }); }); - const data = Modal.getInstance(target) || new Modal(target); + const data = Modal.getOrCreateInstance(target); data.toggle(this); }); /** @@ -3077,7 +3109,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): offcanvas.js + * Bootstrap (v5.0.2): offcanvas.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ @@ -3164,7 +3196,7 @@ this._backdrop.show(); if (!this._config.scroll) { - hide(); + new ScrollBarHelper().hide(); this._enforceFocusOnElement(this._element); } @@ -3217,7 +3249,7 @@ this._element.style.visibility = 'hidden'; if (!this._config.scroll) { - reset(); + new ScrollBarHelper().reset(); } EventHandler.trigger(this._element, EVENT_HIDDEN$2); @@ -3275,7 +3307,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; @@ -3321,12 +3353,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 @@ -3337,7 +3367,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) * -------------------------------------------------------------------------- */ @@ -3432,7 +3462,7 @@ const elName = el.nodeName.toLowerCase(); if (!allowlistKeys.includes(elName)) { - el.parentNode.removeChild(el); + el.remove(); continue; } @@ -3450,7 +3480,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): tooltip.js + * Bootstrap (v5.0.2): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -3619,8 +3649,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) { @@ -3725,8 +3755,8 @@ return; } - if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { - tip.parentNode.removeChild(tip); + if (this._hoverState !== HOVER_STATE_SHOW) { + tip.remove(); } this._cleanTipClass(); @@ -4113,17 +4143,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') { @@ -4148,7 +4168,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): popover.js + * Bootstrap (v5.0.2): popover.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -4218,6 +4238,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 @@ -4254,18 +4292,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') { @@ -4290,7 +4317,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): scrollspy.js + * Bootstrap (v5.0.2): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -4505,7 +4532,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; @@ -4541,7 +4568,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): tab.js + * Bootstrap (v5.0.2): tab.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -4696,7 +4723,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') { @@ -4725,7 +4752,7 @@ return; } - const data = Data.get(this, DATA_KEY$1) || new Tab(this); + const data = Tab.getOrCreateInstance(this); data.show(); }); /** @@ -4739,7 +4766,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): toast.js + * Bootstrap (v5.0.2): toast.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -4939,13 +4966,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') { @@ -4970,7 +4991,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) * -------------------------------------------------------------------------- */ |