-
Notifications
You must be signed in to change notification settings - Fork 5
/
arc_loader.js
51 lines (48 loc) · 1.38 KB
/
arc_loader.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
$(function () {
var runner = ArcJS.context();
var codes = $('script[type="text/arc"]').map(function(i, v) {
var inner = v.innerText;
var src = v.src;
return {script: inner, src: src};
});
var fasls = $('script[type="text/arc-fasl"]').map(function(i, v) {
var inner = v.innerText;
var src = v.src;
return {script: inner, src: src};
});
function iter(codes, i, type, after) {
if (i < codes.length) {
var script = codes[i].script
var src = codes[i].src;
if (src) {
$.ajax({
url: src,
dataType: 'text'
}).done(function(data){
var fasl;
switch(type) {
case 'fasl':
eval('var fasl = (function() {\nvar preloads = [], preload_vals = [];\n' +
data +
'return {preloads: preloads, preload_vals: preload_vals};\n})();');
ArcJS.fasl_loader(ArcJS.NameSpace.get('user'), fasl.preloads, fasl.preload_vals);
break;
case 'arc':
runner.evaluate(data);
break;
}
if (script) runner.evaluate(script);
iter(codes, i+1, type, after);
});
} else {
if (script) runner.evaluate(script);
iter(codes, i+1, type, after);
}
} else {
if (after) after();
}
}
iter(fasls, 0, 'fasl', function() {
iter(codes, 0, 'arc');
});
});