-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
73 lines (64 loc) · 1.58 KB
/
lib.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
(function($) {
var Poller = function(options, callback) {
var defaults = {
frequency: 60,
limit: 10
};
this.callback = callback;
this.config = $.extend(defaults, options);
this.awesomeBands = [
'Creed',
'Godsmack',
'Hoobastank',
'Insane Clown Posse',
'Kid Rock',
'Limp Bizkit',
'Mudvayne',
'Nickelback',
'Puddle Of Mudd',
'Staind'
];
};
Poller.prototype.getRandomNumber = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
Poller.prototype.getData = function() {
var awesomeBand,
i,
len,
results = [];
for (i = 0, len = this.awesomeBands.length; i < len; i++) {
awesomeBand = this.awesomeBands[i];
results.push({
name: awesomeBand,
count: this.getRandomNumber(0, 2000)
});
}
return results;
};
Poller.prototype.processData = function() {
return this.sortData(this.getData()).slice(0, this.config.limit);
};
Poller.prototype.sortData = function(data) {
return data.sort(function(a, b) {
return b.count - a.count;
});
};
Poller.prototype.start = function() {
var _this = this;
this.interval = setInterval((function() {
_this.callback(_this.processData());
}), this.config.frequency * 1000);
this.callback(this.processData());
return this;
};
Poller.prototype.stop = function() {
clearInterval(this.interval);
return this;
};
if (window.massrel == null) {
window.massrel = {
Poller: Poller
};
}
}(jQuery));