2018-11-13 07:41:12 +01:00
|
|
|
/*!
|
2023-03-24 15:30:16 +01:00
|
|
|
* Bootstrap dropdown.js v5.3.0-alpha2 (https://getbootstrap.com/)
|
|
|
|
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
2020-06-16 20:50:01 +02:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2018-11-13 07:41:12 +01:00
|
|
|
*/
|
2018-07-24 02:51:14 +02:00
|
|
|
(function (global, factory) {
|
2022-12-24 17:37:22 +01:00
|
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./util/index.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
|
2022-05-13 08:07:23 +02:00
|
|
|
typeof define === 'function' && define.amd ? define(['@popperjs/core', './util/index', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
|
|
|
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global["@popperjs/core"], global.Index, global.EventHandler, global.Manipulator, global.SelectorEngine, global.BaseComponent));
|
2022-12-24 17:37:22 +01:00
|
|
|
})(this, (function (Popper, index_js, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
|
2019-03-01 17:31:34 +01:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
function _interopNamespaceDefault(e) {
|
2022-05-13 08:07:23 +02:00
|
|
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
2020-12-07 16:50:24 +01:00
|
|
|
if (e) {
|
2021-10-05 17:50:18 +02:00
|
|
|
for (const k in e) {
|
2020-12-07 16:50:24 +01:00
|
|
|
if (k !== 'default') {
|
2021-10-05 17:50:18 +02:00
|
|
|
const d = Object.getOwnPropertyDescriptor(e, k);
|
2020-12-07 16:50:24 +01:00
|
|
|
Object.defineProperty(n, k, d.get ? d : {
|
|
|
|
enumerable: true,
|
2021-10-05 17:50:18 +02:00
|
|
|
get: () => e[k]
|
2020-12-07 16:50:24 +01:00
|
|
|
});
|
|
|
|
}
|
2021-10-05 17:50:18 +02:00
|
|
|
}
|
2020-12-07 16:50:24 +01:00
|
|
|
}
|
2021-10-05 17:50:18 +02:00
|
|
|
n.default = e;
|
2020-12-07 16:50:24 +01:00
|
|
|
return Object.freeze(n);
|
|
|
|
}
|
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
const Popper__namespace = /*#__PURE__*/_interopNamespaceDefault(Popper);
|
2021-02-10 17:14:51 +01:00
|
|
|
|
2021-08-04 17:41:51 +02:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2023-03-24 15:30:16 +01:00
|
|
|
* Bootstrap dropdown.js
|
2021-03-23 17:26:54 +01:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2020-12-03 15:18:59 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
|
2021-03-23 17:26:54 +01:00
|
|
|
const NAME = 'dropdown';
|
|
|
|
const DATA_KEY = 'bs.dropdown';
|
|
|
|
const EVENT_KEY = `.${DATA_KEY}`;
|
|
|
|
const DATA_API_KEY = '.data-api';
|
|
|
|
const ESCAPE_KEY = 'Escape';
|
|
|
|
const TAB_KEY = 'Tab';
|
|
|
|
const ARROW_UP_KEY = 'ArrowUp';
|
|
|
|
const ARROW_DOWN_KEY = 'ArrowDown';
|
|
|
|
const RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button
|
|
|
|
|
|
|
|
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_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}`;
|
|
|
|
const CLASS_NAME_SHOW = 'show';
|
|
|
|
const CLASS_NAME_DROPUP = 'dropup';
|
|
|
|
const CLASS_NAME_DROPEND = 'dropend';
|
|
|
|
const CLASS_NAME_DROPSTART = 'dropstart';
|
2022-05-13 08:07:23 +02:00
|
|
|
const CLASS_NAME_DROPUP_CENTER = 'dropup-center';
|
|
|
|
const CLASS_NAME_DROPDOWN_CENTER = 'dropdown-center';
|
|
|
|
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled)';
|
|
|
|
const SELECTOR_DATA_TOGGLE_SHOWN = `${SELECTOR_DATA_TOGGLE}.${CLASS_NAME_SHOW}`;
|
2021-03-23 17:26:54 +01:00
|
|
|
const SELECTOR_MENU = '.dropdown-menu';
|
2022-05-13 08:07:23 +02:00
|
|
|
const SELECTOR_NAVBAR = '.navbar';
|
2021-03-23 17:26:54 +01:00
|
|
|
const SELECTOR_NAVBAR_NAV = '.navbar-nav';
|
|
|
|
const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)';
|
2022-12-24 17:37:22 +01:00
|
|
|
const PLACEMENT_TOP = index_js.isRTL() ? 'top-end' : 'top-start';
|
|
|
|
const PLACEMENT_TOPEND = index_js.isRTL() ? 'top-start' : 'top-end';
|
|
|
|
const PLACEMENT_BOTTOM = index_js.isRTL() ? 'bottom-end' : 'bottom-start';
|
|
|
|
const PLACEMENT_BOTTOMEND = index_js.isRTL() ? 'bottom-start' : 'bottom-end';
|
|
|
|
const PLACEMENT_RIGHT = index_js.isRTL() ? 'left-start' : 'right-start';
|
|
|
|
const PLACEMENT_LEFT = index_js.isRTL() ? 'right-start' : 'left-start';
|
2022-05-13 08:07:23 +02:00
|
|
|
const PLACEMENT_TOPCENTER = 'top';
|
|
|
|
const PLACEMENT_BOTTOMCENTER = 'bottom';
|
2021-03-23 17:26:54 +01:00
|
|
|
const Default = {
|
2022-07-19 17:43:58 +02:00
|
|
|
autoClose: true,
|
2020-12-07 16:50:24 +01:00
|
|
|
boundary: 'clippingParents',
|
2019-08-27 15:03:21 +02:00
|
|
|
display: 'dynamic',
|
2022-07-19 17:43:58 +02:00
|
|
|
offset: [0, 2],
|
2021-05-05 21:32:12 +02:00
|
|
|
popperConfig: null,
|
2022-07-19 17:43:58 +02:00
|
|
|
reference: 'toggle'
|
2018-11-13 07:41:12 +01:00
|
|
|
};
|
2021-03-23 17:26:54 +01:00
|
|
|
const DefaultType = {
|
2022-07-19 17:43:58 +02:00
|
|
|
autoClose: '(boolean|string)',
|
2018-11-13 07:41:12 +01:00
|
|
|
boundary: '(string|element)',
|
2019-08-27 15:03:21 +02:00
|
|
|
display: 'string',
|
2022-07-19 17:43:58 +02:00
|
|
|
offset: '(array|string|function)',
|
2021-05-05 21:32:12 +02:00
|
|
|
popperConfig: '(null|object|function)',
|
2022-07-19 17:43:58 +02:00
|
|
|
reference: '(string|element|object)'
|
2018-11-13 07:41:12 +01:00
|
|
|
};
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2019-10-08 08:39:10 +02:00
|
|
|
/**
|
2022-05-13 08:07:23 +02:00
|
|
|
* Class definition
|
2019-10-08 08:39:10 +02:00
|
|
|
*/
|
2015-05-13 21:48:34 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
class Dropdown extends BaseComponent {
|
2021-03-23 17:26:54 +01:00
|
|
|
constructor(element, config) {
|
2022-05-13 08:07:23 +02:00
|
|
|
super(element, config);
|
2021-03-23 17:26:54 +01:00
|
|
|
this._popper = null;
|
2022-05-13 08:07:23 +02:00
|
|
|
this._parent = this._element.parentNode; // dropdown wrapper
|
2022-12-24 17:37:22 +01:00
|
|
|
// todo: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/
|
|
|
|
this._menu = SelectorEngine.next(this._element, SELECTOR_MENU)[0] || SelectorEngine.prev(this._element, SELECTOR_MENU)[0] || SelectorEngine.findOne(SELECTOR_MENU, this._parent);
|
2021-03-23 17:26:54 +01:00
|
|
|
this._inNavbar = this._detectNavbar();
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2015-05-10 22:47:11 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Getters
|
2021-03-23 17:26:54 +01:00
|
|
|
static get Default() {
|
|
|
|
return Default;
|
|
|
|
}
|
|
|
|
static get DefaultType() {
|
|
|
|
return DefaultType;
|
|
|
|
}
|
2021-05-13 18:22:20 +02:00
|
|
|
static get NAME() {
|
|
|
|
return NAME;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2015-05-10 22:47:11 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Public
|
2021-03-23 17:26:54 +01:00
|
|
|
toggle() {
|
2021-08-04 17:41:51 +02:00
|
|
|
return this._isShown() ? this.hide() : this.show();
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
show() {
|
2022-12-24 17:37:22 +01:00
|
|
|
if (index_js.isDisabled(this._element) || this._isShown()) {
|
2019-08-27 15:03:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
const relatedTarget = {
|
2018-11-13 07:41:12 +01:00
|
|
|
relatedTarget: this._element
|
|
|
|
};
|
2022-12-24 17:37:22 +01:00
|
|
|
const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, relatedTarget);
|
2019-03-01 17:31:34 +01:00
|
|
|
if (showEvent.defaultPrevented) {
|
2018-11-13 07:41:12 +01:00
|
|
|
return;
|
2021-08-04 17:41:51 +02:00
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
this._createPopper();
|
2017-09-06 06:05:12 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// If this is a touch-enabled device we add extra
|
2018-11-13 07:41:12 +01:00
|
|
|
// empty mouseover listeners to the body's immediate children;
|
|
|
|
// only needed because of broken event delegation on iOS
|
|
|
|
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
2022-05-13 08:07:23 +02:00
|
|
|
if ('ontouchstart' in document.documentElement && !this._parent.closest(SELECTOR_NAVBAR_NAV)) {
|
|
|
|
for (const element of [].concat(...document.body.children)) {
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.on(element, 'mouseover', index_js.noop);
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
|
|
|
this._element.focus();
|
|
|
|
this._element.setAttribute('aria-expanded', true);
|
2021-08-04 17:41:51 +02:00
|
|
|
this._menu.classList.add(CLASS_NAME_SHOW);
|
|
|
|
this._element.classList.add(CLASS_NAME_SHOW);
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.trigger(this._element, EVENT_SHOWN, relatedTarget);
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
hide() {
|
2022-12-24 17:37:22 +01:00
|
|
|
if (index_js.isDisabled(this._element) || !this._isShown()) {
|
2018-11-13 07:41:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
const relatedTarget = {
|
2018-11-13 07:41:12 +01:00
|
|
|
relatedTarget: this._element
|
2018-07-24 02:51:14 +02:00
|
|
|
};
|
2021-05-05 21:32:12 +02:00
|
|
|
this._completeHide(relatedTarget);
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
dispose() {
|
2019-08-27 15:03:21 +02:00
|
|
|
if (this._popper) {
|
2018-11-13 07:41:12 +01:00
|
|
|
this._popper.destroy();
|
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
update() {
|
2018-11-13 07:41:12 +01:00
|
|
|
this._inNavbar = this._detectNavbar();
|
2019-08-27 15:03:21 +02:00
|
|
|
if (this._popper) {
|
2020-12-07 16:50:24 +01:00
|
|
|
this._popper.update();
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2017-10-16 00:51:44 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Private
|
2021-05-05 21:32:12 +02:00
|
|
|
_completeHide(relatedTarget) {
|
2022-12-24 17:37:22 +01:00
|
|
|
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE, relatedTarget);
|
2021-05-05 21:32:12 +02:00
|
|
|
if (hideEvent.defaultPrevented) {
|
|
|
|
return;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2021-05-05 21:32:12 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// If this is a touch-enabled device we remove the extra
|
|
|
|
// empty mouseover listeners we added for iOS support
|
2021-05-05 21:32:12 +02:00
|
|
|
if ('ontouchstart' in document.documentElement) {
|
2022-05-13 08:07:23 +02:00
|
|
|
for (const element of [].concat(...document.body.children)) {
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.off(element, 'mouseover', index_js.noop);
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
2021-05-05 21:32:12 +02:00
|
|
|
}
|
|
|
|
if (this._popper) {
|
|
|
|
this._popper.destroy();
|
|
|
|
}
|
|
|
|
this._menu.classList.remove(CLASS_NAME_SHOW);
|
|
|
|
this._element.classList.remove(CLASS_NAME_SHOW);
|
|
|
|
this._element.setAttribute('aria-expanded', 'false');
|
2022-12-24 17:37:22 +01:00
|
|
|
Manipulator.removeDataAttribute(this._menu, 'popper');
|
|
|
|
EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget);
|
2021-05-05 21:32:12 +02:00
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
_getConfig(config) {
|
2022-05-13 08:07:23 +02:00
|
|
|
config = super._getConfig(config);
|
2022-12-24 17:37:22 +01:00
|
|
|
if (typeof config.reference === 'object' && !index_js.isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') {
|
2021-02-10 17:14:51 +01:00
|
|
|
// Popper virtual elements require a getBoundingClientRect method
|
2021-03-23 17:26:54 +01:00
|
|
|
throw new TypeError(`${NAME.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`);
|
2021-02-10 17:14:51 +01:00
|
|
|
}
|
2018-11-13 07:41:12 +01:00
|
|
|
return config;
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
_createPopper() {
|
2021-08-04 17:41:51 +02:00
|
|
|
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') {
|
2022-05-13 08:07:23 +02:00
|
|
|
referenceElement = this._parent;
|
2022-12-24 17:37:22 +01:00
|
|
|
} else if (index_js.isElement(this._config.reference)) {
|
|
|
|
referenceElement = index_js.getElement(this._config.reference);
|
2021-08-04 17:41:51 +02:00
|
|
|
} else if (typeof this._config.reference === 'object') {
|
|
|
|
referenceElement = this._config.reference;
|
|
|
|
}
|
|
|
|
const popperConfig = this._getPopperConfig();
|
|
|
|
this._popper = Popper__namespace.createPopper(referenceElement, this._menu, popperConfig);
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
_isShown() {
|
|
|
|
return this._menu.classList.contains(CLASS_NAME_SHOW);
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
_getPlacement() {
|
2022-05-13 08:07:23 +02:00
|
|
|
const parentDropdown = this._parent;
|
2020-12-07 16:50:24 +01:00
|
|
|
if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) {
|
|
|
|
return PLACEMENT_RIGHT;
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2020-12-07 16:50:24 +01:00
|
|
|
if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) {
|
|
|
|
return PLACEMENT_LEFT;
|
2022-05-13 08:07:23 +02:00
|
|
|
}
|
|
|
|
if (parentDropdown.classList.contains(CLASS_NAME_DROPUP_CENTER)) {
|
|
|
|
return PLACEMENT_TOPCENTER;
|
|
|
|
}
|
|
|
|
if (parentDropdown.classList.contains(CLASS_NAME_DROPDOWN_CENTER)) {
|
|
|
|
return PLACEMENT_BOTTOMCENTER;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2018-11-13 07:41:12 +01:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// We need to trim the value because custom properties can also include spaces
|
2021-03-23 17:26:54 +01:00
|
|
|
const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end';
|
2020-12-07 16:50:24 +01:00
|
|
|
if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
|
|
|
|
return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP;
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2020-12-07 16:50:24 +01:00
|
|
|
return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM;
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
_detectNavbar() {
|
2022-05-13 08:07:23 +02:00
|
|
|
return this._element.closest(SELECTOR_NAVBAR) !== null;
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
_getOffset() {
|
|
|
|
const {
|
|
|
|
offset
|
|
|
|
} = this._config;
|
2021-02-10 17:14:51 +01:00
|
|
|
if (typeof offset === 'string') {
|
2022-05-13 08:07:23 +02:00
|
|
|
return offset.split(',').map(value => Number.parseInt(value, 10));
|
2021-02-10 17:14:51 +01:00
|
|
|
}
|
|
|
|
if (typeof offset === 'function') {
|
2021-03-23 17:26:54 +01:00
|
|
|
return popperData => offset(popperData, this._element);
|
2021-02-10 17:14:51 +01:00
|
|
|
}
|
|
|
|
return offset;
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
_getPopperConfig() {
|
|
|
|
const defaultBsPopperConfig = {
|
2018-11-13 07:41:12 +01:00
|
|
|
placement: this._getPlacement(),
|
2020-12-07 16:50:24 +01:00
|
|
|
modifiers: [{
|
|
|
|
name: 'preventOverflow',
|
|
|
|
options: {
|
2021-02-10 17:14:51 +01:00
|
|
|
boundary: this._config.boundary
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
name: 'offset',
|
|
|
|
options: {
|
|
|
|
offset: this._getOffset()
|
2017-09-06 06:05:12 +02:00
|
|
|
}
|
2020-12-07 16:50:24 +01:00
|
|
|
}]
|
2022-12-24 17:37:22 +01:00
|
|
|
};
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Disable Popper if we have a static display or Dropdown is in Navbar
|
2022-05-13 08:07:23 +02:00
|
|
|
if (this._inNavbar || this._config.display === 'static') {
|
2022-12-24 17:37:22 +01:00
|
|
|
Manipulator.setDataAttribute(this._menu, 'popper', 'static'); // todo:v6 remove
|
2021-02-10 17:14:51 +01:00
|
|
|
defaultBsPopperConfig.modifiers = [{
|
2020-12-07 16:50:24 +01:00
|
|
|
name: 'applyStyles',
|
2018-11-13 07:41:12 +01:00
|
|
|
enabled: false
|
2020-12-07 16:50:24 +01:00
|
|
|
}];
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
return {
|
|
|
|
...defaultBsPopperConfig,
|
|
|
|
...index_js.execute(this._config.popperConfig, [defaultBsPopperConfig])
|
2021-03-23 17:26:54 +01:00
|
|
|
};
|
2021-05-05 21:32:12 +02:00
|
|
|
}
|
2021-06-22 20:29:16 +02:00
|
|
|
_selectMenuItem({
|
|
|
|
key,
|
|
|
|
target
|
|
|
|
}) {
|
2022-12-24 17:37:22 +01:00
|
|
|
const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(element => index_js.isVisible(element));
|
2021-05-05 21:32:12 +02:00
|
|
|
if (!items.length) {
|
|
|
|
return;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2015-05-10 22:47:11 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// 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
|
|
|
|
index_js.getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus();
|
|
|
|
}
|
2015-05-10 22:47:11 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Static
|
2021-08-04 17:41:51 +02:00
|
|
|
static jQueryInterface(config) {
|
|
|
|
return this.each(function () {
|
|
|
|
const data = Dropdown.getOrCreateInstance(this, config);
|
|
|
|
if (typeof config !== 'string') {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-01 17:31:34 +01:00
|
|
|
if (typeof data[config] === 'undefined') {
|
2021-03-23 17:26:54 +01:00
|
|
|
throw new TypeError(`No method named "${config}"`);
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2019-03-01 17:31:34 +01:00
|
|
|
data[config]();
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
static clearMenus(event) {
|
2022-05-13 08:07:23 +02:00
|
|
|
if (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY) {
|
2021-05-13 18:22:20 +02:00
|
|
|
return;
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
const openToggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE_SHOWN);
|
2022-05-13 08:07:23 +02:00
|
|
|
for (const toggle of openToggles) {
|
|
|
|
const context = Dropdown.getInstance(toggle);
|
2021-05-05 21:32:12 +02:00
|
|
|
if (!context || context._config.autoClose === false) {
|
2018-11-13 07:41:12 +01:00
|
|
|
continue;
|
2018-07-24 02:51:14 +02:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
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;
|
2022-12-24 17:37:22 +01:00
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu
|
2022-05-13 08:07:23 +02:00
|
|
|
if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) {
|
2018-11-13 07:41:12 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-05 21:32:12 +02:00
|
|
|
const relatedTarget = {
|
|
|
|
relatedTarget: context._element
|
|
|
|
};
|
2022-05-13 08:07:23 +02:00
|
|
|
if (event.type === 'click') {
|
|
|
|
relatedTarget.clickEvent = event;
|
2019-08-27 15:03:21 +02:00
|
|
|
}
|
2021-05-05 21:32:12 +02:00
|
|
|
context._completeHide(relatedTarget);
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
static dataApiKeydownHandler(event) {
|
2022-05-13 08:07:23 +02:00
|
|
|
// If not an UP | DOWN | ESCAPE key => not a dropdown command
|
|
|
|
// If input/textarea && if key is other than ESCAPE => not a dropdown command
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2022-05-13 08:07:23 +02:00
|
|
|
const isInput = /input|textarea/i.test(event.target.tagName);
|
|
|
|
const isEscapeEvent = event.key === ESCAPE_KEY;
|
|
|
|
const isUpOrDownEvent = [ARROW_UP_KEY, ARROW_DOWN_KEY].includes(event.key);
|
|
|
|
if (!isUpOrDownEvent && !isEscapeEvent) {
|
2021-05-05 21:32:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
if (isInput && !isEscapeEvent) {
|
2018-11-13 07:41:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
event.preventDefault();
|
2015-08-19 05:28:28 +02:00
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
// todo: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/
|
|
|
|
const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0] || SelectorEngine.next(this, SELECTOR_DATA_TOGGLE)[0] || SelectorEngine.findOne(SELECTOR_DATA_TOGGLE, event.delegateTarget.parentNode);
|
2021-08-04 17:41:51 +02:00
|
|
|
const instance = Dropdown.getOrCreateInstance(getToggleButton);
|
2022-05-13 08:07:23 +02:00
|
|
|
if (isUpOrDownEvent) {
|
|
|
|
event.stopPropagation();
|
|
|
|
instance.show();
|
2021-08-04 17:41:51 +02:00
|
|
|
instance._selectMenuItem(event);
|
2021-02-10 17:14:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-05-13 08:07:23 +02:00
|
|
|
if (instance._isShown()) {
|
|
|
|
// else is escape and we check if it is shown
|
|
|
|
event.stopPropagation();
|
|
|
|
instance.hide();
|
|
|
|
getToggleButton.focus();
|
2018-11-13 07:41:12 +01:00
|
|
|
}
|
2021-03-23 17:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2018-11-13 07:41:12 +01:00
|
|
|
/**
|
2022-05-13 08:07:23 +02:00
|
|
|
* Data API implementation
|
2018-11-13 07:41:12 +01:00
|
|
|
*/
|
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
|
|
|
|
EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
|
|
|
|
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) {
|
2018-11-13 07:41:12 +01:00
|
|
|
event.preventDefault();
|
2021-08-04 17:41:51 +02:00
|
|
|
Dropdown.getOrCreateInstance(this).toggle();
|
2018-11-13 07:41:12 +01:00
|
|
|
});
|
2022-12-24 17:37:22 +01:00
|
|
|
|
2018-11-13 07:41:12 +01:00
|
|
|
/**
|
|
|
|
* jQuery
|
|
|
|
*/
|
|
|
|
|
2022-12-24 17:37:22 +01:00
|
|
|
index_js.defineJQueryPlugin(Dropdown);
|
2015-05-10 22:47:11 +02:00
|
|
|
|
|
|
|
return Dropdown;
|
2018-07-24 02:51:14 +02:00
|
|
|
|
2021-10-05 17:50:18 +02:00
|
|
|
}));
|
2018-07-24 02:51:14 +02:00
|
|
|
//# sourceMappingURL=dropdown.js.map
|