-
Notifications
You must be signed in to change notification settings - Fork 743
/
contains.js
33 lines (31 loc) · 973 Bytes
/
contains.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Wrapper for Node#contains
* @method contains
* @memberof axe.utils
* @param {VirtualNode} vNode The candidate container VirtualNode
* @param {VirtualNode} otherVNode The vNode to test is contained by `vNode`
* @return {Boolean} Whether `vNode` contains `otherVNode`
*/
export default function contains(vNode, otherVNode) {
// Native light DOM method
if (
!vNode.shadowId &&
!otherVNode.shadowId &&
vNode.actualNode &&
// eslint-disable-next-line no-restricted-syntax
typeof vNode.actualNode.contains === 'function'
) {
// eslint-disable-next-line no-restricted-syntax
return vNode.actualNode.contains(otherVNode.actualNode);
}
// Alternative method for shadow DOM / virtual tree tests
do {
if (vNode === otherVNode) {
return true;
} else if (otherVNode.nodeIndex < vNode.nodeIndex) {
return false;
}
otherVNode = otherVNode.parent;
} while (otherVNode);
return false;
}