-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
34 lines (29 loc) · 995 Bytes
/
index.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
<html>
<head>
<style>
/* you can style your program here */
</style>
</head>
<body>
<main>
<div id="outside"></div>
<div id="shadowHost"></div>
</main>
<script>
fetch('./elm.js')
.then(response => response.text())
.then(elmJS =>
{
const shadowRoot = document.querySelector('#shadowHost').attachShadow({mode: 'closed'});
shadowRoot.innerHTML = `<div id = 'outer-container'><div id = 'elm-will-replace'></div></div> `;
const patchedJS = elmJS.replace
('var node = document.getElementById(id);'
,'var node = appRoot.getRootNode().getElementById(id);');
const fakeElmScope = {};
new Function('appRoot', patchedJS).call(fakeElmScope, shadowRoot.getElementById('outer-container'));
var app = fakeElmScope.Elm.Main.init({ node: shadowRoot.getElementById('elm-will-replace') })
// you can use ports and stuff here
});
</script>
</body>
</html>