main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
697 bytes
|
Line | |
---|
1 | // @flow
|
---|
2 | import { isShadowRoot } from './instanceOf';
|
---|
3 |
|
---|
4 | export default function contains(parent: Element, child: Element) {
|
---|
5 | const rootNode = child.getRootNode && child.getRootNode();
|
---|
6 |
|
---|
7 | // First, attempt with faster native method
|
---|
8 | if (parent.contains(child)) {
|
---|
9 | return true;
|
---|
10 | }
|
---|
11 | // then fallback to custom implementation with Shadow DOM support
|
---|
12 | else if (rootNode && isShadowRoot(rootNode)) {
|
---|
13 | let next = child;
|
---|
14 | do {
|
---|
15 | if (next && parent.isSameNode(next)) {
|
---|
16 | return true;
|
---|
17 | }
|
---|
18 | // $FlowFixMe[prop-missing]: need a better way to handle this...
|
---|
19 | next = next.parentNode || next.host;
|
---|
20 | } while (next);
|
---|
21 | }
|
---|
22 |
|
---|
23 | // Give up, the result is false
|
---|
24 | return false;
|
---|
25 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.