-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
117 lines (104 loc) · 3.39 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Demo: Fixed Blockly</title>
<script src="../blockly/blockly_uncompressed.js"></script>
<script src="../blockly/blocks/variables.js"></script>
<script src="../blockly/blocks/math.js"></script>
<script src="../blockly/blocks/logic.js"></script>
<script src="../blockly/msg/js/en.js"></script>
<script src="./blocks/contract.js"></script>
<script src="./generators/solidity.js"></script>
<script src="./generators/solidity/contract.js"></script>
<script src="./generators/solidity/methods.js"></script>
<script src="./generators/solidity/logic.js"></script>
<script src="./generators/solidity/math.js"></script>
<style>
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
</style>
</head>
<body>
<div id="blocklyDiv" style="height: 480px; width: 100%;"></div>
<xml id="toolbox" style="display: none">
<block type="contract_state"></block>
<block type="contract_state_get"></block>
<block type="contract_state_set"></block>
<block type="contract_method"></block>
<block type="contract_method_parameter"></block>
<block type="contract_method_parameter_get"></block>
<block type="contract_ctor"></block>
<block type="contract_method_call"></block>
<block type="math_number"></block>
<block type="math_arithmetic"></block>
<block type="logic_boolean"></block>
<block type="logic_compare"></block>
<block type="controls_ifelse"></block>
<block type="controls_if"></block>
<block type="contract_method"></block>
<block type="contract_method_parameter"></block>
<block type="contract_method_parameter_get"></block>
<block type="logic_operation"></block>
<block type="math_arithmetic"></block>
</xml>
<textarea id="textarea" style="width:calc(34% - 10px);height:600px;float:right"></textarea>
<script>
var workspace = Blockly.inject(
'blocklyDiv',
{
media: '../blockly/media/',
toolbox: document.getElementById('toolbox'),
scrollbars: true,
zoom: {
controls: true
},
grid: {
spacing: 25,
length: 3,
colour: '#ccc',
snap: true
},
}
);
Blockly.Xml.domToWorkspace(
Blockly.Xml.textToDom(
'<xml><block type="contract" deletable="false" movable="false"></block></xml>'
),
workspace
);
var contractBlock = workspace.getTopBlocks()[0];
function setDisabledRec(block, disabled) {
block.setDisabled(disabled);
block.setMovable(true);
var children = block.getChildren();
for (var i = 0; i < children.length; i++) {
setDisabledRec(children[i], disabled);
}
}
function myUpdateFunction(event) {
var code = Blockly.Solidity.blockToCode(contractBlock);
var topBlocks = workspace.getAllBlocks();
for (var i = 0; i < topBlocks.length; ++i) {
var block = topBlocks[i];
if (contractBlock == block) {
continue;
}
if (!block.getParent()) {
setDisabledRec(block, true);
} else if (block.getParent() == contractBlock) {
setDisabledRec(block, false);
}
}
document.getElementById('textarea').value = code;
}
workspace.addChangeListener(myUpdateFunction);
</script>
</body>
</html>