aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2022-01-30 16:24:03 +0200
committerGitHub <[email protected]>2022-01-30 16:24:03 +0200
commit882185bbde9fa6ce0e7885404e76afa0090bdabb (patch)
treee31de10f1221d25abcf8bb4811854d3e6bce5117 /js/src
parent89f88762c52f4c7dfca0fe1de6d41386bb673289 (diff)
downloadbootstrap-882185bbde9fa6ce0e7885404e76afa0090bdabb.tar.xz
bootstrap-882185bbde9fa6ce0e7885404e76afa0090bdabb.zip
Change selector-engine.js `parents` method to utilize better js native methods (#35684)
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js/src')
-rw-r--r--js/src/dom/selector-engine.js13
1 files changed, 4 insertions, 9 deletions
diff --git a/js/src/dom/selector-engine.js b/js/src/dom/selector-engine.js
index 39f3971dc..7f4165afc 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