forked from ens-lg4/MenulyJSON
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
89 lines (68 loc) · 2.87 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A Blockly-based visual editor for JSON structures.</title>
<script type="text/javascript" src="blockly_compressed.js"></script>
<!-- context menu in English: -->
<script type="text/javascript" src="msg/js/en.js"></script>
<!-- a simple yet very practical widget: -->
<script type="text/javascript" src="field_textbutton.js"></script>
<!-- override/extend some Blockly code (menu-based building code): -->
<script type="text/javascript" src="menuly_override.js"></script>
<!-- blocks to build JSON structures from: -->
<script type="text/javascript" src="menuly_blocks.js"></script>
<!-- transforming a blockly diagram into a JSON string: -->
<script type="text/javascript" src="menuly_codegen.js"></script>
<!-- building a blockly diagram from a JSON string: -->
<script type="text/javascript" src="menuly_2blocks.js"></script>
<script>
function updateJSONarea() {
document.getElementById('json_area').value = Blockly.JSON.fromWorkspace( Blockly.getMainWorkspace() );
}
function interpretJSONarea() {
Blockly.JSON.toWorkspace( document.getElementById('json_area').value, Blockly.getMainWorkspace() );
}
</script>
<style>
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
</style>
</head>
<body>
<h1>An editor for <a href=http://www.json.org>JSON</a> structures made out of <a href="https://developers.google.com/blockly/">Blockly</a>-with-menus.</h1>
<br/>
<div style="height: 600px">
<div id="blocklyDiv" style="float: left; width: 74%; height: 100%"></div>
<xml id="toolbox" style="display: none">
<block type="dictionary"></block>
<block type="array"></block>
<block type="number"></block>
<block type="string"></block>
<block type="true"></block>
<block type="false"></block>
</xml>
<div style="margin-left: 74%; width: 24%; height: 100%">
<button onclick='interpretJSONarea()'>interpret JSON from the textarea below</button>
<textarea id=json_area style="height: 95%; width: 100%"></textarea>
</div>
</div>
<script>
Blockly.inject(document.getElementById('blocklyDiv'), {
//rtl: true,
toolbox: document.getElementById('toolbox'),
media: 'media/', // to avoid reaching to the web for icons
sound: false,
collapse: true, comments: true, disable: false, scrollbars: true, trashcan: true // those ones are automatically true when there are categories
});
Blockly.JSON.toWorkspace( 'null', Blockly.getMainWorkspace() ); // dogfooding: load the initial state using our own JSON converter
Blockly.addChangeListener(updateJSONarea);
</script>
</body>
</html>