0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Change selector-engine.js parents method to utilize better js native methods (#35684)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
GeoSot 2022-01-30 16:24:03 +02:00 committed by GitHub
parent 89f88762c5
commit 882185bbde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,8 +11,6 @@ import { isDisabled, isVisible } from '../util/index'
* Constants * Constants
*/ */
const NODE_TEXT = 3
const SelectorEngine = { const SelectorEngine = {
find(selector, element = document.documentElement) { find(selector, element = document.documentElement) {
return [].concat(...Element.prototype.querySelectorAll.call(element, selector)) return [].concat(...Element.prototype.querySelectorAll.call(element, selector))
@ -28,14 +26,11 @@ const SelectorEngine = {
parents(element, selector) { parents(element, selector) {
const parents = [] const parents = []
let ancestor = element.parentNode let ancestor = element.parentNode.closest(selector)
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) { while (ancestor) {
if (ancestor.matches(selector)) { parents.push(ancestor)
parents.push(ancestor) ancestor = ancestor.parentNode.closest(selector)
}
ancestor = ancestor.parentNode
} }
return parents return parents