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:
parent
89f88762c5
commit
882185bbde
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user