-
Notifications
You must be signed in to change notification settings - Fork 15
/
fikascript.browser.js
88 lines (79 loc) · 2.26 KB
/
fikascript.browser.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
FikaScript.load = function(url, callback, options) {
var xhr;
if (options == null) {
options = {};
}
options.sourceFiles = [url];
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest();
xhr.open('GET', url, true);
if ('overrideMimeType' in xhr) {
xhr.overrideMimeType('text/plain');
}
xhr.onreadystatechange = function() {
var _ref;
if (xhr.readyState === 4) {
if ((_ref = xhr.status) === 0 || _ref === 200) {
FikaScript.run(xhr.responseText, options);
} else {
throw new Error("Could not load " + url);
}
if (callback) {
return callback();
}
}
};
return xhr.send(null);
};
FikaScript.run = function(code, options) {
if (options == null) {
options = {};
}
options.bare = true;
options.shiftLine = true;
return Function(compile(code, options))();
};
if (typeof window === "undefined" || window === null) {
return;
}
compile = function(code, options) {
return FikaScript.swedishToEnglish(code);
}
var runScripts,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
runScripts = function() {
var fikas, fikatypes, execute, index, length, s, scripts;
scripts = window.document.getElementsByTagName('script');
fikatypes = ['text/fikascript'];
fikas = (function() {
var _i, _len, _ref, _results;
_results = [];
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
s = scripts[_i];
if (_ref = s.type, __indexOf.call(fikatypes, _ref) >= 0) {
_results.push(s);
}
}
return _results;
})();
index = 0;
length = fikas.length;
(execute = function() {
var mediatype, options, script;
script = fikas[index++];
mediatype = script != null ? script.type : void 0;
if (__indexOf.call(fikatypes, mediatype) >= 0) {
if (script.src) {
return FikaScript.load(script.src, execute, options);
} else {
FikaScript.run(script.innerHTML, options);
return execute();
}
}
})();
return null;
};
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', runScripts, false);
} else {
window.attachEvent('onload', runScripts);
}