-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
55 lines (48 loc) · 1.58 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo: Resizable Blockly (Part 2)</title>
<script src="blockly_accessible_compressed.js"></script>
<script src="blocks_compressed.js"></script>
<!--<script src="demos/code/msg/en.js"></script>-->
<script src="msg/js/en.js"></script>
</head>
<body>
<div id="blocklyDiv" style="height: 768px; width: 1024px;"></div>
<xml id="toolbox" style="display: none">
<category id="ffplugins" name="ffplugins"></category>
</xml>
<script>
/**
* @return {string}
*/
function Get(yourUrl) {
const Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET", yourUrl, false);
Httpreq.send(null);
return Httpreq.responseText;
}
const ff = JSON.parse(Get("x.json"));
const ff2 = ff["model"];
const used = [];
const pluginsParent = document.getElementById("ffplugins");
ff2.map(function (k) {
let k3 = k["type"];
let prefix = `${k.previousStatement}->${k.nextStatement}` ;
if (!used[prefix]) {
const element = document.createElement("category");
element.setAttribute("name", prefix);
used[prefix] = element;
pluginsParent.appendChild(element)
}
let element2 = document.createElement("block");
element2.setAttribute("type", k3);
used[prefix].appendChild(element2);
});
Blockly.defineBlocksWithJsonArray(ff2);
const workspace = Blockly.inject('blocklyDiv',
{toolbox: document.getElementById('toolbox')});
</script>
</body>
</html>