Refactor the iframe generator
This commit is contained in:
parent
e04b254b48
commit
bcd57a6b22
|
@ -144,23 +144,20 @@ function playground_text(playground) {
|
||||||
.then(response => {
|
.then(response => {
|
||||||
result_block.innerText = "";
|
result_block.innerText = "";
|
||||||
var iframe = result_block.appendChild(document.createElement('iframe')),
|
var iframe = result_block.appendChild(document.createElement('iframe')),
|
||||||
doc = iframe.contentWindow.document,
|
doc = iframe.contentWindow.document;
|
||||||
options = {
|
iframe.id = "wasm-rendering";
|
||||||
objid: 152,
|
iframe.style.width = "100%";
|
||||||
key: 316541321
|
iframe.style.height = "100%";
|
||||||
},
|
var xhr = new XMLHttpRequest();
|
||||||
//src = "host/widget.js",
|
xhr.open('GET', 'iframe.html', true);
|
||||||
uri = encodeURIComponent(JSON.stringify(options));
|
xhr.onreadystatechange = function () {
|
||||||
doc.someVar = "Hello World!";
|
if (this.readyState !== 4) return;
|
||||||
iframe.id = "iframewidget";
|
if (this.status !== 200) return; // or whatever error handling you want
|
||||||
iframe.width = result_block.width;
|
var html = this.responseText;
|
||||||
iframe.height = result_block.height;
|
|
||||||
|
|
||||||
var html = '<body onload="var d=document;' +
|
|
||||||
'var script=d.createElement(\'script\');script.type=\'module\';script.src=\'wasm-test.js\';' +
|
|
||||||
'd.getElementsByTagName(\'head\')[0].appendChild(script);"><div id="button_click"></div></body>';
|
|
||||||
doc.open().write(html);
|
doc.open().write(html);
|
||||||
doc.close();
|
doc.close();
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
})
|
})
|
||||||
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!-- Code injected from iframe.html -->
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
// dynamically create script element and append to head
|
||||||
|
// call wasm-entry to load the built wasm.js
|
||||||
|
function body_onload() {
|
||||||
|
var d = document;
|
||||||
|
var script = d.createElement('script');
|
||||||
|
script.type = 'module';
|
||||||
|
script.src = 'wasm-entry.mjs';
|
||||||
|
d.getElementsByTagName('head')[0].appendChild(script);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="body_onload();">
|
||||||
|
<div id="_start"></div>
|
||||||
|
</body>
|
|
@ -0,0 +1,3 @@
|
||||||
|
import init from './wasm.js';
|
||||||
|
|
||||||
|
init();
|
Loading…
Reference in New Issue