diff options
author | Mario <mario@mariovavti.com> | 2021-09-23 08:33:36 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-09-23 08:33:36 +0000 |
commit | a451449766d581978068a5b8f8c1e27f50386ea7 (patch) | |
tree | 17388d0d116d3c3a3e14745397b5b3278e933d74 /vendor/twbs/bootstrap/js/src/dropdown.js | |
parent | 3347fab105a01f38800a907e7d6281d835a29f5c (diff) | |
download | volse-hubzilla-a451449766d581978068a5b8f8c1e27f50386ea7.tar.gz volse-hubzilla-a451449766d581978068a5b8f8c1e27f50386ea7.tar.bz2 volse-hubzilla-a451449766d581978068a5b8f8c1e27f50386ea7.zip |
Revert "composer update bootstrap to version 5.1.1"
This reverts commit 89e4006b2d84d398e34d407a019854823b1dd37d.
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/dropdown.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/src/dropdown.js | 121 |
1 files changed, 68 insertions, 53 deletions
diff --git a/vendor/twbs/bootstrap/js/src/dropdown.js b/vendor/twbs/bootstrap/js/src/dropdown.js index 874cf907b..681369b48 100644 --- a/vendor/twbs/bootstrap/js/src/dropdown.js +++ b/vendor/twbs/bootstrap/js/src/dropdown.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.1): dropdown.js + * Bootstrap (v5.0.2): dropdown.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -11,12 +11,12 @@ import { defineJQueryPlugin, getElement, getElementFromSelector, - getNextActiveElement, isDisabled, isElement, - isRTL, isVisible, + isRTL, noop, + getNextActiveElement, typeCheckConfig } from './util/index' import EventHandler from './dom/event-handler' @@ -48,6 +48,7 @@ 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 EVENT_CLICK = `click${EVENT_KEY}` const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY}${DATA_API_KEY}` const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY}${DATA_API_KEY}` @@ -102,6 +103,8 @@ class Dropdown extends BaseComponent { this._config = this._getConfig(config) this._menu = this._getMenuElement() this._inNavbar = this._detectNavbar() + + this._addEventListeners() } // Getters @@ -121,14 +124,26 @@ class Dropdown extends BaseComponent { // Public toggle() { - return this._isShown() ? this.hide() : this.show() + if (isDisabled(this._element)) { + return + } + + const isActive = this._element.classList.contains(CLASS_NAME_SHOW) + + if (isActive) { + this.hide() + return + } + + this.show() } show() { - if (isDisabled(this._element) || this._isShown(this._menu)) { + if (isDisabled(this._element) || this._menu.classList.contains(CLASS_NAME_SHOW)) { return } + const parent = Dropdown.getParentFromElement(this._element) const relatedTarget = { relatedTarget: this._element } @@ -139,12 +154,32 @@ class Dropdown extends BaseComponent { return } - const parent = Dropdown.getParentFromElement(this._element) // Totally disable Popper for Dropdowns in Navbar if (this._inNavbar) { Manipulator.setDataAttribute(this._menu, 'popper', 'none') } else { - this._createPopper(parent) + if (typeof Popper === 'undefined') { + throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)') + } + + let referenceElement = this._element + + if (this._config.reference === 'parent') { + referenceElement = parent + } else if (isElement(this._config.reference)) { + referenceElement = getElement(this._config.reference) + } else if (typeof this._config.reference === 'object') { + referenceElement = this._config.reference + } + + const popperConfig = this._getPopperConfig() + const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false) + + this._popper = Popper.createPopper(referenceElement, this._menu, popperConfig) + + if (isDisplayStatic) { + Manipulator.setDataAttribute(this._menu, 'popper', 'static') + } } // If this is a touch-enabled device we add extra @@ -160,13 +195,13 @@ class Dropdown extends BaseComponent { this._element.focus() this._element.setAttribute('aria-expanded', true) - this._menu.classList.add(CLASS_NAME_SHOW) - this._element.classList.add(CLASS_NAME_SHOW) + this._menu.classList.toggle(CLASS_NAME_SHOW) + this._element.classList.toggle(CLASS_NAME_SHOW) EventHandler.trigger(this._element, EVENT_SHOWN, relatedTarget) } hide() { - if (isDisabled(this._element) || !this._isShown(this._menu)) { + if (isDisabled(this._element) || !this._menu.classList.contains(CLASS_NAME_SHOW)) { return } @@ -194,6 +229,13 @@ class Dropdown extends BaseComponent { // Private + _addEventListeners() { + EventHandler.on(this._element, EVENT_CLICK, event => { + event.preventDefault() + this.toggle() + }) + } + _completeHide(relatedTarget) { const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE, relatedTarget) if (hideEvent.defaultPrevented) { @@ -237,35 +279,6 @@ class Dropdown extends BaseComponent { return config } - _createPopper(parent) { - if (typeof Popper === 'undefined') { - throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)') - } - - let referenceElement = this._element - - if (this._config.reference === 'parent') { - referenceElement = parent - } else if (isElement(this._config.reference)) { - referenceElement = getElement(this._config.reference) - } else if (typeof this._config.reference === 'object') { - referenceElement = this._config.reference - } - - const popperConfig = this._getPopperConfig() - const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false) - - this._popper = Popper.createPopper(referenceElement, this._menu, popperConfig) - - if (isDisplayStatic) { - Manipulator.setDataAttribute(this._menu, 'popper', 'static') - } - } - - _isShown(element = this._element) { - return element.classList.contains(CLASS_NAME_SHOW) - } - _getMenuElement() { return SelectorEngine.next(this._element, SELECTOR_MENU)[0] } @@ -354,19 +367,21 @@ class Dropdown extends BaseComponent { // Static - static jQueryInterface(config) { - return this.each(function () { - const data = Dropdown.getOrCreateInstance(this, config) - - if (typeof config !== 'string') { - return - } + static dropdownInterface(element, config) { + const data = Dropdown.getOrCreateInstance(element, config) + if (typeof config === 'string') { if (typeof data[config] === 'undefined') { throw new TypeError(`No method named "${config}"`) } data[config]() + } + } + + static jQueryInterface(config) { + return this.each(function () { + Dropdown.dropdownInterface(this, config) }) } @@ -383,7 +398,7 @@ class Dropdown extends BaseComponent { continue } - if (!context._isShown()) { + if (!context._element.classList.contains(CLASS_NAME_SHOW)) { continue } @@ -449,20 +464,20 @@ class Dropdown extends BaseComponent { return } - const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0] - const instance = Dropdown.getOrCreateInstance(getToggleButton) + const getToggleButton = () => this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0] if (event.key === ESCAPE_KEY) { - instance.hide() + getToggleButton().focus() + Dropdown.clearMenus() return } if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) { if (!isActive) { - instance.show() + getToggleButton().click() } - instance._selectMenuItem(event) + Dropdown.getInstance(getToggleButton())._selectMenuItem(event) return } @@ -484,7 +499,7 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus) EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus) EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { event.preventDefault() - Dropdown.getOrCreateInstance(this).toggle() + Dropdown.dropdownInterface(this) }) /** |