forked from microsoft/pxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrendertest.html
More file actions
71 lines (62 loc) · 2.21 KB
/
rendertest.html
File metadata and controls
71 lines (62 loc) · 2.21 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<body>
<pre id="mycode">
basic.showString("hello!")
</pre>
<pre id="mycode2">
basic.showIcon(IconNames.Heart)
</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"))
break;
case "renderblocks":
console.log(msg);
var id = msg.id;
var img;
var injectAsSvg = true;
if (injectAsSvg) {
var svg = new DOMParser().parseFromString(msg.svg, "image/svg+xml");
img = svg.childNodes.item(0)
} else {
img = document.createElement("img");
img.src = msg.uri;
img.width = msg.width;
img.height = msg.height;
}
var code = document.getElementById(id)
code.parentElement.insertBefore(img, code)
code.parentElement.removeChild(code);
break;
}
}, false);
makeCodeInjectRenderer();
</script>
</body>
</html>