-
Notifications
You must be signed in to change notification settings - Fork 52
/
easySetup.js
70 lines (61 loc) · 1.79 KB
/
easySetup.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
/*
Easy setup add on
*/
(function(exports,$){
"use strict";
var opt = {},
elems = {},
stats = false,
played = false,
$ul, $script= $('script').last();
//basically read the url of the script to check for options
(function(){
var uri = $script.attr('src');
var options = uri.replace(/.*\?/,'');
if(options === uri){
return;
}
$.each(options.split('&'),function(i,o){
o = o.split('=');
if(o.length === 2){
opt[o[0]] = o[1];
}
});
}());
if(!opt.host){
return;
}
//if a value has been passed in the url then show that value wherever the script was inserted
opt.value && (function(){
//if value is played then add a ul otherwise add a p
opt.value === 'played' ? $script.after('<ul id="played"></ul>') : $script.after('<p data-shoutcast-value="'+opt.value+'"></p>');
}());
opt.playedInterval = opt.playedInterval || 30000;
opt.statsInterval = opt.statsInterval || 5000;
//get all items which want shoutcast stats
$('[data-shoutcast-value]').each(function(i,item){
item = $(item);
elems[item.data('shoutcast-value')] = item;
});
stats = !$.isEmptyObject(elems);
$ul = $('#played');
played = !!$ul.length;
//only update stats if there are items
stats && (opt.stats = function(){
var i;
for(i in elems){if(elems.hasOwnProperty(i)){
elems[i].text(this.get(i));
}}
});
//only update played if there is #played
played && (opt.played = function(tracks){
var html = '';
$.each(tracks,function(i,track){
html+='<li>'+track.title+'</li>';
});
$ul.html(html);
});
exports.SHOUTcast = $.SHOUTcast(opt);
stats && exports.SHOUTcast.startStats();
played && exports.SHOUTcast.startPlayed();
}(window,window.jQuery));