-
Notifications
You must be signed in to change notification settings - Fork 1
/
codeembed.html
140 lines (127 loc) · 4.53 KB
/
codeembed.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<style>
body {
background: transparent;
}
a,
a:visited {
text-decoration: none !important;
}
body a svg {
width: calc(100% - 1rem);
height: calc(100% - 3rem);
}
footer {
position: absolute;
bottom: 0;
height: 1.3rem;
background: #ccc;
text-align: right;
color: white;
font-size: 0.7rem;
font-family: consolas;
left: 0;
right: 0;
padding-top: 0.5rem;
padding-right: 1rem;
}
footer a, footer a:visited {
color: white;
}
</style>
<body>
<div id="blocks"></div>
<footer class="ui horizontal small divided link list footer">
<a target="_blank" class="item" href="https://makecode.com">Microsoft MakeCode</a>
<a target="_blank" class="item" href="https://makecode.com/termsofuse">Terms of Use </a>
<a target="_blank" class="item" href="https://makecode.com/privacy">Privacy </a>
</footer>
<script id="loader">
// This line gets patched up by the cloud
var pxtConfig = {
"relprefix": "/pxt-microbit-test/",
"verprefix": "",
"workerjs": "/pxt-microbit-test/worker.js",
"monacoworkerjs": "/pxt-microbit-test/monacoworker.js",
"gifworkerjs": "/pxt-microbit-test/gifjs/gif.worker.js",
"serviceworkerjs": "/pxt-microbit-test/serviceworker.js",
"pxtVersion": "5.37.42",
"pxtRelId": "",
"pxtCdnUrl": "/pxt-microbit-test/",
"commitCdnUrl": "/pxt-microbit-test/",
"blobCdnUrl": "/pxt-microbit-test/",
"cdnUrl": "/pxt-microbit-test/",
"targetVersion": "0.0.0",
"targetRelId": "",
"targetUrl": "",
"targetId": "microbit",
"simUrl": "/pxt-microbit-test/simulator.html",
"simserviceworkerUrl": "/pxt-microbit-test/simulatorserviceworker.js",
"simworkerconfigUrl": "/pxt-microbit-test/workerConfig.js",
"partsUrl": "/pxt-microbit-test/siminstructions.html",
"runUrl": "/pxt-microbit-test/run.html",
"docsUrl": "/pxt-microbit-test/docs.html",
"multiUrl": "/pxt-microbit-test/multi.html",
"isStatic": true
};
// handle to rendering iframe
var pxtFrame;
// ....#pub:projectid
var projectid = /pub:([^&?]+)/i.exec(window.location.hash)[1];
function makeCodeInjectRenderer() {
pxtFrame = document.createElement("iframe");
pxtFrame.id = "makecoderenderer";
pxtFrame.style.position = "absolute";
pxtFrame.style.left = 0;
pxtFrame.style.bottom = 0;
pxtFrame.style.width = "1px";
pxtFrame.style.height = "1px";
pxtFrame.src = (pxtConfig ? pxtConfig.docsUrl : '---docs') + '?render=1';
document.body.appendChild(pxtFrame);
}
function makeCodeRenderPre(elid, pid) {
var f = document.getElementById("makecoderenderer");
f.contentWindow.postMessage({
type: "renderblocks",
id: elid,
options: {
packageId: pid
}
}, "*");
}
function removeEl(el) {
if (el && el.parentElement) el.parentElement.removeChild(el);
}
window.addEventListener("message", function (ev) {
var msg = ev.data;
if (msg.source != "makecode") return;
switch (msg.type) {
case "renderready":
makeCodeRenderPre("blocks", projectid)
break;
case "renderblocks":
var id = msg.id;
if (msg.svg) {
var svg = new DOMParser().parseFromString(msg.svg, "image/svg+xml");
var img = svg.childNodes.item(0)
var code = document.getElementById(id)
var a = document.createElement("a")
a.target = "_blank"
a.href = (pxtConfig ? pxtConfig.targetUrl : "") + "/#pub:" + projectid;
a.appendChild(img)
code.parentElement.insertBefore(a, code)
code.parentElement.removeChild(code);
}
// unload iframe
if (pxtFrame) {
removeEl(pxtFrame);
removeEl(document.getElementById("loader"));
pxtFrame = undefined;
}
break;
}
}, false);
makeCodeInjectRenderer();
</script>
</body>
</html>