]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Change selector-engine.js `parents` method to utilize better js native methods (...
authorGeoSot <geo.sotis@gmail.com>
Sun, 30 Jan 2022 14:24:03 +0000 (16:24 +0200)
committerGitHub <noreply@github.com>
Sun, 30 Jan 2022 14:24:03 +0000 (16:24 +0200)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
js/src/dom/selector-engine.js

index 39f3971dca3e0bf7c8a41097f3df7416bdc1f238..7f4165afcc515241ad1e388a84a31ca2adbc300e 100644 (file)
@@ -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