aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/dropdown.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/dropdown.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/dropdown.js202
1 files changed, 96 insertions, 106 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/dropdown.js b/vendor/twbs/bootstrap/js/dist/dropdown.js
index 89ca569c7..268b78d36 100644
--- a/vendor/twbs/bootstrap/js/dist/dropdown.js
+++ b/vendor/twbs/bootstrap/js/dist/dropdown.js
@@ -1,41 +1,46 @@
/*!
- * Bootstrap dropdown.js v5.0.2 (https://getbootstrap.com/)
+ * Bootstrap dropdown.js v5.1.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)
*/
(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/selector-engine.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
- typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/selector-engine', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.SelectorEngine, global.EventHandler, global.Manipulator, global.Base));
-}(this, (function (Popper, SelectorEngine, EventHandler, Manipulator, BaseComponent) { 'use strict';
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
+ typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
+})(this, (function (Popper, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
+ const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
function _interopNamespace(e) {
if (e && e.__esModule) return e;
- var n = Object.create(null);
+ const n = Object.create(null);
if (e) {
- Object.keys(e).forEach(function (k) {
+ for (const k in e) {
if (k !== 'default') {
- var d = Object.getOwnPropertyDescriptor(e, k);
+ const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
- get: function () {
- return e[k];
- }
+ get: () => e[k]
});
}
- });
+ }
}
- n['default'] = e;
+ n.default = e;
return Object.freeze(n);
}
- var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
- var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
- var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
- var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
- var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+ const Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
+ const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
+ const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
+ const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
+ const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+
+ /**
+ * --------------------------------------------------------------------------
+ * Bootstrap (v5.1.2): util/index.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
+ * --------------------------------------------------------------------------
+ */
const toType = obj => {
if (obj === null || obj === undefined) {
@@ -93,7 +98,7 @@
}
if (typeof obj === 'string' && obj.length > 0) {
- return SelectorEngine__default['default'].findOne(obj);
+ return document.querySelector(obj);
}
return null;
@@ -216,7 +221,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): dropdown.js
+ * Bootstrap (v5.1.2): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -242,7 +247,6 @@
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}`;
@@ -283,15 +287,13 @@
* ------------------------------------------------------------------------
*/
- class Dropdown extends BaseComponent__default['default'] {
+ class Dropdown extends BaseComponent__default.default {
constructor(element, config) {
super(element);
this._popper = null;
this._config = this._getConfig(config);
this._menu = this._getMenuElement();
this._inNavbar = this._detectNavbar();
-
- this._addEventListeners();
} // Getters
@@ -309,61 +311,29 @@
toggle() {
- if (isDisabled(this._element)) {
- return;
- }
-
- const isActive = this._element.classList.contains(CLASS_NAME_SHOW);
-
- if (isActive) {
- this.hide();
- return;
- }
-
- this.show();
+ return this._isShown() ? this.hide() : this.show();
}
show() {
- if (isDisabled(this._element) || this._menu.classList.contains(CLASS_NAME_SHOW)) {
+ if (isDisabled(this._element) || this._isShown(this._menu)) {
return;
}
- const parent = Dropdown.getParentFromElement(this._element);
const relatedTarget = {
relatedTarget: this._element
};
- const showEvent = EventHandler__default['default'].trigger(this._element, EVENT_SHOW, relatedTarget);
+ const showEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW, relatedTarget);
if (showEvent.defaultPrevented) {
return;
- } // Totally disable Popper for Dropdowns in Navbar
+ }
+ const parent = Dropdown.getParentFromElement(this._element); // Totally disable Popper for Dropdowns in Navbar
if (this._inNavbar) {
- Manipulator__default['default'].setDataAttribute(this._menu, 'popper', 'none');
+ Manipulator__default.default.setDataAttribute(this._menu, 'popper', 'none');
} else {
- if (typeof Popper__namespace === '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__namespace.createPopper(referenceElement, this._menu, popperConfig);
-
- if (isDisplayStatic) {
- Manipulator__default['default'].setDataAttribute(this._menu, 'popper', 'static');
- }
+ this._createPopper(parent);
} // If this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children;
// only needed because of broken event delegation on iOS
@@ -371,22 +341,22 @@
if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
- [].concat(...document.body.children).forEach(elem => EventHandler__default['default'].on(elem, 'mouseover', noop));
+ [].concat(...document.body.children).forEach(elem => EventHandler__default.default.on(elem, 'mouseover', noop));
}
this._element.focus();
this._element.setAttribute('aria-expanded', true);
- this._menu.classList.toggle(CLASS_NAME_SHOW);
+ this._menu.classList.add(CLASS_NAME_SHOW);
- this._element.classList.toggle(CLASS_NAME_SHOW);
+ this._element.classList.add(CLASS_NAME_SHOW);
- EventHandler__default['default'].trigger(this._element, EVENT_SHOWN, relatedTarget);
+ EventHandler__default.default.trigger(this._element, EVENT_SHOWN, relatedTarget);
}
hide() {
- if (isDisabled(this._element) || !this._menu.classList.contains(CLASS_NAME_SHOW)) {
+ if (isDisabled(this._element) || !this._isShown(this._menu)) {
return;
}
@@ -414,15 +384,8 @@
} // Private
- _addEventListeners() {
- EventHandler__default['default'].on(this._element, EVENT_CLICK, event => {
- event.preventDefault();
- this.toggle();
- });
- }
-
_completeHide(relatedTarget) {
- const hideEvent = EventHandler__default['default'].trigger(this._element, EVENT_HIDE, relatedTarget);
+ const hideEvent = EventHandler__default.default.trigger(this._element, EVENT_HIDE, relatedTarget);
if (hideEvent.defaultPrevented) {
return;
@@ -431,7 +394,7 @@
if ('ontouchstart' in document.documentElement) {
- [].concat(...document.body.children).forEach(elem => EventHandler__default['default'].off(elem, 'mouseover', noop));
+ [].concat(...document.body.children).forEach(elem => EventHandler__default.default.off(elem, 'mouseover', noop));
}
if (this._popper) {
@@ -444,13 +407,13 @@
this._element.setAttribute('aria-expanded', 'false');
- Manipulator__default['default'].removeDataAttribute(this._menu, 'popper');
- EventHandler__default['default'].trigger(this._element, EVENT_HIDDEN, relatedTarget);
+ Manipulator__default.default.removeDataAttribute(this._menu, 'popper');
+ EventHandler__default.default.trigger(this._element, EVENT_HIDDEN, relatedTarget);
}
_getConfig(config) {
config = { ...this.constructor.Default,
- ...Manipulator__default['default'].getDataAttributes(this._element),
+ ...Manipulator__default.default.getDataAttributes(this._element),
...config
};
typeCheckConfig(NAME, config, this.constructor.DefaultType);
@@ -463,8 +426,37 @@
return config;
}
+ _createPopper(parent) {
+ if (typeof Popper__namespace === '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__namespace.createPopper(referenceElement, this._menu, popperConfig);
+
+ if (isDisplayStatic) {
+ Manipulator__default.default.setDataAttribute(this._menu, 'popper', 'static');
+ }
+ }
+
+ _isShown(element = this._element) {
+ return element.classList.contains(CLASS_NAME_SHOW);
+ }
+
_getMenuElement() {
- return SelectorEngine__default['default'].next(this._element, SELECTOR_MENU)[0];
+ return SelectorEngine__default.default.next(this._element, SELECTOR_MENU)[0];
}
_getPlacement() {
@@ -540,7 +532,7 @@
key,
target
}) {
- const items = SelectorEngine__default['default'].find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible);
+ const items = SelectorEngine__default.default.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible);
if (!items.length) {
return;
@@ -552,21 +544,19 @@
} // Static
- static dropdownInterface(element, config) {
- const data = Dropdown.getOrCreateInstance(element, config);
+ static jQueryInterface(config) {
+ return this.each(function () {
+ const data = Dropdown.getOrCreateInstance(this, config);
+
+ if (typeof config !== 'string') {
+ return;
+ }
- 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);
});
}
@@ -575,7 +565,7 @@
return;
}
- const toggles = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE);
+ const toggles = SelectorEngine__default.default.find(SELECTOR_DATA_TOGGLE);
for (let i = 0, len = toggles.length; i < len; i++) {
const context = Dropdown.getInstance(toggles[i]);
@@ -584,7 +574,7 @@
continue;
}
- if (!context._element.classList.contains(CLASS_NAME_SHOW)) {
+ if (!context._isShown()) {
continue;
}
@@ -643,20 +633,20 @@
return;
}
- const getToggleButton = () => this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine__default['default'].prev(this, SELECTOR_DATA_TOGGLE)[0];
+ const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine__default.default.prev(this, SELECTOR_DATA_TOGGLE)[0];
+ const instance = Dropdown.getOrCreateInstance(getToggleButton);
if (event.key === ESCAPE_KEY) {
- getToggleButton().focus();
- Dropdown.clearMenus();
+ instance.hide();
return;
}
if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
if (!isActive) {
- getToggleButton().click();
+ instance.show();
}
- Dropdown.getInstance(getToggleButton())._selectMenuItem(event);
+ instance._selectMenuItem(event);
return;
}
@@ -674,13 +664,13 @@
*/
- EventHandler__default['default'].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
- EventHandler__default['default'].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
- EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus);
- EventHandler__default['default'].on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
- EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
+ EventHandler__default.default.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
+ EventHandler__default.default.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
+ EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus);
+ EventHandler__default.default.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
+ EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
event.preventDefault();
- Dropdown.dropdownInterface(this);
+ Dropdown.getOrCreateInstance(this).toggle();
});
/**
* ------------------------------------------------------------------------
@@ -693,5 +683,5 @@
return Dropdown;
-})));
+}));
//# sourceMappingURL=dropdown.js.map