-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
148 lines (124 loc) · 3.91 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<style>
html,
body {
height: 100%;
width: 100%;
scrollbar-width: none;
-ms-overflow-style: none;
margin:0 auto;
}
table {
height: 100%;
width: 100%;
}
#shadow {
position: fixed;
width:120%;
height:120%;
z-index:3;
background:#000;
opacity: 0.3;
left:10px;
top: 10px;
}
#blocklyArea {
z-index:1;
}
#blocklyDiv {
z-index:1;
}
</style>
<script type="text/javascript" src="source/blockly_compressed.js"></script>
</head>
<body>
<table>
<tr>
<td id="blocklyArea"> </td>
<!--Blockly will be positioned here.-->
</tr>
</table>
<div id="blocklyDiv" style="position: absolute"></div>
<script>
const blocklyArea = document.getElementById('blocklyArea');
const blocklyDiv = document.getElementById('blocklyDiv');
var workspace;
function init(workspaceParam, xmlString) {
const workspaceJson = JSON.parse(workspaceParam);
workspace = Blockly.inject(blocklyDiv,
{
collapse: workspaceJson.Collapse,
toolbox: workspaceJson.Toolbox,
theme: workspaceJson.Theme,
grid:
{
spacing: workspaceJson.BlocklyGrid.Spacing,
length: workspaceJson.BlocklyGrid.Length,
colour: workspaceJson.BlocklyGrid.Colour,
snap: workspaceJson.BlocklyGrid.Snap
},
trashcan: workspaceJson.ShowTrashcan,
scrollbars: true,
render: workspaceJson.Render
}
);
}
function saveWorkspace(workspace) {
var xmlDom = Blockly.Xml.workspaceToDom(workspace);
var xmlText = Blockly.Xml.domToText(xmlDom);
localStorage.setItem("blockly.xml", xmlText);
}
function getSavedWorkspace(){
var xmlText = localStorage.getItem("blockly.xml");
return xmlText;
}
function loadSavedWorkspace(xml) {
if (xml) {
Blockly.mainWorkspace.clear();
xmlDom = Blockly.Xml.textToDom(xml);
Blockly.Xml.domToWorkspace(xmlDom, workspace);
}
}
function loadSrcs(...srcs) {
for (let i = 0; i < srcs.length; i++) {
loadSrc(srcs[i]);
}
}
function loadSrc(src) {
var s = document.createElement('script');
s.setAttribute('src', src);
document.head.appendChild(s);
}
function sendMessage(action, data)
{
var msgObject =
{
action: action,
data: data
};
var json = JSON.stringify(msgObject);
window.chrome.webview.postMessage(json);
}
const onresize = function (e) {
let element = blocklyArea;
let x = 0;
let y = 0;
do {
x += element.offsetLeft;
y += element.offsetTop;
element = element.offsetParent;
} while (element);
// Position blocklyDiv over blocklyArea.
blocklyDiv.style.left = x + 'px';
blocklyDiv.style.top = y + 'px';
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';
};
window.addEventListener('resize', onresize, false);
onresize();
</script>
</body>
</html>