-
Notifications
You must be signed in to change notification settings - Fork 18
/
Ω.js
124 lines (89 loc) · 2.13 KB
/
Ω.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
var Ω = (function() {
"use strict";
var preloading = true,
pageLoaded = false,
assetsToLoad = 0,
maxAssets = 0,
timers = [];
return {
evt: {
onloads: [],
progress: [],
onload: function(func) {
if (!pageLoaded) {
this.onloads.push(func);
} else {
// Page already loaded... so call it up.
func();
}
}
},
env: {
x: 0,
y: 0,
w: 0,
h: 0
},
preload: function (name) {
if (!preloading) {
return function () {
// console.log("preloading finished!", name);
};
}
maxAssets = Math.max(++assetsToLoad, maxAssets);
return function () {
assetsToLoad -= 1;
Ω.evt.progress.map(function (p) {
return p(assetsToLoad, maxAssets);
});
if (assetsToLoad === 0 && pageLoaded) {
if (!preloading) {
console.error("Preloading finished (onload called) multiple times!");
}
preloading = false;
Ω.evt.onloads.map(function (o) {
o();
});
}
};
},
pageLoad: function () {
pageLoaded = true;
if (maxAssets === 0 || assetsToLoad === 0) {
// No assets to load, so fire onload
preloading = false;
Ω.evt.onloads.map(function (o) {
o();
});
}
},
timers: {
add: function (timer) {
timers.push(timer);
},
tick: function () {
timers = timers.filter(function (t) {
return t.tick();
});
}
},
urlParams: (function () {
if (!window.location && !window.location.search) {
return {};
}
var params = {},
match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query)) {
params[decode(match[1])] = decode(match[2]);
}
return params;
}())
};
}());
// Polyfills
Array.isArray || (Array.isArray = function (a){ return '' + a !== a && {}.toString.call(a) == '[object Array]' });
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;