0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +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
*/
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
let ancestor = element.parentNode.closest(selector)
while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
if (ancestor.matches(selector)) {
parents.push(ancestor)
}
ancestor = ancestor.parentNode
while (ancestor) {
parents.push(ancestor)
ancestor = ancestor.parentNode.closest(selector)
}
return parents