assets/javascripts/bootstrap.js in bootstrap-5.0.0 vs assets/javascripts/bootstrap.js in bootstrap-5.0.1

- old
+ new

@@ -1,7 +1,7 @@ /*! - * Bootstrap v5.0.0 (https://getbootstrap.com/) + * Bootstrap v5.0.1 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core')) : @@ -31,14 +31,86 @@ var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): util/index.js + * Bootstrap (v5.0.1): dom/selector-engine.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ + + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ + const NODE_TEXT = 3; + const SelectorEngine = { + find(selector, element = document.documentElement) { + return [].concat(...Element.prototype.querySelectorAll.call(element, selector)); + }, + + findOne(selector, element = document.documentElement) { + return Element.prototype.querySelector.call(element, selector); + }, + + children(element, selector) { + return [].concat(...element.children).filter(child => child.matches(selector)); + }, + + parents(element, selector) { + const parents = []; + let ancestor = element.parentNode; + + while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) { + if (ancestor.matches(selector)) { + parents.push(ancestor); + } + + ancestor = ancestor.parentNode; + } + + return parents; + }, + + prev(element, selector) { + let previous = element.previousElementSibling; + + while (previous) { + if (previous.matches(selector)) { + return [previous]; + } + + previous = previous.previousElementSibling; + } + + return []; + }, + + next(element, selector) { + let next = element.nextElementSibling; + + while (next) { + if (next.matches(selector)) { + return [next]; + } + + next = next.nextElementSibling; + } + + return []; + } + + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.0.1): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + const MAX_UID = 1000000; const MILLISECONDS_MULTIPLIER = 1000; const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp) const toType = obj => { @@ -127,12 +199,35 @@ const triggerTransitionEnd = element => { element.dispatchEvent(new Event(TRANSITION_END)); }; - const isElement = obj => (obj[0] || obj).nodeType; + const isElement = obj => { + if (!obj || typeof obj !== 'object') { + return false; + } + if (typeof obj.jquery !== 'undefined') { + obj = obj[0]; + } + + return typeof obj.nodeType !== 'undefined'; + }; + + const getElement = obj => { + if (isElement(obj)) { + // it's a jQuery object or a node element + return obj.jquery ? obj[0] : obj; + } + + if (typeof obj === 'string' && obj.length > 0) { + return SelectorEngine.findOne(obj); + } + + return null; + }; + const emulateTransitionEnd = (element, duration) => { let called = false; const durationPadding = 5; const emulatedDuration = duration + durationPadding; @@ -238,16 +333,17 @@ } }; const isRTL = () => document.documentElement.dir === 'rtl'; - const defineJQueryPlugin = (name, plugin) => { + const defineJQueryPlugin = plugin => { onDOMContentLoaded(() => { const $ = getjQuery(); /* istanbul ignore if */ if ($) { + const name = plugin.NAME; const JQUERY_NO_CONFLICT = $.fn[name]; $.fn[name] = plugin.jQueryInterface; $.fn[name].Constructor = plugin; $.fn[name].noConflict = () => { @@ -264,11 +360,11 @@ } }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): dom/data.js + * Bootstrap (v5.0.1): dom/data.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** @@ -318,11 +414,11 @@ }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): dom/event-handler.js + * Bootstrap (v5.0.1): dom/event-handler.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -607,25 +703,25 @@ }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): base-component.js + * Bootstrap (v5.0.1): base-component.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ - const VERSION = '5.0.0'; + const VERSION = '5.0.1'; class BaseComponent { constructor(element) { - element = typeof element === 'string' ? document.querySelector(element) : element; + element = getElement(element); if (!element) { return; } @@ -633,13 +729,26 @@ Data.set(this._element, this.constructor.DATA_KEY, this); } dispose() { Data.remove(this._element, this.constructor.DATA_KEY); - EventHandler.off(this._element, `.${this.constructor.DATA_KEY}`); - this._element = null; + EventHandler.off(this._element, this.constructor.EVENT_KEY); + Object.getOwnPropertyNames(this).forEach(propertyName => { + this[propertyName] = null; + }); } + + _queueCallback(callback, element, isAnimated = true) { + if (!isAnimated) { + execute(callback); + return; + } + + const transitionDuration = getTransitionDurationFromElement(element); + EventHandler.one(element, 'transitionend', () => execute(callback)); + emulateTransitionEnd(element, transitionDuration); + } /** Static */ static getInstance(element) { return Data.get(element, this.DATA_KEY); @@ -647,15 +756,27 @@ static get VERSION() { return VERSION; } + static get NAME() { + throw new Error('You have to implement the static method "NAME", for each component!'); + } + + static get DATA_KEY() { + return `bs.${this.NAME}`; + } + + static get EVENT_KEY() { + return `.${this.DATA_KEY}`; + } + } /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): alert.js + * Bootstrap (v5.0.1): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -680,12 +801,12 @@ * ------------------------------------------------------------------------ */ class Alert extends BaseComponent { // Getters - static get DATA_KEY() { - return DATA_KEY$b; + static get NAME() { + return NAME$c; } // Public close(element) { const rootElement = element ? this._getRootElement(element) : this._element; @@ -708,20 +829,13 @@ return EventHandler.trigger(element, EVENT_CLOSE); } _removeElement(element) { element.classList.remove(CLASS_NAME_SHOW$9); + const isAnimated = element.classList.contains(CLASS_NAME_FADE$6); - if (!element.classList.contains(CLASS_NAME_FADE$6)) { - this._destroyElement(element); - - return; - } - - const transitionDuration = getTransitionDurationFromElement(element); - EventHandler.one(element, 'transitionend', () => this._destroyElement(element)); - emulateTransitionEnd(element, transitionDuration); + this._queueCallback(() => this._destroyElement(element), element, isAnimated); } _destroyElement(element) { if (element.parentNode) { element.parentNode.removeChild(element); @@ -769,15 +883,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Alert to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$c, Alert); + defineJQueryPlugin(Alert); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): button.js + * Bootstrap (v5.0.1): button.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -798,12 +912,12 @@ * ------------------------------------------------------------------------ */ class Button extends BaseComponent { // Getters - static get DATA_KEY() { - return DATA_KEY$a; + static get NAME() { + return NAME$b; } // Public toggle() { // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method @@ -849,15 +963,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Button to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$b, Button); + defineJQueryPlugin(Button); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): dom/manipulator.js + * Bootstrap (v5.0.1): dom/manipulator.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ function normalizeData(val) { if (val === 'true') { @@ -927,91 +1041,20 @@ }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): dom/selector-engine.js + * Bootstrap (v5.0.1): carousel.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ - /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ - const NODE_TEXT = 3; - const SelectorEngine = { - find(selector, element = document.documentElement) { - return [].concat(...Element.prototype.querySelectorAll.call(element, selector)); - }, - findOne(selector, element = document.documentElement) { - return Element.prototype.querySelector.call(element, selector); - }, - - children(element, selector) { - return [].concat(...element.children).filter(child => child.matches(selector)); - }, - - parents(element, selector) { - const parents = []; - let ancestor = element.parentNode; - - while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) { - if (ancestor.matches(selector)) { - parents.push(ancestor); - } - - ancestor = ancestor.parentNode; - } - - return parents; - }, - - prev(element, selector) { - let previous = element.previousElementSibling; - - while (previous) { - if (previous.matches(selector)) { - return [previous]; - } - - previous = previous.previousElementSibling; - } - - return []; - }, - - next(element, selector) { - let next = element.nextElementSibling; - - while (next) { - if (next.matches(selector)) { - return [next]; - } - - next = next.nextElementSibling; - } - - return []; - } - - }; - - /** - * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): carousel.js - * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) - * -------------------------------------------------------------------------- - */ - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ - const NAME$a = 'carousel'; const DATA_KEY$9 = 'bs.carousel'; const EVENT_KEY$9 = `.${DATA_KEY$9}`; const DATA_API_KEY$6 = '.data-api'; const ARROW_LEFT_KEY = 'ArrowLeft'; @@ -1099,12 +1142,12 @@ static get Default() { return Default$9; } - static get DATA_KEY() { - return DATA_KEY$9; + static get NAME() { + return NAME$a; } // Public next() { if (!this._isSliding) { @@ -1178,21 +1221,10 @@ } const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV; this._slide(order, this._items[index]); - } - - dispose() { - this._items = null; - this._config = null; - this._interval = null; - this._isPaused = null; - this._isSliding = null; - this._activeElement = null; - this._indicatorsElement = null; - super.dispose(); } // Private _getConfig(config) { config = { ...Default$9, @@ -1417,41 +1449,39 @@ this._setActiveIndicatorElement(nextElement); this._activeElement = nextElement; + const triggerSlidEvent = () => { + EventHandler.trigger(this._element, EVENT_SLID, { + relatedTarget: nextElement, + direction: eventDirectionName, + from: activeElementIndex, + to: nextElementIndex + }); + }; + if (this._element.classList.contains(CLASS_NAME_SLIDE)) { nextElement.classList.add(orderClassName); reflow(nextElement); activeElement.classList.add(directionalClassName); nextElement.classList.add(directionalClassName); - const transitionDuration = getTransitionDurationFromElement(activeElement); - EventHandler.one(activeElement, 'transitionend', () => { + + const completeCallBack = () => { nextElement.classList.remove(directionalClassName, orderClassName); nextElement.classList.add(CLASS_NAME_ACTIVE$2); activeElement.classList.remove(CLASS_NAME_ACTIVE$2, orderClassName, directionalClassName); this._isSliding = false; - setTimeout(() => { - EventHandler.trigger(this._element, EVENT_SLID, { - relatedTarget: nextElement, - direction: eventDirectionName, - from: activeElementIndex, - to: nextElementIndex - }); - }, 0); - }); - emulateTransitionEnd(activeElement, transitionDuration); + setTimeout(triggerSlidEvent, 0); + }; + + this._queueCallback(completeCallBack, activeElement, true); } else { activeElement.classList.remove(CLASS_NAME_ACTIVE$2); nextElement.classList.add(CLASS_NAME_ACTIVE$2); this._isSliding = false; - EventHandler.trigger(this._element, EVENT_SLID, { - relatedTarget: nextElement, - direction: eventDirectionName, - from: activeElementIndex, - to: nextElementIndex - }); + triggerSlidEvent(); } if (isCycling) { this.cycle(); } @@ -1566,15 +1596,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Carousel to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$a, Carousel); + defineJQueryPlugin(Carousel); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): collapse.js + * Bootstrap (v5.0.1): collapse.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -1647,12 +1677,12 @@ static get Default() { return Default$8; } - static get DATA_KEY() { - return DATA_KEY$8; + static get NAME() { + return NAME$9; } // Public toggle() { if (this._element.classList.contains(CLASS_NAME_SHOW$8)) { @@ -1740,13 +1770,13 @@ EventHandler.trigger(this._element, EVENT_SHOWN$5); }; const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1); const scrollSize = `scroll${capitalizedDimension}`; - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', complete); - emulateTransitionEnd(this._element, transitionDuration); + + this._queueCallback(complete, this._element, true); + this._element.style[dimension] = `${this._element[scrollSize]}px`; } hide() { if (this._isTransitioning || !this._element.classList.contains(CLASS_NAME_SHOW$8)) { @@ -1793,25 +1823,16 @@ EventHandler.trigger(this._element, EVENT_HIDDEN$5); }; this._element.style[dimension] = ''; - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', complete); - emulateTransitionEnd(this._element, transitionDuration); + + this._queueCallback(complete, this._element, true); } setTransitioning(isTransitioning) { this._isTransitioning = isTransitioning; - } - - dispose() { - super.dispose(); - this._config = null; - this._parent = null; - this._triggerArray = null; - this._isTransitioning = null; } // Private _getConfig(config) { config = { ...Default$8, @@ -1829,20 +1850,11 @@ _getParent() { let { parent } = this._config; - - if (isElement(parent)) { - // it's a jQuery object - if (typeof parent.jquery !== 'undefined' || typeof parent[0] !== 'undefined') { - parent = parent[0]; - } - } else { - parent = SelectorEngine.findOne(parent); - } - + parent = getElement(parent); const selector = `${SELECTOR_DATA_TOGGLE$4}[data-bs-parent="${parent}"]`; SelectorEngine.find(selector, parent).forEach(element => { const selected = getElementFromSelector(element); this._addAriaAndCollapsedClass(selected, [element]); @@ -1939,15 +1951,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Collapse to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$9, Collapse); + defineJQueryPlugin(Collapse); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): dropdown.js + * Bootstrap (v5.0.1): dropdown.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -2030,12 +2042,12 @@ static get DefaultType() { return DefaultType$7; } - static get DATA_KEY() { - return DATA_KEY$7; + static get NAME() { + return NAME$8; } // Public toggle() { if (isDisabled(this._element)) { @@ -2078,15 +2090,11 @@ let referenceElement = this._element; if (this._config.reference === 'parent') { referenceElement = parent; } else if (isElement(this._config.reference)) { - referenceElement = this._config.reference; // Check if it's jQuery element - - if (typeof this._config.reference.jquery !== 'undefined') { - referenceElement = this._config.reference[0]; - } + referenceElement = getElement(this._config.reference); } else if (typeof this._config.reference === 'object') { referenceElement = this._config.reference; } const popperConfig = this._getPopperConfig(); @@ -2129,16 +2137,12 @@ this._completeHide(relatedTarget); } dispose() { - this._menu = null; - if (this._popper) { this._popper.destroy(); - - this._popper = null; } super.dispose(); } @@ -2320,18 +2324,12 @@ Dropdown.dropdownInterface(this, config); }); } static clearMenus(event) { - if (event) { - if (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY) { - return; - } - - if (/input|select|option|textarea|form/i.test(event.target.tagName)) { - return; - } + if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) { + return; } const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE$3); for (let i = 0, len = toggles.length; i < len; i++) { @@ -2353,14 +2351,14 @@ const composedPath = event.composedPath(); const isMenuTarget = composedPath.includes(context._menu); if (composedPath.includes(context._element) || context._config.autoClose === 'inside' && !isMenuTarget || context._config.autoClose === 'outside' && isMenuTarget) { continue; - } // Tab navigation through the dropdown menu shouldn't close the menu + } // Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu - if (event.type === 'keyup' && event.key === TAB_KEY && context._menu.contains(event.target)) { + if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) { continue; } if (event.type === 'click') { relatedTarget.clickEvent = event; @@ -2442,15 +2440,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Dropdown to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$8, Dropdown); + defineJQueryPlugin(Dropdown); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): util/scrollBar.js + * Bootstrap (v5.0.1): 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'; @@ -2520,11 +2518,11 @@ }); }; /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): util/backdrop.js + * Bootstrap (v5.0.1): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ const Default$6 = { isVisible: true, @@ -2604,10 +2602,11 @@ _getConfig(config) { config = { ...Default$6, ...(typeof config === 'object' ? config : {}) }; + config.rootElement = config.rootElement || document.body; typeCheckConfig(NAME$7, config, DefaultType$6); return config; } _append() { @@ -2648,11 +2647,11 @@ } /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): modal.js + * Bootstrap (v5.0.1): modal.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -2678,11 +2677,11 @@ const EVENT_HIDE$3 = `hide${EVENT_KEY$6}`; const EVENT_HIDE_PREVENTED = `hidePrevented${EVENT_KEY$6}`; const EVENT_HIDDEN$3 = `hidden${EVENT_KEY$6}`; const EVENT_SHOW$3 = `show${EVENT_KEY$6}`; const EVENT_SHOWN$3 = `shown${EVENT_KEY$6}`; - const EVENT_FOCUSIN$1 = `focusin${EVENT_KEY$6}`; + const EVENT_FOCUSIN$2 = `focusin${EVENT_KEY$6}`; const EVENT_RESIZE = `resize${EVENT_KEY$6}`; const EVENT_CLICK_DISMISS$2 = `click.dismiss${EVENT_KEY$6}`; const EVENT_KEYDOWN_DISMISS$1 = `keydown.dismiss${EVENT_KEY$6}`; const EVENT_MOUSEUP_DISMISS = `mouseup.dismiss${EVENT_KEY$6}`; const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY$6}`; @@ -2715,12 +2714,12 @@ static get Default() { return Default$5; } - static get DATA_KEY() { - return DATA_KEY$6; + static get NAME() { + return NAME$6; } // Public toggle(relatedTarget) { return this._isShown ? this.hide() : this.show(relatedTarget); @@ -2790,45 +2789,33 @@ this._setEscapeEvent(); this._setResizeEvent(); - EventHandler.off(document, EVENT_FOCUSIN$1); + EventHandler.off(document, EVENT_FOCUSIN$2); this._element.classList.remove(CLASS_NAME_SHOW$5); EventHandler.off(this._element, EVENT_CLICK_DISMISS$2); EventHandler.off(this._dialog, EVENT_MOUSEDOWN_DISMISS); - if (isAnimated) { - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', event => this._hideModal(event)); - emulateTransitionEnd(this._element, transitionDuration); - } else { - this._hideModal(); - } + this._queueCallback(() => this._hideModal(), this._element, isAnimated); } dispose() { [window, this._dialog].forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY$6)); + + this._backdrop.dispose(); + super.dispose(); /** * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API` * Do not move `document` in `htmlElements` array * It will remove `EVENT_CLICK_DATA_API` event that should remain */ - EventHandler.off(document, EVENT_FOCUSIN$1); - this._config = null; - this._dialog = null; - - this._backdrop.dispose(); - - this._backdrop = null; - this._isShown = null; - this._ignoreBackdropClick = null; - this._isTransitioning = null; + EventHandler.off(document, EVENT_FOCUSIN$2); } handleUpdate() { this._adjustDialog(); } // Private @@ -2894,23 +2881,17 @@ EventHandler.trigger(this._element, EVENT_SHOWN$3, { relatedTarget }); }; - if (isAnimated) { - const transitionDuration = getTransitionDurationFromElement(this._dialog); - EventHandler.one(this._dialog, 'transitionend', transitionComplete); - emulateTransitionEnd(this._dialog, transitionDuration); - } else { - transitionComplete(); - } + this._queueCallback(transitionComplete, this._dialog, isAnimated); } _enforceFocus() { - EventHandler.off(document, EVENT_FOCUSIN$1); // guard against infinite focus loop + EventHandler.off(document, EVENT_FOCUSIN$2); // guard against infinite focus loop - EventHandler.on(document, EVENT_FOCUSIN$1, event => { + EventHandler.on(document, EVENT_FOCUSIN$2, event => { if (document !== event.target && this._element !== event.target && !this._element.contains(event.target)) { this._element.focus(); } }); } @@ -3090,15 +3071,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Modal to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$6, Modal); + defineJQueryPlugin(Modal); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): offcanvas.js + * Bootstrap (v5.0.1): offcanvas.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -3126,11 +3107,11 @@ const OPEN_SELECTOR = '.offcanvas.show'; const EVENT_SHOW$2 = `show${EVENT_KEY$5}`; const EVENT_SHOWN$2 = `shown${EVENT_KEY$5}`; const EVENT_HIDE$2 = `hide${EVENT_KEY$5}`; const EVENT_HIDDEN$2 = `hidden${EVENT_KEY$5}`; - const EVENT_FOCUSIN = `focusin${EVENT_KEY$5}`; + const EVENT_FOCUSIN$1 = `focusin${EVENT_KEY$5}`; const EVENT_CLICK_DATA_API$1 = `click${EVENT_KEY$5}${DATA_API_KEY$2}`; const EVENT_CLICK_DISMISS$1 = `click.dismiss${EVENT_KEY$5}`; const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY$5}`; const SELECTOR_DATA_DISMISS$1 = '[data-bs-dismiss="offcanvas"]'; const SELECTOR_DATA_TOGGLE$1 = '[data-bs-toggle="offcanvas"]'; @@ -3149,16 +3130,16 @@ this._addEventListeners(); } // Getters - static get Default() { - return Default$4; + static get NAME() { + return NAME$5; } - static get DATA_KEY() { - return DATA_KEY$5; + static get Default() { + return Default$4; } // Public toggle(relatedTarget) { return this._isShown ? this.hide() : this.show(relatedTarget); @@ -3200,13 +3181,11 @@ EventHandler.trigger(this._element, EVENT_SHOWN$2, { relatedTarget }); }; - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', completeCallBack); - emulateTransitionEnd(this._element, transitionDuration); + this._queueCallback(completeCallBack, this._element, true); } hide() { if (!this._isShown) { return; @@ -3216,11 +3195,11 @@ if (hideEvent.defaultPrevented) { return; } - EventHandler.off(document, EVENT_FOCUSIN); + EventHandler.off(document, EVENT_FOCUSIN$1); this._element.blur(); this._isShown = false; @@ -3242,22 +3221,18 @@ } EventHandler.trigger(this._element, EVENT_HIDDEN$2); }; - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', completeCallback); - emulateTransitionEnd(this._element, transitionDuration); + this._queueCallback(completeCallback, this._element, true); } dispose() { this._backdrop.dispose(); super.dispose(); - EventHandler.off(document, EVENT_FOCUSIN); - this._config = null; - this._backdrop = null; + EventHandler.off(document, EVENT_FOCUSIN$1); } // Private _getConfig(config) { config = { ...Default$4, @@ -3276,13 +3251,13 @@ clickCallback: () => this.hide() }); } _enforceFocusOnElement(element) { - EventHandler.off(document, EVENT_FOCUSIN); // guard against infinite focus loop + EventHandler.off(document, EVENT_FOCUSIN$1); // guard against infinite focus loop - EventHandler.on(document, EVENT_FOCUSIN, event => { + EventHandler.on(document, EVENT_FOCUSIN$1, event => { if (document !== event.target && element !== event.target && !element.contains(event.target)) { element.focus(); } }); element.focus(); @@ -3356,15 +3331,15 @@ * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - defineJQueryPlugin(NAME$5, Offcanvas); + defineJQueryPlugin(Offcanvas); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): util/sanitizer.js + * Bootstrap (v5.0.1): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ const uriAttrs = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']); const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i; @@ -3473,11 +3448,11 @@ return createdDocument.body.innerHTML; } /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): tooltip.js + * Bootstrap (v5.0.1): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -3576,11 +3551,11 @@ this._timeout = 0; this._hoverState = ''; this._activeTrigger = {}; this._popper = null; // Protected - this.config = this._getConfig(config); + this._config = this._getConfig(config); this.tip = null; this._setListeners(); } // Getters @@ -3591,22 +3566,14 @@ static get NAME() { return NAME$4; } - static get DATA_KEY() { - return DATA_KEY$4; - } - static get Event() { return Event$2; } - static get EVENT_KEY() { - return EVENT_KEY$4; - } - static get DefaultType() { return DefaultType$3; } // Public @@ -3654,22 +3621,14 @@ if (this.tip && this.tip.parentNode) { this.tip.parentNode.removeChild(this.tip); } - this._isEnabled = null; - this._timeout = null; - this._hoverState = null; - this._activeTrigger = null; - if (this._popper) { this._popper.destroy(); } - this._popper = null; - this.config = null; - this.tip = null; super.dispose(); } show() { if (this._element.style.display === 'none') { @@ -3694,22 +3653,23 @@ this._element.setAttribute('aria-describedby', tipId); this.setContent(); - if (this.config.animation) { + if (this._config.animation) { tip.classList.add(CLASS_NAME_FADE$3); } - const placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this._element) : this.config.placement; + const placement = typeof this._config.placement === 'function' ? this._config.placement.call(this, tip, this._element) : this._config.placement; const attachment = this._getAttachment(placement); this._addAttachmentClass(attachment); - const container = this._getContainer(); - + const { + container + } = this._config; Data.set(tip, this.constructor.DATA_KEY, this); if (!this._element.ownerDocument.documentElement.contains(this.tip)) { container.appendChild(tip); EventHandler.trigger(this._element, this.constructor.Event.INSERTED); @@ -3720,11 +3680,11 @@ } else { this._popper = Popper__namespace.createPopper(this._element, tip, this._getPopperConfig(attachment)); } tip.classList.add(CLASS_NAME_SHOW$3); - const customClass = typeof this.config.customClass === 'function' ? this.config.customClass() : this.config.customClass; + const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass; if (customClass) { tip.classList.add(...customClass.split(' ')); } // If this is a touch-enabled device we add extra // empty mouseover listeners to the body's immediate children; @@ -3746,17 +3706,13 @@ if (prevHoverState === HOVER_STATE_OUT) { this._leave(null, this); } }; - if (this.tip.classList.contains(CLASS_NAME_FADE$3)) { - const transitionDuration = getTransitionDurationFromElement(this.tip); - EventHandler.one(this.tip, 'transitionend', complete); - emulateTransitionEnd(this.tip, transitionDuration); - } else { - complete(); - } + const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE$3); + + this._queueCallback(complete, this.tip, isAnimated); } hide() { if (!this._popper) { return; @@ -3800,18 +3756,13 @@ } this._activeTrigger[TRIGGER_CLICK] = false; this._activeTrigger[TRIGGER_FOCUS] = false; this._activeTrigger[TRIGGER_HOVER] = false; + const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE$3); - if (this.tip.classList.contains(CLASS_NAME_FADE$3)) { - const transitionDuration = getTransitionDurationFromElement(tip); - EventHandler.one(tip, 'transitionend', complete); - emulateTransitionEnd(tip, transitionDuration); - } else { - complete(); - } + this._queueCallback(complete, this.tip, isAnimated); this._hoverState = ''; } update() { @@ -3829,11 +3780,11 @@ if (this.tip) { return this.tip; } const element = document.createElement('div'); - element.innerHTML = this.config.template; + element.innerHTML = this._config.template; this.tip = element.children[0]; return this.tip; } setContent() { @@ -3845,17 +3796,14 @@ setElementContent(element, content) { if (element === null) { return; } - if (typeof content === 'object' && isElement(content)) { - if (content.jquery) { - content = content[0]; - } // content is a DOM node or a jQuery + if (isElement(content)) { + content = getElement(content); // content is a DOM node or a jQuery - - if (this.config.html) { + if (this._config.html) { if (content.parentNode !== element) { element.innerHTML = ''; element.appendChild(content); } } else { @@ -3863,13 +3811,13 @@ } return; } - if (this.config.html) { - if (this.config.sanitize) { - content = sanitizeHtml(content, this.config.allowList, this.config.sanitizeFn); + if (this._config.html) { + if (this._config.sanitize) { + content = sanitizeHtml(content, this._config.allowList, this._config.sanitizeFn); } element.innerHTML = content; } else { element.textContent = content; @@ -3878,11 +3826,11 @@ getTitle() { let title = this._element.getAttribute('data-bs-original-title'); if (!title) { - title = typeof this.config.title === 'function' ? this.config.title.call(this._element) : this.config.title; + title = typeof this._config.title === 'function' ? this._config.title.call(this._element) : this._config.title; } return title; } @@ -3912,11 +3860,11 @@ } _getOffset() { const { offset - } = this.config; + } = this._config; if (typeof offset === 'string') { return offset.split(',').map(val => Number.parseInt(val, 10)); } @@ -3931,21 +3879,21 @@ const defaultBsPopperConfig = { placement: attachment, modifiers: [{ name: 'flip', options: { - fallbackPlacements: this.config.fallbackPlacements + fallbackPlacements: this._config.fallbackPlacements } }, { name: 'offset', options: { offset: this._getOffset() } }, { name: 'preventOverflow', options: { - boundary: this.config.boundary + boundary: this._config.boundary } }, { name: 'arrow', options: { element: `.${this.constructor.NAME}-arrow` @@ -3961,44 +3909,33 @@ this._handlePopperPlacementChange(data); } } }; return { ...defaultBsPopperConfig, - ...(typeof this.config.popperConfig === 'function' ? this.config.popperConfig(defaultBsPopperConfig) : this.config.popperConfig) + ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig) }; } _addAttachmentClass(attachment) { this.getTipElement().classList.add(`${CLASS_PREFIX$1}-${this.updateAttachment(attachment)}`); } - _getContainer() { - if (this.config.container === false) { - return document.body; - } - - if (isElement(this.config.container)) { - return this.config.container; - } - - return SelectorEngine.findOne(this.config.container); - } - _getAttachment(placement) { return AttachmentMap[placement.toUpperCase()]; } _setListeners() { - const triggers = this.config.trigger.split(' '); + const triggers = this._config.trigger.split(' '); + triggers.forEach(trigger => { if (trigger === 'click') { - EventHandler.on(this._element, this.constructor.Event.CLICK, this.config.selector, event => this.toggle(event)); + EventHandler.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event)); } else if (trigger !== TRIGGER_MANUAL) { const eventIn = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSEENTER : this.constructor.Event.FOCUSIN; const eventOut = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSELEAVE : this.constructor.Event.FOCUSOUT; - EventHandler.on(this._element, eventIn, this.config.selector, event => this._enter(event)); - EventHandler.on(this._element, eventOut, this.config.selector, event => this._leave(event)); + EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event)); + EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event)); } }); this._hideModalHandler = () => { if (this._element) { @@ -4006,12 +3943,12 @@ } }; EventHandler.on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler); - if (this.config.selector) { - this.config = { ...this.config, + if (this._config.selector) { + this._config = { ...this._config, trigger: 'manual', selector: '' }; } else { this._fixTitle(); @@ -4047,20 +3984,20 @@ } clearTimeout(context._timeout); context._hoverState = HOVER_STATE_SHOW; - if (!context.config.delay || !context.config.delay.show) { + if (!context._config.delay || !context._config.delay.show) { context.show(); return; } context._timeout = setTimeout(() => { if (context._hoverState === HOVER_STATE_SHOW) { context.show(); } - }, context.config.delay.show); + }, context._config.delay.show); } _leave(event, context) { context = this._initializeOnDelegatedTarget(event, context); @@ -4073,20 +4010,20 @@ } clearTimeout(context._timeout); context._hoverState = HOVER_STATE_OUT; - if (!context.config.delay || !context.config.delay.hide) { + if (!context._config.delay || !context._config.delay.hide) { context.hide(); return; } context._timeout = setTimeout(() => { if (context._hoverState === HOVER_STATE_OUT) { context.hide(); } - }, context.config.delay.hide); + }, context._config.delay.hide); } _isWithActiveTrigger() { for (const trigger in this._activeTrigger) { if (this._activeTrigger[trigger]) { @@ -4102,19 +4039,15 @@ Object.keys(dataAttributes).forEach(dataAttr => { if (DISALLOWED_ATTRIBUTES.has(dataAttr)) { delete dataAttributes[dataAttr]; } }); - - if (config && typeof config.container === 'object' && config.container.jquery) { - config.container = config.container[0]; - } - config = { ...this.constructor.Default, ...dataAttributes, ...(typeof config === 'object' && config ? config : {}) }; + config.container = config.container === false ? document.body : getElement(config.container); if (typeof config.delay === 'number') { config.delay = { show: config.delay, hide: config.delay @@ -4139,14 +4072,14 @@ } _getDelegateConfig() { const config = {}; - if (this.config) { - for (const key in this.config) { - if (this.constructor.Default[key] !== this.config[key]) { - config[key] = this.config[key]; + if (this._config) { + for (const key in this._config) { + if (this.constructor.Default[key] !== this._config[key]) { + config[key] = this._config[key]; } } } return config; @@ -4209,15 +4142,15 @@ * ------------------------------------------------------------------------ * add .Tooltip to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$4, Tooltip); + defineJQueryPlugin(Tooltip); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): popover.js + * Bootstrap (v5.0.1): popover.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -4270,22 +4203,14 @@ static get NAME() { return NAME$3; } - static get DATA_KEY() { - return DATA_KEY$3; - } - static get Event() { return Event$1; } - static get EVENT_KEY() { - return EVENT_KEY$3; - } - static get DefaultType() { return DefaultType$2; } // Overrides @@ -4312,11 +4237,11 @@ _addAttachmentClass(attachment) { this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`); } _getContent() { - return this._element.getAttribute('data-bs-content') || this.config.content; + return this._element.getAttribute('data-bs-content') || this._config.content; } _cleanTipClass() { const tip = this.getTipElement(); const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX); @@ -4359,15 +4284,15 @@ * ------------------------------------------------------------------------ * add .Popover to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$3, Popover); + defineJQueryPlugin(Popover); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): scrollspy.js + * Bootstrap (v5.0.1): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -4428,12 +4353,12 @@ static get Default() { return Default$1; } - static get DATA_KEY() { - return DATA_KEY$2; + static get NAME() { + return NAME$2; } // Public refresh() { const autoMethod = this._scrollElement === this._scrollElement.window ? METHOD_OFFSET : METHOD_POSITION; @@ -4462,19 +4387,12 @@ this._targets.push(item[1]); }); } dispose() { - super.dispose(); EventHandler.off(this._scrollElement, EVENT_KEY$2); - this._scrollElement = null; - this._config = null; - this._selector = null; - this._offsets = null; - this._targets = null; - this._activeTarget = null; - this._scrollHeight = null; + super.dispose(); } // Private _getConfig(config) { config = { ...Default$1, @@ -4617,15 +4535,15 @@ * jQuery * ------------------------------------------------------------------------ * add .ScrollSpy to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$2, ScrollSpy); + defineJQueryPlugin(ScrollSpy); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): tab.js + * Bootstrap (v5.0.1): tab.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -4659,12 +4577,12 @@ * ------------------------------------------------------------------------ */ class Tab extends BaseComponent { // Getters - static get DATA_KEY() { - return DATA_KEY$1; + static get NAME() { + return NAME$1; } // Public show() { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(CLASS_NAME_ACTIVE)) { @@ -4718,14 +4636,13 @@ const isTransitioning = callback && active && active.classList.contains(CLASS_NAME_FADE$1); const complete = () => this._transitionComplete(element, active, callback); if (active && isTransitioning) { - const transitionDuration = getTransitionDurationFromElement(active); active.classList.remove(CLASS_NAME_SHOW$1); - EventHandler.one(active, 'transitionend', complete); - emulateTransitionEnd(active, transitionDuration); + + this._queueCallback(complete, element, true); } else { complete(); } } @@ -4816,15 +4733,15 @@ * jQuery * ------------------------------------------------------------------------ * add .Tab to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME$1, Tab); + defineJQueryPlugin(Tab); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): toast.js + * Bootstrap (v5.0.1): toast.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------ @@ -4834,10 +4751,14 @@ const NAME = 'toast'; const DATA_KEY = 'bs.toast'; const EVENT_KEY = `.${DATA_KEY}`; const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`; + const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`; + const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`; + const EVENT_FOCUSIN = `focusin${EVENT_KEY}`; + const EVENT_FOCUSOUT = `focusout${EVENT_KEY}`; const EVENT_HIDE = `hide${EVENT_KEY}`; const EVENT_HIDDEN = `hidden${EVENT_KEY}`; const EVENT_SHOW = `show${EVENT_KEY}`; const EVENT_SHOWN = `shown${EVENT_KEY}`; const CLASS_NAME_FADE = 'fade'; @@ -4864,10 +4785,12 @@ class Toast extends BaseComponent { constructor(element, config) { super(element); this._config = this._getConfig(config); this._timeout = null; + this._hasMouseInteraction = false; + this._hasKeyboardInteraction = false; this._setListeners(); } // Getters @@ -4877,12 +4800,12 @@ static get Default() { return Default; } - static get DATA_KEY() { - return DATA_KEY; + static get NAME() { + return NAME; } // Public show() { const showEvent = EventHandler.trigger(this._element, EVENT_SHOW); @@ -4902,30 +4825,20 @@ this._element.classList.add(CLASS_NAME_SHOW); EventHandler.trigger(this._element, EVENT_SHOWN); - if (this._config.autohide) { - this._timeout = setTimeout(() => { - this.hide(); - }, this._config.delay); - } + this._maybeScheduleHide(); }; this._element.classList.remove(CLASS_NAME_HIDE); reflow(this._element); this._element.classList.add(CLASS_NAME_SHOWING); - if (this._config.animation) { - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', complete); - emulateTransitionEnd(this._element, transitionDuration); - } else { - complete(); - } + this._queueCallback(complete, this._element, this._config.animation); } hide() { if (!this._element.classList.contains(CLASS_NAME_SHOW)) { return; @@ -4943,28 +4856,21 @@ EventHandler.trigger(this._element, EVENT_HIDDEN); }; this._element.classList.remove(CLASS_NAME_SHOW); - if (this._config.animation) { - const transitionDuration = getTransitionDurationFromElement(this._element); - EventHandler.one(this._element, 'transitionend', complete); - emulateTransitionEnd(this._element, transitionDuration); - } else { - complete(); - } + this._queueCallback(complete, this._element, this._config.animation); } dispose() { this._clearTimeout(); if (this._element.classList.contains(CLASS_NAME_SHOW)) { this._element.classList.remove(CLASS_NAME_SHOW); } super.dispose(); - this._config = null; } // Private _getConfig(config) { config = { ...Default, @@ -4973,12 +4879,58 @@ }; typeCheckConfig(NAME, config, this.constructor.DefaultType); return config; } + _maybeScheduleHide() { + if (!this._config.autohide) { + return; + } + + if (this._hasMouseInteraction || this._hasKeyboardInteraction) { + return; + } + + this._timeout = setTimeout(() => { + this.hide(); + }, this._config.delay); + } + + _onInteraction(event, isInteracting) { + switch (event.type) { + case 'mouseover': + case 'mouseout': + this._hasMouseInteraction = isInteracting; + break; + + case 'focusin': + case 'focusout': + this._hasKeyboardInteraction = isInteracting; + break; + } + + if (isInteracting) { + this._clearTimeout(); + + return; + } + + const nextElement = event.relatedTarget; + + if (this._element === nextElement || this._element.contains(nextElement)) { + return; + } + + this._maybeScheduleHide(); + } + _setListeners() { EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide()); + EventHandler.on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true)); + EventHandler.on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false)); + EventHandler.on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true)); + EventHandler.on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false)); } _clearTimeout() { clearTimeout(this._timeout); this._timeout = null; @@ -5012,14 +4964,14 @@ * ------------------------------------------------------------------------ * add .Toast to jQuery only if jQuery is present */ - defineJQueryPlugin(NAME, Toast); + defineJQueryPlugin(Toast); /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): index.umd.js + * Bootstrap (v5.0.1): index.umd.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ var index_umd = { Alert,