-
Notifications
You must be signed in to change notification settings - Fork 1
/
rendertest.html
88 lines (79 loc) · 2.76 KB
/
rendertest.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
<html>
<head>
<style>
img {
display: block;
}
</style>
</head>
<body>
<pre id="mycode">
<code>basic.showString("hello!")</code>
</pre>
<pre id="mycode2">
basic.showIcon(IconNames.Heart)
</pre>
<pre id="mycode3">
<code>
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="device_forever"></block>
</xml>
</code>
</pre>
<div id="status"></div>
<div id="blocks"></div>
<script>
function makeCodeInjectRenderer() {
var f = document.createElement("iframe");
f.id = "makecoderenderer";
f.style.position = "absolute";
f.style.left = 0;
f.style.bottom = 0;
f.style.width = "1px";
f.style.height = "1px";
f.src = "/--docs?render=1&lang=fr"
document.body.appendChild(f);
}
function makeCodeRenderPre(pre) {
var f = document.getElementById("makecoderenderer");
f.contentWindow.postMessage({
type: "renderblocks",
id: pre.id,
code: pre.innerText
}, "*");
}
window.addEventListener("message", function (ev) {
var msg = ev.data;
if (msg.source != "makecode") return;
switch (msg.type) {
case "renderready":
// makeCodeRenderPre(document.getElementById("mycode"))
makeCodeRenderPre(document.getElementById("mycode2"))
makeCodeRenderPre(document.getElementById("mycode3"))
break;
case "renderblocks":
console.log(msg);
var id = msg.id;
var code = document.getElementById(id)
// inject as svg
{
var svg = new DOMParser().parseFromString(msg.svg, "image/svg+xml");
img = svg.childNodes.item(0)
code.parentElement.insertBefore(img, code)
}
// inject as data uri
{
var img = document.createElement("img");
img.src = msg.uri;
img.width = msg.width;
img.height = msg.height;
code.parentElement.insertBefore(img, code)
}
code.parentElement.removeChild(code);
break;
}
}, false);
makeCodeInjectRenderer();
</script>
</body>
</html>