mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-11 09:45:24 +01:00
17 lines
439 B
JavaScript
17 lines
439 B
JavaScript
|
// Check if some condition applies for a node or any of its ancestors,
|
||
|
// stopping at an element that returns true for the given stopFunc. Returns
|
||
|
// false if none match
|
||
|
export function checkDomAncestors (node, checkFunc, stopFunc) {
|
||
|
let thisNode = node
|
||
|
while (thisNode) {
|
||
|
if (stopFunc(thisNode)) {
|
||
|
break
|
||
|
}
|
||
|
if (checkFunc(thisNode)) {
|
||
|
return true
|
||
|
}
|
||
|
thisNode = thisNode.parentElement
|
||
|
}
|
||
|
return false
|
||
|
}
|