diff options
Diffstat (limited to 'js/dist/dom/selector-engine.js')
| -rw-r--r-- | js/dist/dom/selector-engine.js | 96 |
1 files changed, 65 insertions, 31 deletions
diff --git a/js/dist/dom/selector-engine.js b/js/dist/dom/selector-engine.js index 6b2297e35..1d260dce7 100644 --- a/js/dist/dom/selector-engine.js +++ b/js/dist/dom/selector-engine.js @@ -1,5 +1,5 @@ /*! - * Bootstrap selector-engine.js v5.0.0-beta2 (https://getbootstrap.com/) + * Bootstrap selector-engine.js v5.1.0 (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) */ @@ -11,44 +11,70 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta2): dom/selector-engine.js + * Bootstrap (v5.1.0): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ - var NODE_TEXT = 3; - var SelectorEngine = { - find: function find(selector, element) { - var _ref; + const isElement = obj => { + if (!obj || typeof obj !== 'object') { + return false; + } - if (element === void 0) { - element = document.documentElement; - } + if (typeof obj.jquery !== 'undefined') { + obj = obj[0]; + } + + return typeof obj.nodeType !== 'undefined'; + }; + + const isVisible = element => { + if (!isElement(element) || element.getClientRects().length === 0) { + return false; + } + + return getComputedStyle(element).getPropertyValue('visibility') === 'visible'; + }; + + const isDisabled = element => { + if (!element || element.nodeType !== Node.ELEMENT_NODE) { + return true; + } + + if (element.classList.contains('disabled')) { + return true; + } - return (_ref = []).concat.apply(_ref, Element.prototype.querySelectorAll.call(element, selector)); + if (typeof element.disabled !== 'undefined') { + return element.disabled; + } + + return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false'; + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.0): dom/selector-engine.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + const NODE_TEXT = 3; + const SelectorEngine = { + find(selector, element = document.documentElement) { + return [].concat(...Element.prototype.querySelectorAll.call(element, selector)); }, - findOne: function findOne(selector, element) { - if (element === void 0) { - element = document.documentElement; - } + findOne(selector, element = document.documentElement) { return Element.prototype.querySelector.call(element, selector); }, - children: function children(element, selector) { - var _ref2; - return (_ref2 = []).concat.apply(_ref2, element.children).filter(function (child) { - return child.matches(selector); - }); + children(element, selector) { + return [].concat(...element.children).filter(child => child.matches(selector)); }, - parents: function parents(element, selector) { - var parents = []; - var ancestor = element.parentNode; + + parents(element, selector) { + const parents = []; + let ancestor = element.parentNode; while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) { if (ancestor.matches(selector)) { @@ -60,8 +86,9 @@ return parents; }, - prev: function prev(element, selector) { - var previous = element.previousElementSibling; + + prev(element, selector) { + let previous = element.previousElementSibling; while (previous) { if (previous.matches(selector)) { @@ -73,8 +100,9 @@ return []; }, - next: function next(element, selector) { - var next = element.nextElementSibling; + + next(element, selector) { + let next = element.nextElementSibling; while (next) { if (next.matches(selector)) { @@ -85,7 +113,13 @@ } return []; + }, + + focusableChildren(element) { + const focusables = ['a', 'button', 'input', 'textarea', 'select', 'details', '[tabindex]', '[contenteditable="true"]'].map(selector => `${selector}:not([tabindex^="-"])`).join(', '); + return this.find(focusables, element).filter(el => !isDisabled(el) && isVisible(el)); } + }; return SelectorEngine; |
