Skip to content

Commit

Permalink
Change selector-engine.js parents method to utilize better js nativ…
Browse files Browse the repository at this point in the history
…e methods (#35684)

Co-authored-by: XhmikosR <[email protected]>
  • Loading branch information
GeoSot and XhmikosR authored Jan 30, 2022
1 parent 89f8876 commit 882185b
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions js/src/dom/selector-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 882185b

Please sign in to comment.