-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
120 lines (111 loc) · 3.62 KB
/
test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<script>
const originalOffsetParent = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetParent').get;
const originalOffsetTop = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetTop').get;
const originalOffsetLeft = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetLeft').get;
window.originalOffsetParentForTesting = element => originalOffsetParent.apply(element);
window.originalOffsetTopForTesting = element => originalOffsetTop.apply(element);
window.originalOffsetLeftForTesting = element => originalOffsetLeft.apply(element);
</script>
<script src="offsetParent-polyfill.js"></script>
<style>
.box {
width: 10px;
height: 10px;
}
</style>
<div>
<template shadowroot=open>
<style>
.box {
width: 10px;
height: 10px;
}
</style>
<div class=box></div>
<div id=target1shadow style="position: relative">
<div class=box></div>
<slot></slot>
</div>
</template>
<div class=box></div>
<div id=target1 style="position: absolute" class=box></div>
</div>
<span>
<template shadowroot=open>
<style>
.box {
width: 10px;
height: 10px;
}
</style>
<span class=box></span>
<span id=target2shadow style="position: relative">
<span class=box></span>
<slot></slot>
</span>
</template>
<span class=box></span>
<span id=target2 style="position: absolute" class=box></span>
</span>
<div>
<template shadowroot=open>
<style>
.box {
width: 10px;
height: 10px;
}
</style>
<div class=box></div>
<div id=target3shadowouter style="position: relative">
<div class=box></div>
<div>
<template shadowroot=open>
<style>
.box {
width: 10px;
height: 10px;
}
</style>
<div class=box></div>
<div id=target3shadowinner style="position: relative">
<div class=box></div>
<slot></slot>
</div>
</template>
<slot></slot>
</div>
</div>
</template>
<div class=box></div>
<div id=target3 style="position: absolute" class=box></div>
</div>
<div id=output></div>
<script>
(function attachShadowRoots(root) {
root.querySelectorAll("template[shadowroot]").forEach(template => {
const mode = template.getAttribute("shadowroot");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
attachShadowRoots(shadowRoot);
});
})(document);
</script>
<script>
function log(str) {
output.insertAdjacentHTML('beforeend', `<div>${str}</div>`);
}
log(`target1 polyfill: ${target1.offsetTop}`);
log(`target2 polyfill: ${target2.offsetTop}`);
log(`target3 polyfill: ${target3.offsetTop}`);
log('target1 native: ' + originalOffsetTopForTesting(target1));
log('target2 native: ' + originalOffsetTopForTesting(target2));
log('target3 native: ' + originalOffsetTopForTesting(target3));
log(`target1 offsetParent polyfill: ${target1.offsetParent.tagName} ${target1.offsetParent.id}`);
log(`target2 offsetParent polyfill: ${target2.offsetParent.tagName} ${target2.offsetParent.id}`);
log(`target3 offsetParent polyfill: ${target3.offsetParent.tagName} ${target3.offsetParent.id}`);
log(`target1 offsetParent native: ${originalOffsetParentForTesting(target1).tagName} ${originalOffsetParentForTesting(target1).id}`);
log(`target2 offsetParent native: ${originalOffsetParentForTesting(target2).tagName} ${originalOffsetParentForTesting(target2).id}`);
log(`target3 offsetParent native: ${originalOffsetParentForTesting(target3).tagName} ${originalOffsetParentForTesting(target3).id}`);
</script>