forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay-manager.js
More file actions
53 lines (42 loc) · 1.16 KB
/
overlay-manager.js
File metadata and controls
53 lines (42 loc) · 1.16 KB
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
let iframeReference = null;
export function resetOverlay() {
try {
window.document.body.removeChild(iframeReference);
iframeReference = null;
} catch (e) {
/* nothing */
}
}
function createIframe() {
return new Promise(resolve => {
if (iframeReference) {
resolve(iframeReference);
}
const iframe = document.createElement('iframe');
iframe.setAttribute(
'style',
`position: fixed; top: 0; left: 0; width: 100%; height: 100%; border: none; z-index: 214748366;`
);
iframe.setAttribute('id', 'frame');
iframeReference = iframe;
document.body.appendChild(iframe);
if (iframe.contentDocument) {
resolve(iframe);
} else if (document.getElementById('not-found-frame')) {
document.getElementById('not-found-frame').onload = () => {
resolve(iframe);
};
} else {
resolve(iframe);
}
});
}
export async function createOverlay(html) {
const iframe = await createIframe();
const isMounted = !!document.getElementById('not-found-frame');
if (!isMounted) {
document.body.appendChild(iframe);
}
iframe.contentDocument.body.innerHTML = html;
return iframe;
}