-
Notifications
You must be signed in to change notification settings - Fork 4
/
jarTT.js
400 lines (365 loc) · 9.27 KB
/
jarTT.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
/*
* jarTT: A turntable.fm mod. Chris "inajar" Vickery <[email protected]>
* javascript:(function(){$.getScript('https://raw.github.com/chrisinajar/jarTT/master/jarTT.js');})();
*
* Redistribution and use in source, minified, binary, or any other forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name, jarTT, nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* No disclaimer, just don't be a dick.
*
*/
var oldJarTT = {};
var jarTTLoad = function(){};
(function() {
var baseUrl = "https://raw.github.com/chrisinajar/jarTT/master/";
if (localStorage.jarTT_devurl)
baseUrl = localStorage.jarTT_devurl;
/*********************************
****** THIRD PARTY MODULES ******
*********************************/
var modules = {
'flow': {
deps: [],
url: 'https://raw.github.com/chrisinajar/flow-js/master/flow.js',
options: {
noload: true
},
author: 'chrisinajar',
version: '1.0.0',
details: null
},
'bopomatic': {
deps: [], // doesn't use jarTT api..
url: 'https://turntablefm-autobop.googlecode.com/svn/trunk/ttfmautobop.js',
options: {
noload: true
},
author: 'Google',
version: '1.0.1',
details: null
},
'socket.io': {
deps: [],
url: 'http://chrisinajar.com:64277/socket.io/socket.io.js',
options: {
noload: true
},
author: null,
version: null,
details: null
},
'hivemind_raw': {
deps: ['socket.io', 'ttObjects'],
url: 'https://raw.github.com/chrisinajar/ttfm-hivemind/master/client.js',
options: {
noload: true
},
author: null,
version: null,
details: null
},
'ttObjects': {
deps: [],
url: 'https://raw.github.com/ttdevelopers/ttObjects/master/ttObjects.js',
options: {
noload: true,
required: true
},
author: null,
version: null,
details: null
},
// main jarTT, most of the code is here
'main': {
deps: ['ttObjects'],
url: baseUrl+ 'jarTT.main.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
// Ability to hook onto events along with the basic event driven stuff like idle timers
'events': {
deps: ['main'],
url: baseUrl+ 'jarTT.events.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
// Avatar related stuff, basically anything that uses identifyDiv
'avatar': {
deps: ['events'],
url: baseUrl+ 'jarTT.avatar.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
// HTML5 storage
'storage': {
deps: ['events'],
url: baseUrl+ 'jarTT.storage.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
// UI shit
'ui': {
deps: ['events', 'storage'],
url: baseUrl+ 'jarTT.ui.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
'version': {
deps: ['ui'],
url: baseUrl+ 'jarTT.version.js',
options: {
required: true
},
author: null,
version: null,
details: null
},
// hivemind realtime communication
'hivemind': {
deps: ['ttObjects', 'flow', 'events'],
url: baseUrl+ 'jarTT.hivemind.js',
options: {
},
author: null,
version: null,
details: null
},
'modulebrowser': {
deps: ['version'],
url: baseUrl+ 'jarTT.modulebrowser.js',
options: {
required: true
},
author: 'cannjeff',
version: '0.0.1',
details: ''
},
'testmodule': {
deps: ['modulebrowser'],
url: baseUrl+ 'exampleModule.js',
options: {
noload: true
},
author: 'Frank Smith',
version: '1.2.3',
details: null
},
'muteonlame': {
deps: ['events'],
url: baseUrl+ 'jarTT.muteonlame.js',
author: 'Pete Jones',
version: '0.0.1',
details: null
},
'customs': {
deps: ['avatar', 'events'],
url: baseUrl+ 'jarTT.customs.js',
author: 'Hulk Hogan',
version: '0.0.1',
details: null
}
/*
'songshare': {
deps: [],
url: 'https://raw.github.com/gist/75297cc418375d79b5ec/gistfile1.js',
author: 'Overra',
version: '1.0',
details: null,
options: {
noload: true
}
}
myplugin: {
deps: ['events', 'storage'],
url: https://github.com/chrisinajar/myplugin.js
},
*/
};
var autoLoad = [
'main',
'events',
'avatar',
'ui',
'storage',
'version',
'hivemind',
'muteonlame',
'modulebrowser',
'customs'
//'songshare'
];
if (localStorage.jarTT_modules) {
var module_ar = JSON.parse(localStorage.jarTT_modules);
autoLoad = autoLoad.concat(module_ar);
}
/*
* Load modules like this:
*
jarTTLoad.loadScript('http://www.awesomemod.com/test/awesomemod.js', 'awesomemod', function(){
jarTT.log("That worked!");
});
*
* You'll notice that it doesn't work, try this out though:
*
jarTT.settings.debug = true;
*
* There's no need to argue, parents just don't understand.
*/
// This file is just a big complicated loader.
// no longer true --v
// The majority of this code is creating an object called jarTTLoad which can take either an
// object or a string, and a success handler as the second parameter. The object works just like
// the "comp" variable like 10 lines down from here, and the string will just be a dependencyless string value
// that is loaded without any additional checking. Don't do that. I should probably make it private.
var wasLoaded = false;
// The following code is hideous, but makes the other code cleaner.
/* First we unload any existing jarTT instances */
if (typeof jarTT != "undefined" && jarTT != null) {
wasLoaded = true;
oldJarTT = jarTT;
jarTT.unload();
jarTT = null;
}
jarTTLoad = function(mod, cb) {
if (!cb)
cb = function(){};
if (mod in modules) {
jarTTLoad.dependency(mod, cb);
} else {
jarTTLoad.loadScript(baseUrl + 'jarTT.' + mod + '.js', mod, cb);
}
};
jarTTLoad.dependency = (function(c, h) {
if ($.inArray(c, jarTTLoad.ld) != -1)
h();
var module = modules[c];
var toLoad = []
for (var i = 0, l = module.deps.length; i<l; ++i) (function(i) {
if ($.inArray(module.deps[i], jarTTLoad.ld) == -1)
toLoad.push(module.deps[i]);
})(i);
var count = toLoad.length;
var complete = function() {
jarTTLoad.l(c, h);
};
if (count == 0)
return complete();
var cur = 0;
for (var i = 0; i < count; ++i) {
jarTTLoad.dependency(toLoad[i], function() {
cur++;
if (cur == count)
complete();
});
}
});
jarTTLoad.ld = []; // loaded
jarTTLoad.cl = {}; // currently loading
jarTTLoad.l = (function (name, cb, d) {
if (typeof name != "string")
return;
if (!isNaN(name))
return;
if ($.inArray(name, jarTTLoad.ld) != -1)
return cb?cb(d):null;
if (name in jarTTLoad.cl) {
var oldcb = jarTTLoad.cl[name];
jarTTLoad.cl[name] = function() {oldcb(); cb(d);};
return;
}
else
jarTTLoad.cl[name] = function() {cb(d);};
jarTTLoad.loadScript(modules[name].url, name, function() {
jarTTLoad.cl[name]();
delete jarTTLoad.cl[name];
}, modules[name].options);
});
// Code borrowed and altered from LABjs, http://labjs.com/
// Specifically: https://gist.github.com/603980
// Credit where credit is due.
jarTTLoad.loadScript = (function(script, name, h, options) {
var global = window;
var oDOC = document;
var head = oDOC.head || oDOC.getElementsByTagName("head");
options = options?options:{};
var handler = function() {
if (!options.noload)
jarTT[name].load();
jarTTLoad.ld.push(name);
h();
};
// Everything after this is stolen from LABjs, I never checked their license but lets just pretend it's definitely something friendly like GPL
// loading code borrowed directly from LABjs itself
setTimeout(function () {
if ("item" in head) { // check if ref is still a live node list
if (!head[0]) { // append_to node not yet ready
setTimeout(arguments.callee, 25);
return;
}
head = head[0]; // reassign from live node list ref to pure node ref -- avoids nasty IE bug where changes to DOM invalidate live node lists
}
var scriptElem = oDOC.createElement("script"),
scriptdone = false;
scriptElem.onload = scriptElem.onreadystatechange = function () {
if ((scriptElem.readyState && scriptElem.readyState !== "complete" && scriptElem.readyState !== "loaded") || scriptdone) {
return false;
}
scriptElem.onload = scriptElem.onreadystatechange = null;
scriptdone = true;
handler();
};
scriptElem.src = script + '?_=' + (new Date()).getTime();
head.insertBefore(scriptElem, head.firstChild);
}, 0);
// required: shim for FF <= 3.5 not having document.readyState
if (oDOC.readyState == null && oDOC.addEventListener) {
oDOC.readyState = "loading";
oDOC.addEventListener("DOMContentLoaded", handler = function () {
oDOC.removeEventListener("DOMContentLoaded", handler, false);
oDOC.readyState = "complete";
}, false);
}
});
(function(autoLoad) {
var count = autoLoad.length;
var cur = 0;
for (var i = 0; i < count; ++i) {
jarTTLoad(autoLoad[i], function() {
cur++;
if (cur == count) {
if (jarTT.modulebrowser)
jarTT.modulebrowser.modules = modules;
jarTT.events.dispatchEvent("jarTT_loaded");
}
});
};
})(autoLoad);
})();