forked from BrightspaceUI/d2l-polymer-behaviors-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2l-dom.html
78 lines (60 loc) · 1.39 KB
/
d2l-dom.html
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script>
(function() {
'use strict';
var Dom = {
findComposedAncestor: function(node, predicate) {
while (node) {
if (predicate(node) === true) {
return node;
}
node = this.getComposedParent(node);
}
return null;
},
getComposedChildren: function(node) {
if (!node) {
return null;
}
if (node.nodeType !== 1 && node.nodeType !== 9 && node.nodeType !== 11) {
return null;
}
var nodes, children = [];
if (node.tagName === 'CONTENT') {
nodes = node.getDistributedNodes();
} else {
if (node.shadowRoot) {
node = node.shadowRoot;
}
nodes = node.children;
}
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType === 1) {
children.push(nodes[i]);
}
}
return children;
},
getComposedParent: function(node) {
if (node.getDestinationInsertionPoints) {
var insertionPoints = node.getDestinationInsertionPoints();
if (insertionPoints && insertionPoints.length > 0) {
return insertionPoints[0];
}
}
if (node.parentNode) {
return node.parentNode;
} else if (node.host) {
return node.host;
}
return null;
},
isComposedAncestor: function(ancestorNode, node) {
return this.findComposedAncestor(node, function(node) {
return (node === ancestorNode);
}) !== null;
}
};
window.D2L = window.D2L || {};
window.D2L.Dom = Dom;
})();
</script>