-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
70 lines (63 loc) · 1.82 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo: Toolbox</title>
<style>
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
</style>
</head>
<body>
<p>Blockly for Mathematical Proofs</p>
<div id="blocklyDiv" style="height: 500px; width: 800px;"></div>
<xml id="toolbox" style="display: none">
<category name="Proof" id="categoryElement">
<block type="proof_by_contradiction"></block>
<block type="proof_by_induction"></block>
</category>
<sep></sep>
</xml>
<button onclick="checkBlocks()">
Check
</button>
<span id="answer">
<label>Answer is </label>
<input type="text" disabled="true" id="answerText"/>
</span>
<script src="js/blockly_compressed.js"></script>
<script src="js/blocks_compressed.js"></script>
<script src="js/msg/js/en.js"></script>
<script src="js/blocks/output.js"></script>
<script src="js/blocks/default_blocks.js"></script>
<script src="js/xmlHelper.js"></script>
<script>
var workspace = Blockly.inject('blocklyDiv',
{media: 'media/',
toolbox: document.getElementById('toolbox')});
function checkBlocks() {
var xml = Blockly.Xml.workspaceToDom(workspace);
var xml_text = Blockly.Xml.domToText(xml);
var parsedXML = parseXml(xml_text);
var blocksJSON = xml2json(parsedXML);
blocksJSON = JSON.parse(blocksJSON.replace("undefined", ""));
document.getElementById("answerText").value = processJSON(blocksJSON);
}
function processJSON(JSONObj) {
block = JSONObj.xml.block;
answer = []
while(block && block.next) {
answer.push(block.field.name);
block = block.next.block;
}
return answer.join(",");
}
</script>
</body>
</html>