-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathd2l-dom.js
49 lines (44 loc) · 1.33 KB
/
d2l-dom.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {
findComposedAncestor,
getComposedChildren,
getComposedParent,
isComposedAncestor
} from '@brightspace-ui/core/helpers/dom.js';
window.D2L = window.D2L || {};
window.D2L.Dom = window.D2L.Dom || {};
window.D2L.Dom.findComposedAncestor = findComposedAncestor;
window.D2L.Dom.getComposedChildren = getComposedChildren;
window.D2L.Dom.getComposedParent = getComposedParent;
window.D2L.Dom.isComposedAncestor = isComposedAncestor;
window.D2L.Dom.getOffsetParent = function(node) {
if (!window.ShadowRoot) {
return node.offsetParent;
}
if (
!this.getComposedParent(node) ||
node.tagName === 'BODY' ||
window.getComputedStyle(node).position === 'fixed'
) {
return null;
}
let currentNode = this.getComposedParent(node);
while (currentNode) {
if (currentNode instanceof ShadowRoot) {
currentNode = this.getComposedParent(currentNode);
} else if (currentNode instanceof DocumentFragment) {
return null;
} else if (currentNode.tagName === 'BODY') {
return currentNode;
}
const position = window.getComputedStyle(currentNode).position;
const tagName = currentNode.tagName;
if (
(position && position !== 'static') ||
position === 'static' && (tagName === 'TD' || tagName === 'TH' || tagName === 'TABLE')
) {
return currentNode;
}
currentNode = this.getComposedParent(currentNode);
}
return null;
};