aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/dropdown.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
committerMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
commitd459dfac74e90c29950d49a82edc19fd913d435e (patch)
tree7bed5f2dbc318f87bbe0f4be2cde3dde09cd97c7 /vendor/twbs/bootstrap/js/dist/dropdown.js
parentcec2f0d894b80f3affeb60cff2d4afa49a2019a8 (diff)
downloadvolse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.gz
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.bz2
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.zip
update to bootstrap 5.0.2
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/dropdown.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/dropdown.js105
1 files changed, 61 insertions, 44 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/dropdown.js b/vendor/twbs/bootstrap/js/dist/dropdown.js
index 09db6e8ad..89ca569c7 100644
--- a/vendor/twbs/bootstrap/js/dist/dropdown.js
+++ b/vendor/twbs/bootstrap/js/dist/dropdown.js
@@ -1,13 +1,13 @@
/*!
- * Bootstrap dropdown.js v5.0.1 (https://getbootstrap.com/)
+ * Bootstrap dropdown.js v5.0.2 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/selector-engine.js'), require('./dom/data.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/data', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.SelectorEngine, global.Data, global.EventHandler, global.Manipulator, global.Base));
-}(this, (function (Popper, SelectorEngine, Data, EventHandler, Manipulator, BaseComponent) { 'use strict';
+ 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';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -33,7 +33,6 @@
var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
- var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
@@ -113,17 +112,11 @@
};
const isVisible = element => {
- if (!element) {
+ if (!isElement(element) || element.getClientRects().length === 0) {
return false;
}
- if (element.style && element.parentNode && element.parentNode.style) {
- const elementStyle = getComputedStyle(element);
- const parentNodeStyle = getComputedStyle(element.parentNode);
- return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
- }
-
- return false;
+ return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
};
const isDisabled = element => {
@@ -156,9 +149,18 @@
return null;
};
+ const DOMContentLoadedCallbacks = [];
+
const onDOMContentLoaded = callback => {
if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', callback);
+ // add listener on the first call when the document is in loading state
+ if (!DOMContentLoadedCallbacks.length) {
+ document.addEventListener('DOMContentLoaded', () => {
+ DOMContentLoadedCallbacks.forEach(callback => callback());
+ });
+ }
+
+ DOMContentLoadedCallbacks.push(callback);
} else {
callback();
}
@@ -184,10 +186,37 @@
}
});
};
+ /**
+ * Return the previous/next element of a list.
+ *
+ * @param {array} list The list of elements
+ * @param activeElement The active element
+ * @param shouldGetNext Choose to get next or previous element
+ * @param isCycleAllowed
+ * @return {Element|elem} The proper element
+ */
+
+
+ const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
+ let index = list.indexOf(activeElement); // if the element does not exist in the list return an element depending on the direction and if cycle is allowed
+
+ if (index === -1) {
+ return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
+ }
+
+ const listLength = list.length;
+ index += shouldGetNext ? 1 : -1;
+
+ if (isCycleAllowed) {
+ index = (index + listLength) % listLength;
+ }
+
+ return list[Math.max(0, Math.min(index, listLength - 1))];
+ };
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.1): dropdown.js
+ * Bootstrap (v5.0.2): dropdown.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -507,38 +536,24 @@
};
}
- _selectMenuItem(event) {
+ _selectMenuItem({
+ key,
+ target
+ }) {
const items = SelectorEngine__default['default'].find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible);
if (!items.length) {
return;
- }
-
- let index = items.indexOf(event.target); // Up
-
- if (event.key === ARROW_UP_KEY && index > 0) {
- index--;
- } // Down
+ } // if target isn't included in items (e.g. when expanding the dropdown)
+ // allow cycling to get the last item in case key equals ARROW_UP_KEY
- if (event.key === ARROW_DOWN_KEY && index < items.length - 1) {
- index++;
- } // index is -1 if the first keydown is an ArrowUp
-
-
- index = index === -1 ? 0 : index;
- items[index].focus();
+ getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus();
} // Static
static dropdownInterface(element, config) {
- let data = Data__default['default'].get(element, DATA_KEY);
-
- const _config = typeof config === 'object' ? config : null;
-
- if (!data) {
- data = new Dropdown(element, _config);
- }
+ const data = Dropdown.getOrCreateInstance(element, config);
if (typeof config === 'string') {
if (typeof data[config] === 'undefined') {
@@ -563,7 +578,7 @@
const toggles = SelectorEngine__default['default'].find(SELECTOR_DATA_TOGGLE);
for (let i = 0, len = toggles.length; i < len; i++) {
- const context = Data__default['default'].get(toggles[i], DATA_KEY);
+ const context = Dropdown.getInstance(toggles[i]);
if (!context || context._config.autoClose === false) {
continue;
@@ -636,17 +651,19 @@
return;
}
- if (!isActive && (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY)) {
- getToggleButton().click();
+ if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
+ if (!isActive) {
+ getToggleButton().click();
+ }
+
+ Dropdown.getInstance(getToggleButton())._selectMenuItem(event);
+
return;
}
if (!isActive || event.key === SPACE_KEY) {
Dropdown.clearMenus();
- return;
}
-
- Dropdown.getInstance(getToggleButton())._selectMenuItem(event);
}
}