-
Notifications
You must be signed in to change notification settings - Fork 5
/
editor.html
336 lines (292 loc) · 13.8 KB
/
editor.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>sulfurous</title>
<link rel=icon type="image/png" href="favicon.ico">
<link rel=stylesheet href=player.css>
<link rel=stylesheet href=index.css>
<title>Argon Editor</title>
<style>
html,
body {
height: 100%;
margin: 0;
}
body {
background-color: #fff;
font-family: sans-serif;
overflow: hidden;
}
h1 {
font-weight: normal;
font-size: 140%;
}
table {
height: 100%;
width: 100%;
}
#blocklyArea {
height: 99%;
background: #fc9;
text-align: center;
}
</style>
</head>
<body>
<table>
<tr>
<td>
<div class=area id=player-area>
<div class=controls>
<span class=stop></span>
<span class=pause></span>
<span class=flag title="Shift+click to enable turbo mode."></span>
<div class=turbo>Turbo Mode</div>
<span class=full-screen></span>
</div>
<div class=player></div>
<div id="blocklyDiv" style="height: 480px; width: 900px;"></div>
<div class=internal-error>
An internal error occurred. <a id=error-bug-link target=_blank href=https://github.com/mittagskogel/sulfurous/issues/new>Click here</a> to file a bug report.
</div>
</div>
<div class=title>
<div class=progress-bar></div>
<input class=url value=https://scratch.mit.edu/projects/>
<a target=_blank class=project-link title="View project on Scratch"></a>
</div>
<div class=area id=project-area>
</div>
</td>
</tr>
<tr>
<td id="blocklyArea">
Blockly will be positioned here.
</td>
</tr>
</table>
</body>
<script src=fonts.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.js></script>
<script src="blockly_compressed.js"></script>
<script src="blocks_motion.js"></script>
<script src="blocks_data.js"></script>
<script src="en.js"></script>
<script src=xml2json.js></script>
<script src=argon.js></script>
<script src=phosphorus.js></script>
<script src=player.js></script>
<script>
(function() {
'use strict';
var prefix = 'https://scratch.mit.edu/projects/';
var initialId = location.hash.substr(1);
if (initialId === 'zip') initialId = '';
var titleArea = document.querySelector('#title-area');
var playerArea = document.querySelector('#player-area');
var projectArea = document.querySelector('#project-area');
playerArea.style.height = projectArea.style.height = 'auto';
var titleAreaHeight = titleArea.offsetHeight;
var playerAreaHeight = playerArea.offsetHeight;
var projectAreaHeight = projectArea.offsetHeight;
playerArea.style.height = projectArea.style.height = 0;
var examples = document.querySelector('#examples');
var urlInput = document.querySelector('.url');
urlInput.value = prefix + initialId;
var progressBar = document.querySelector('.progress-bar');
var player = document.querySelector('.player');
var projectLink = document.querySelector('.project-link');
var bugLink = document.querySelector('#bug-link');
var packageLink = document.querySelector('#package-link');
var packageTurbo = document.querySelector('#package-turbo');
var packageFullScreen = document.querySelector('#package-full-screen');
var packageStandardResolution = document.querySelector('#package-standard-resolution');
var packageDoubleResolution = document.querySelector('#package-double-resolution');
var packageCustomResolution = document.querySelector('#package-custom-resolution');
var packageCustomResolutionValue = document.querySelector('#package-custom-resolution-value');
var embedCode = document.querySelector('#embed-code');
var embedAutoStart = document.querySelector('#embed-auto-start');
var embedLightContent = document.querySelector('#embed-light-content');
var embedHideControls = document.querySelector('#embed-hide-controls');
var embedStandardResolution = document.querySelector('#embed-standard-resolution');
var embedDoubleResolution = document.querySelector('#embed-double-resolution');
var embedCustomResolution = document.querySelector('#embed-custom-resolution');
var embedCustomResolutionValue = document.querySelector('#embed-custom-resolution-value');
var timeout;
urlInput.addEventListener('input', function() {
var ss = urlInput.selectionStart;
var se = urlInput.selectionEnd;
var url = urlInput.value;
var id = url.match(/\d+/g) || [''];
while (id.length > 1 && id.indexOf(P.player.projectId) > -1) {
id.splice(id.indexOf(P.player.projectId), 1);
}
id = id[0];
urlInput.value = url = prefix + id;
urlInput.selectionStart = urlInput.selectionEnd = Math.max(prefix.length, ss);
clearTimeout(timeout);
if (P.player.projectId !== id) {
timeout = setTimeout(function() {
location.hash = '#' + id;
}, 300);
}
});
urlInput.addEventListener('focus', function() {
setTimeout(function() {
if (/\d/.test(urlInput.value)) {
urlInput.select();
}
});
});
examples.addEventListener('change', function() {
if (examples.value) {
location.hash = '#' + examples.value;
examples.selectedIndex = 0;
}
});
window.addEventListener('hashchange', function() {
var id = location.hash.substr(1);
if (id !== 'zip') {
if (+id !== +id) id = '';
urlInput.value = prefix + id;
}
load(id);
});
function show(id) {
titleArea.style.height = id ? 0 : titleAreaHeight + 'px';
playerArea.style.height = id ? playerAreaHeight + 'px' : 0
projectArea.style.height = id ? projectAreaHeight + 'px' : 0;
if (!id) urlInput.focus();
}
function load(id) {
if (id !== 'zip') {
show(id);
}
else {
id = '';
}
document.title = 'sulfurous';
P.player.load(id, function(stage) {
stage.triggerGreenFlag();
}, function(title) {
document.title = title ? title + ' \xb7 sulfurous' : 'sulfurous';
updateBugLink();
});
projectLink.href = P.player.projectURL;
updateBugLink();
updatePackageLink();
updateEmbedCode();
}
function updateBugLink() {
bugLink.href = P.player.projectId ? 'https://github.com/mittagskogel/sulfurous/issues/new?title=' + encodeURIComponent(P.player.projectTitle || P.player.projectURL) + '&body=' + encodeURIComponent('\n\n\n' + P.player.projectURL + '\nhttps://newton.nes.aau.at/~sulfurous/#' + P.player.projectId + '\n' + navigator.userAgent) : 'https://github.com/mittagskogel/sulfurous/issues/new?body=' + encodeURIComponent('\n\n\n' + navigator.userAgent);
}
function updatePackageLink() {
if (packageFullScreen.checked) packageCustomResolutionValue.value = null;
if (packageStandardResolution.checked) packageCustomResolutionValue.value = 480;
if (packageDoubleResolution.checked) packageCustomResolutionValue.value = 960;
//remember to change the URL back to /app.html when putting this back online...
//packageLink.href = P.player.projectId ? 'file:///D:/Mittagskogel/Sulfurous/app.html?id=' + P.player.projectId + '&turbo=' + packageTurbo.checked + '&full-screen=' + packageFullScreen.checked + '&resolution-x=' + packageCustomResolutionValue.value: 'about:blank';
packageLink.href = P.player.projectId ? 'https://sulfurous.aau.at/~sulfurous/app.html?id=' + P.player.projectId + '&turbo=' + packageTurbo.checked + '&full-screen=' + packageFullScreen.checked + '&resolution-x=' + packageCustomResolutionValue.value : 'about:blank';
packageCustomResolutionValue.disabled = !packageCustomResolution.checked;
}
packageTurbo.addEventListener('change', updatePackageLink);
packageFullScreen.addEventListener('change', updatePackageLink);
packageStandardResolution.addEventListener('change', updatePackageLink);
packageDoubleResolution.addEventListener('change', updatePackageLink);
packageCustomResolution.addEventListener('change', updatePackageLink);
packageCustomResolutionValue.addEventListener('change', updatePackageLink);
function updateEmbedCode(e) {
if (embedStandardResolution.checked) embedCustomResolutionValue.value = 480;
if (embedDoubleResolution.checked) embedCustomResolutionValue.value = 960;
//remember to change the URL back to 'https://' + location.host when putting this back online...
//embedCode.value = P.player.projectId ? '<script src=file:///D:/Mittagskogel/Sulfurous' + '/embed.js?id=' + P.player.projectId + '&resolution-x=' + embedCustomResolutionValue.value + (embedHideControls.checked ? '&ui=false' : '&auto-start=' + embedAutoStart.checked + '&light-content=' + embedLightContent.checked) + '></' + 'script>' : '';
embedCode.value = P.player.projectId ? '<script src=https://sulfurous.aau.at/~sulfurous' + '/embed.js?id=' + P.player.projectId + '&resolution-x=' + embedCustomResolutionValue.value + (embedHideControls.checked ? '&ui=false' : '&auto-start=' + embedAutoStart.checked + '&light-content=' + embedLightContent.checked) + '></' + 'script>' : '';
embedCustomResolutionValue.disabled = !embedCustomResolution.checked;
embedAutoStart.disabled =
embedLightContent.disabled = embedHideControls.checked;
if (embedHideControls.checked) embedAutoStart.checked = true;
if (e) embedCode.focus();
}
function selectEmbedCode() {
setTimeout(function() {
embedCode.select();
});
}
embedCode.addEventListener('focus', selectEmbedCode);
embedCode.addEventListener('click', selectEmbedCode);
embedHideControls.addEventListener('change', updateEmbedCode);
embedAutoStart.addEventListener('change', updateEmbedCode);
embedLightContent.addEventListener('change', updateEmbedCode);
embedStandardResolution.addEventListener('change', updateEmbedCode);
embedDoubleResolution.addEventListener('change', updateEmbedCode);
embedCustomResolution.addEventListener('change', updateEmbedCode);
embedCustomResolutionValue.addEventListener('change', updateEmbedCode);
load(initialId);
setTimeout(function() {
function setTransition(el) {
el.style.WebkitTransition =
el.style.MozTransition =
el.style.OTransition =
el.style.transition = 'height 0.2s';
}
setTransition(titleArea);
setTransition(playerArea);
setTransition(projectArea);
});
function cancel(e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}
document.body.addEventListener('dragover', cancel);
document.body.addEventListener('dragenter', cancel);
document.body.addEventListener('drop', function(e) {
e.preventDefault();
var f = e.dataTransfer.files[0];
if (f) {
location.hash = '#zip';
show('zip');
var ext = f.name.split('.').pop();
if (ext === 'sb2' || ext === 'zip') {
var request = P.IO.loadSB2File(f);
}
else if (ext === 'json') {
request = P.IO.loadJSONFile(f);
}
if (request) {
P.player.showProgress(request, function(stage) {
stage.triggerGreenFlag();
});
}
}
});
}());
</script>
</html>
<xml id="toolbox" style="display: none">
<category name="Motion" colour="225">
<block type="forward:"></block>
<block type="turnRight:"></block>
<block type="turnLeft:"></block>
<block type="heading:"></block>
<block type="pointTowards:"></block>
<block type="gotoX:y:"></block>
<block type="gotoSpriteOrMouse:"></block>
<block type="glideSecs:toX:y:elapsed:from:"></block>
<block type="changeXposBy:"></block>
<block type="xpos:"></block>
<block type="changeYposBy:"></block>
<block type="ypos:"></block>
<block type="bounceOffEdge"></block>
<block type="setRotationStyle"></block>
<block type="xpos"></block>
<block type="ypos"></block>
<block type="heading"></block>
</category>
<category name="Data" colour="32">
<block type="input"></block>
<block type="variable"></block>
<block type="list"></block>
</category>
</xml>