-
Notifications
You must be signed in to change notification settings - Fork 479
/
brambleHost.js
826 lines (738 loc) · 24.2 KB
/
brambleHost.js
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
/* global requirejs */
/**
* JS to communicate between Bramble and Code Studio
*/
window.requirejs.config({
baseUrl: '/blockly/js/bramble/'
// DEVMODE: baseUrl: 'http://127.0.0.1:8000/src/'
});
// This is needed to support jQuery binary downloads
import '../assetManagement/download';
// the main Bramble object -- used to access file system
let bramble_ = null;
// the Bramble proxy object -- used to access methods on the Bramble UI frame
let brambleProxy_ = null;
// interface to Web Lab host in Code Studio
let webLab_ = null;
// the registered onProjectChanged callback function
let onProjectChangedCallback_ = null;
// the registered onBrambleMountable callback function
let onBrambleMountableCallback_ = null;
// the registered onBrambleReady callback function
let onBrambleReadyCallback_ = null;
// the registered onInspectorChanged callback function
let onInspectorChangedCallback_ = null;
// the set of recent changes since the last syncFilesWithBramble() called
let _recentBrambleChanges;
// the version id of the project at the time of the last bramble file sync
let _lastSyncedVersionId;
// Project root in file system
const weblabRoot = '/codedotorg/weblab';
function ensureProjectRootDirExists(callback) {
const fs = bramble_.getFileSystem();
const sh = new fs.Shell();
// create project root directory
sh.mkdirp(`${weblabRoot}/${currentProjectPath}`, err => {
if (err && err.code === 'EEXIST') {
// If it already exists, treat that as a success case
err = null;
}
callback(err);
});
}
function putFilesInBramble(sources, callback) {
const fs = bramble_.getFileSystem();
const sh = new fs.Shell();
const Path = bramble_.Filer.Path;
sh.rm(`${weblabRoot}/${currentProjectPath}`, {recursive: true}, err => {
// create project root directory
sh.mkdirp(`${weblabRoot}/${currentProjectPath}`, err => {
function writeFileDataAndContinue(filename, data, currentIndex) {
var path = Path.join(`${weblabRoot}/${currentProjectPath}`, filename);
// write the data
function onWriteComplete(err) {
if (err) {
// call completion callback
callback(err);
} else {
// force these writes into the _recentBrambleChanges log since the events take
// too long to appear (the later events will not be harmful):
_recentBrambleChanges.push({
operation: 'change',
file: filename,
fileDataPath: filename
});
// continue on to the next item on the list
writeSourceFile(currentIndex + 1);
}
}
if (typeof data === 'string') {
fs.writeFile(path, data, onWriteComplete);
} else {
fs.writeFile(path, data, {encoding: null}, onWriteComplete);
}
}
// async-chained enumeration: write the i-th file into Bramble file system
function writeSourceFile(currentIndex) {
if (currentIndex < sources.files.length) {
const file = sources.files[currentIndex];
if (!file.name) {
console.warn(`startSources file entry has no name property!`);
writeSourceFile(currentIndex + 1);
return;
}
if (file.url) {
if (file.data) {
console.warn(`startSources ${file.name} has both url and data!`);
}
// read the data from the URL
$.ajax(file.url, {
dataType: 'binary',
responseType: 'arraybuffer'
})
.done(data => {
writeFileDataAndContinue(
file.name,
new Buffer(data),
currentIndex
);
})
.fail((jqXHR, textStatus, errorThrown) => {
callback(errorThrown);
});
} else if (file.data) {
// write file data into Bramble
writeFileDataAndContinue(file.name, file.data, currentIndex);
} else {
console.warn(`startSources ${file.name} has neither url or data!`);
writeSourceFile(currentIndex + 1);
}
} else {
// end of list, call completion callback
callback(null);
}
}
if (err && err.code !== 'EEXIST') {
callback(err);
} else {
// start an async-chained enumeration through the file list
writeSourceFile(0);
}
});
});
}
function removeAllFilesInBramble(callback) {
const fs = bramble_.getFileSystem();
const sh = new fs.Shell();
sh.rm(`${weblabRoot}/${currentProjectPath}`, {recursive: true}, err => {
// create project root directory
sh.mkdirp(`${weblabRoot}/${currentProjectPath}`, err => {
if (err && err.code === 'EEXIST') {
err = null;
}
callback(err);
});
});
}
/*
* Get the file data for filename
* @param {string} filename
* @param {function} callback Function to call with error code and fileData
*/
function getFileData(filename, callback) {
const fs = bramble_.getFileSystem();
const Path = bramble_.Filer.Path;
const path = Path.join(`${weblabRoot}/${currentProjectPath}`, filename);
fs.readFile(path, {encoding: null}, callback);
}
function resetBrambleChangesAndProjectVersion(projectVersion) {
_recentBrambleChanges = [];
_lastSyncedVersionId = projectVersion;
}
function syncFilesWithBramble(fileEntries, currentProjectVersion, callback) {
const fs = bramble_.getFileSystem();
const Path = bramble_.Filer.Path;
const Buffer = bramble_.Filer.Buffer;
fileEntries = fileEntries || [];
var localChangeList = [];
function requestFileEntryAndWrite(fileEntry, callback) {
// read the data
$.ajax(`${fileEntry.url}?version=${fileEntry.versionId}`, {
dataType: 'binary',
responseType: 'arraybuffer'
})
.done(data => {
var path = Path.join(
`${weblabRoot}/${currentProjectPath}`,
fileEntry.name
);
// write the data
fs.writeFile(path, new Buffer(data), {encoding: null}, callback);
})
.fail((jqXHR, textStatus, errorThrown) => {
callback(errorThrown);
});
}
// async-chained enumeration: write the i-th file into Bramble file system
function writeFileEntry(i, callback) {
if (i < fileEntries.length) {
// request and write fileEntry data into Bramble
requestFileEntryAndWrite(fileEntries[i], err => {
if (err) {
// error, call completion callback
callback();
} else {
// continue on to the next item on the list
writeFileEntry(i + 1, callback);
}
});
} else {
// end of list, call completion callback
callback();
}
}
// async-chained enumeration: handle local file system changes and send them
// to the service
function handleLocalChange(i, callback) {
if (i < localChangeList.length) {
let change = localChangeList[i];
switch (change.operation) {
case 'delete':
webLab_.deleteProjectFile(change.file, (err, versionId) => {
if (err) {
callback();
} else {
_lastSyncedVersionId = versionId;
handleLocalChange(i + 1, callback);
}
});
break;
case 'rename':
webLab_.renameProjectFile(
change.file,
change.newFile,
(err, versionId) => {
if (err) {
callback();
} else {
_lastSyncedVersionId = versionId;
handleLocalChange(i + 1, callback);
}
}
);
break;
case 'change':
getFileData(change.fileDataPath, (err, fileData) => {
if (err) {
callback();
} else {
webLab_.changeProjectFile(
change.file,
fileData,
(err, versionId) => {
if (err) {
callback();
} else {
_lastSyncedVersionId = versionId;
handleLocalChange(i + 1, callback);
}
}
);
}
});
break;
default:
console.error('Bramble host: unknown local change');
callback();
}
} else {
callback();
}
}
if (_lastSyncedVersionId !== currentProjectVersion) {
if (_recentBrambleChanges.length > 0) {
console.warn(
'Bramble host: recent changes ignored and replaced by service changes!'
);
}
resetBrambleChangesAndProjectVersion(currentProjectVersion);
// Cancel any beforewrite hook that we may have registered, because we are
// now treating the service as the source of truth:
webLab_.registerBeforeFirstWriteHook(null);
// Changes on the server, rebuild from the fileEntries supplied:
removeAllFilesInBramble(err => {
if (err) {
callback();
} else {
// start an async-chained enumeration through the fileEntries list
writeFileEntry(0, callback);
}
});
} else {
// Copy _recentBrambleChanges into localChangeList before resetting it:
localChangeList = _recentBrambleChanges;
resetBrambleChangesAndProjectVersion(currentProjectVersion);
// If the copied localChangeList was populated, start handling it here:
handleLocalChange(0, callback);
}
}
function validateProjectChanged(callback) {
getAllFileDataFromBramble((userFiles, error) => {
const startSources = webLab_.getStartSources();
// Don't let an error from bramble block the student from progressing.
if (error || userFiles.files.length !== startSources.files.length) {
callback(true /* project changed */);
return;
}
const changedFile = startSources.files.find(startFile => {
const matchingFile = userFiles.files.find(
file => file.name === startFile.name
);
// If startFile doesn't have `data` (and instead has something different
// like `url`), this is an image and is stored differently in the
// startSources than in bramble. Check for a matching file name, but
// don't compare data.
// Regex: Compare without whitespace.
return (
!matchingFile ||
(startFile.data &&
startFile.data.replace(/\s+/g, '') !==
matchingFile.data.replace(/\s+/g, ''))
);
});
callback(!!changedFile);
});
}
function getAllFileDataFromBramble(callback) {
const fs = bramble_.getFileSystem();
const sh = new fs.Shell();
const allFileData = [];
// enumerate files in the file system off the project root
sh.ls(`${weblabRoot}/${currentProjectPath}`, function(err, entries) {
// async-chained enumeration: get the file data for i-th file
function getEntryFileData(i, callback, err) {
if (err) {
callback(null, err);
return;
}
if (i < entries.length) {
const entry = entries[i];
getFileData(entry.path, (err, fileData) => {
// also get the file name
allFileData.push({name: entry.path, data: fileData.toString()});
getEntryFileData(i + 1, callback, err);
});
} else {
// end of list, call completion callback
callback({files: allFileData});
}
}
// start an async-chained enumeration through the file list
getEntryFileData(0, callback, err);
});
}
function uploadAllFilesFromBramble(callback) {
const fs = bramble_.getFileSystem();
const sh = new fs.Shell();
// enumerate files in the file system off the project root
sh.ls(`${weblabRoot}/${currentProjectPath}`, function(err, entries) {
// async-chained enumeration: get the file data for i-th file
function getEntryFileData(i, callback) {
if (i < entries.length) {
const entry = entries[i];
getFileData(entry.path, (err, fileData) => {
// Always call the callback. If err is undefined, the callback will handle it gracefully.
callback(err);
if (!err) {
webLab_.changeProjectFile(
entry.path,
fileData,
(err, versionId) => {
callback(err);
if (!err) {
_lastSyncedVersionId = versionId;
getEntryFileData(i + 1, callback);
}
},
true /* skipPreWriteHook - because we are calling from within the preWriteHook */
);
}
});
} else {
// end of list, call completion callback
callback(null, true /* preWriteHook was successful */);
}
}
if (err) {
callback(err);
} else {
// start an async-chained enumeration through the file list
getEntryFileData(0, callback);
}
});
}
function addFileHTML() {
brambleProxy_.addNewFile(
{
basenamePrefix: 'new',
ext: 'html',
contents:
'<!DOCTYPE html>\n<html>\n <head>\n \n </head>\n <body>\n \n </body>\n</html>'
},
err => {
if (err) {
throw err;
}
}
);
}
function addFileCSS() {
brambleProxy_.addNewFile(
{
basenamePrefix: 'new',
ext: 'css',
contents:
'body {\n background: white;\n}\np {\n color: black;\n}\nh1 {\n font-weight: bold;\n}'
},
err => {
if (err) {
throw err;
}
}
);
}
function undo() {
brambleProxy_.undo();
}
function redo() {
brambleProxy_.redo();
}
function hideTutorial() {
brambleProxy_.hideTutorial();
}
function showTutorial() {
brambleProxy_.showTutorial();
}
function enableInspector() {
brambleProxy_.enableInspector();
}
function disableInspector() {
brambleProxy_.disableInspector();
}
function refreshPreview() {
brambleProxy_.refreshPreview();
}
function enableFullscreenPreview(callback) {
brambleProxy_.enableFullscreenPreview(callback);
}
function disableFullscreenPreview(callback) {
brambleProxy_.disableFullscreenPreview(callback);
}
function onProjectChanged(callback) {
onProjectChangedCallback_ = callback;
}
function onBrambleMountable(callback) {
onBrambleMountableCallback_ = callback;
}
function onBrambleReady(callback) {
onBrambleReadyCallback_ = callback;
}
function onInspectorChanged(callback) {
onInspectorChangedCallback_ = callback;
}
var hasMounted_ = false;
function ensureMounted() {
if (!hasMounted_) {
bramble_.mount(`${weblabRoot}/${currentProjectPath}`);
}
hasMounted_ = true;
}
function startInitialFileSync(callback, forceResetToStartSources) {
ensureProjectRootDirExists(err => {
const wrappedCallback = err => {
ensureMounted();
callback(err);
};
if (err) {
wrappedCallback(err);
return;
}
const currentProjectVersion = webLab_.getCurrentFilesVersionId();
if (!currentProjectVersion || forceResetToStartSources) {
// Get initial sources to put in file system
const startSources = webLab_.getStartSources();
// Sync what's on the service locally (should be nothing, but this ensures
// our _lastSyncedVersionId matches before we make changes)
syncFiles(err => {
if (err) {
console.warn(
`Bramble host: Initial syncFiles failed with error: ${err}`
);
}
// put the source files into the Bramble file system
putFilesInBramble(startSources, err => {
if (!err && !forceResetToStartSources) {
// First-time level load - no project versionId
// Ignore all of the change events that just occured as we wrote the
// startSources into bramble - there is no need to save these during
// sync until a user-initiated change occurs
resetBrambleChangesAndProjectVersion(currentProjectVersion);
webLab_.registerBeforeFirstWriteHook(uploadAllFilesFromBramble);
}
// Start the initial files sync
syncFiles(wrappedCallback);
});
});
} else {
syncFiles(wrappedCallback);
}
});
}
function syncFiles(callback) {
// Get current fileEntries to put in file system
const currentFileEntries = webLab_.getCurrentFileEntries();
const currentProjectVersion = webLab_.getCurrentFilesVersionId();
syncFilesWithBramble(currentFileEntries, currentProjectVersion, callback);
}
// Init change list and version structures
resetBrambleChangesAndProjectVersion();
// Get the WebLab object from our parent window
if (parent.getWebLab) {
webLab_ = parent.getWebLab();
} else {
console.error('ERROR: getWebLab() method not found on parent');
}
// expose object for parent window to talk to us through
const brambleHost = {
// return file data from the Bramble editor
addFileHTML,
addFileCSS,
undo,
redo,
hideTutorial,
showTutorial,
enableInspector,
disableInspector,
refreshPreview,
enableFullscreenPreview,
disableFullscreenPreview,
onProjectChanged,
onBrambleMountable,
onBrambleReady,
onInspectorChanged,
startInitialFileSync,
syncFiles,
validateProjectChanged
};
// Give our interface to our parent
var currentProjectPath = webLab_.setBrambleHost(brambleHost);
var removeProjectRootRegex = new RegExp(
`^\\/codedotorg\/weblab\/${currentProjectPath}\/`,
'g'
);
function load(Bramble) {
bramble_ = Bramble;
Bramble.load('#bramble', {
url:
'//downloads.computinginthecore.org/bramble_0.1.26/index.html?disableExtensions=bramble-move-file',
// DEVMODE: INSECURE (local) url: "../blockly/js/bramble/index.html?disableExtensions=bramble-move-file",
// DEVMODE: INSECURE url: "http://127.0.0.1:8000/src/index.html?disableExtensions=bramble-move-file",
useLocationSearch: true,
disableUIState: true,
initialUIState: {
theme: 'light-theme',
readOnly: webLab_.getPageConstants().isReadOnlyWorkspace
}
});
// Event listeners
Bramble.on('readyStateChange', (_, newState) => {
if (Bramble.MOUNTABLE === newState) {
if (onBrambleMountableCallback_) {
onBrambleMountableCallback_();
onBrambleMountableCallback_ = null;
}
}
});
Bramble.once('ready', function(bramble) {
function handleInspectorChange(object) {
if (onInspectorChangedCallback_) {
onInspectorChangedCallback_(object && object.enabled);
}
}
function handleFileChange(path) {
// Remove leading project root path
var cleanedPath = path.replace(removeProjectRootRegex, '');
// If a 'change' operation is already queued for the same file, return
const hasExistingChangeForPath = _recentBrambleChanges.some(
change => change.operation === 'change' && change.file === cleanedPath
);
if (!hasExistingChangeForPath) {
_recentBrambleChanges.push({
operation: 'change',
file: cleanedPath,
fileDataPath: cleanedPath
});
}
if (onProjectChangedCallback_) {
onProjectChangedCallback_();
}
}
function handleFileDelete(path) {
// Remove leading project root path
var cleanedPath = path.replace(removeProjectRootRegex, '');
_recentBrambleChanges.push({
operation: 'delete',
file: cleanedPath
});
if (onProjectChangedCallback_) {
onProjectChangedCallback_();
}
}
function handleFileRename(oldFilename, newFilename) {
// Remove leading project root paths
var cleanedOldFilename = oldFilename.replace(removeProjectRootRegex, '');
var cleanedNewFilename = newFilename.replace(removeProjectRootRegex, '');
// Update the fileDataPath for any pending 'change' operations (new or modified files)
for (var i = 0; i < _recentBrambleChanges.length; i++) {
let change = _recentBrambleChanges[i];
if (
change.operation === 'change' &&
change.fileDataPath === cleanedOldFilename
) {
change.fileDataPath = cleanedNewFilename;
}
}
_recentBrambleChanges.push({
operation: 'rename',
file: cleanedOldFilename,
newFile: cleanedNewFilename
});
if (onProjectChangedCallback_) {
onProjectChangedCallback_();
}
}
function handleFolderRename(paths) {
if (onProjectChangedCallback_) {
onProjectChangedCallback_();
}
}
bramble.on('inspectorChange', handleInspectorChange);
bramble.on('fileChange', handleFileChange);
bramble.on('fileDelete', handleFileDelete);
bramble.on('fileRename', handleFileRename);
bramble.on('folderRename', handleFolderRename);
brambleProxy_ = bramble;
if (onBrambleReadyCallback_) {
onBrambleReadyCallback_();
}
});
Bramble.once('error', function(err) {
// Send to New Relic
webLab_.addPageAction(webLab_.PageAction.BrambleError, {
error: err && err.message
});
console.error('Bramble error', err);
if (err && err.code === 'EFILESYSTEMERROR') {
modalError(
`We're sorry, Web Lab failed to load for some reason. ${SUPPORT_ARTICLE_HTML}`,
Bramble
);
} else {
modalError(
`Fatal Error: ${
err.message
}. If you're in Private Browsing mode, data can't be written. ${SUPPORT_ARTICLE_HTML}`,
Bramble
);
}
});
Bramble.on('readyStateChange', function(previous, current) {});
startInitialFileSync(() => {});
}
const SUPPORT_ARTICLE_URL =
'https://support.code.org/hc/en-us/articles/360016804871';
const SUPPORT_ARTICLE_HTML = `Please see our support article <a href="${SUPPORT_ARTICLE_URL}">"Troubleshooting Web Lab problems"</a> for more information.`;
// Custom modal for handling Bramble initialization errors and pointing users to our support article.
function modalError(message, Bramble, showButtons = true) {
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = 0;
overlay.style.left = 0;
overlay.style.right = 0;
overlay.style.bottom = 0;
overlay.style.display = 'flex';
overlay.style.flexDirection = 'column';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.75)';
function reloadWebLab() {
parent.location.reload();
}
function hideModal() {
document.body.removeChild(overlay);
}
function resetBrambleFilesystem() {
hideModal();
if (Bramble) {
Bramble.formatFileSystem(err => {
if (err) {
webLab_.addPageAction(
webLab_.PageAction.BrambleFilesystemResetFailed,
{
error: err && err.message
}
);
// Unable to create filesystem, fatal (and highly unlikely) error
modalError(
`Failed to reset Web Lab. ${err.message}. ${SUPPORT_ARTICLE_HTML}`,
Bramble
);
} else {
webLab_.addPageAction(
webLab_.PageAction.BrambleFilesystemResetSuccess,
{}
);
// filesystem is now clean and empty, use Bramble.getFileSystem() to obtain instance
modalError(`Web Lab reset complete. Reloading...`, Bramble, false);
reloadWebLab();
}
});
} else {
modalError(
`An unexpected error occurred (Bramble not found). ${SUPPORT_ARTICLE_HTML}`
);
}
}
const messageBox = document.createElement('div');
messageBox.style.backgroundColor = 'white';
messageBox.style.border = 'solid black medium';
messageBox.style.padding = '1em';
messageBox.style.maxWidth = '50%';
messageBox.style.borderRadius = '1em';
overlay.appendChild(messageBox);
const messageDiv = document.createElement('div');
messageDiv.innerHTML = message;
messageBox.appendChild(messageDiv);
function button(text, callback) {
const button = document.createElement('button');
button.innerHTML = text;
button.onclick = callback;
button.style.margin = '0.5em';
return button;
}
if (showButtons) {
const buttons = document.createElement('div');
buttons.style.textAlign = 'center';
buttons.style.marginTop = '1em';
buttons.appendChild(button('Try again', reloadWebLab));
buttons.appendChild(button('Reset Web Lab', resetBrambleFilesystem));
buttons.appendChild(button('Dismiss', hideModal));
messageBox.appendChild(buttons);
}
document.body.appendChild(overlay);
}
// Load bramble.js
requirejs(['bramble'], function(Bramble) {
// DEVMODE: requirejs(["bramble/client/main"], function (Bramble) {
load(Bramble);
});