-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpirkle.js
executable file
·53 lines (42 loc) · 1.18 KB
/
pirkle.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
(function (Pirkle) {
Pirkle.emptyFn = function () {};
Pirkle.queue = [];
Pirkle.queueFn = Pirkle.emptyFn;
Pirkle.load = function () {
var me = this,
argLength = arguments.length,
script,
newScript,
className,
i;
for (i = 0; i < argLength; i++) {
if (typeof arguments[i] !== "function") {
className = arguments[i];
newScript = document.createElement("script"),
script = document.getElementsByTagName("script")[0];
me.queue.push(className);
newScript.src="classes/" + className + '.js';
newScript.onload = function (name) {
return me.onLoad(name);
}(className);
script.parentNode.insertBefore(newScript, script);
} else {
me.queueFn = arguments[i];
me.onLoad();
}
}
};
Pirkle.onLoad = function (name) {
var me = this,
queueLength = me.queue.length;
while (queueLength--) {
if (me.queue[queueLength] === name) {
me.queue.splice(queueLength, 1);
}
}
if (me.queue.length === 0) {
me.queueFn();
me.queueFn = me.emptyFn;
}
};
}(window.Pirkle = window.Pirkle || {}));