mirror of
https://github.com/Hopiu/bootstrap.git
synced 2026-03-17 05:00:24 +00: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
1 changed files with 4 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue