From: GeoSot Date: Sun, 30 Jan 2022 14:24:03 +0000 (+0200) Subject: Change selector-engine.js `parents` method to utilize better js native methods (... X-Git-Tag: v5.2.0-beta1~296 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=882185bbde9fa6ce0e7885404e76afa0090bdabb;p=thirdparty%2Fbootstrap.git Change selector-engine.js `parents` method to utilize better js native methods (#35684) Co-authored-by: XhmikosR --- diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js index 39f3971dca..7f4165afcc 100644 --- a/js/src/dom/selector-engine.js +++ b/js/src/dom/selector-engine.js @@ -11,8 +11,6 @@ import { isDisabled, isVisible } from '../util/index' * Constants */ -const NODE_TEXT = 3 - const SelectorEngine = { find(selector, element = document.documentElement) { return [].concat(...Element.prototype.querySelectorAll.call(element, selector)) @@ -28,14 +26,11 @@ const SelectorEngine = { parents(element, selector) { const parents = [] - let ancestor = element.parentNode - - while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) { - if (ancestor.matches(selector)) { - parents.push(ancestor) - } + let ancestor = element.parentNode.closest(selector) - ancestor = ancestor.parentNode + while (ancestor) { + parents.push(ancestor) + ancestor = ancestor.parentNode.closest(selector) } return parents