-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmelon.js
100 lines (91 loc) · 2.87 KB
/
melon.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
/* global Module */
Module.register("melon", {
getTranslations() {
return {
en: 'translations/en.json',
de: 'translations/de.json',
kr: 'translations/kr.json'
};
},
defaults: {
updateInterval: 60 * 60 * 1000, //every 60 minutes
initialLoadDelay: 0,
colored: false,
fade: true,
fadePoint: 0.5,
fadeListBigger: 3,
cutLine: 5
},
start: function() {
Log.info("Starting module: " + this.name);
this.loaded = false;
this.chartData = {};
this.scheduleUpdate(this.config.initialLoadDelay);
},
getDom: function() {
var wrapper = document.createElement("div");
var table = document.createElement("table");
table.className = "small";
var heading = table.insertRow(0);
heading.insertCell(0).outerHTML = '<th>' + this.translate('TITLE') + '</th>';
heading.insertCell(1).outerHTML = '<th>' + this.translate('ARTIST') + '</th>';
heading.insertCell(2).outerHTML = '<th>' + this.translate('ALBUM') + '</th>';
for (var place in this.chartData.data) {
var chart = this.chartData.data[place];
var row = document.createElement("tr");
if (this.config.colored) {
row.className = "colored";
}
table.appendChild(row);
var titleCell = document.createElement("td");
titleCell.innerHTML = chart.title;
titleCell.className = "";
row.appendChild(titleCell);
var artistCell = document.createElement("td");
artistCell.innerHTML = chart.artist;
artistCell.className = "";
row.appendChild(artistCell);
var albumCell = document.createElement("td");
albumCell.innerHTML = chart.album;
albumCell.className = "";
row.appendChild(albumCell);
// Create fade effect.
if (this.config.fade && this.config.fadePoint < 1 && this.config.fadeListBigger < this.chartData.data.length) {
if (this.config.fadePoint < 0) {
this.config.fadePoint = 0;
}
var startingPoint = this.chartData.data.length * this.config.fadePoint;
var steps = this.chartData.data.length - startingPoint;
if (chart >= startingPoint) {
var currentStep = chart - startingPoint;
row.style.opacity = 1 - (1 / steps * currentStep);
}
}
}
return table;
},
updateMelon: function() {
this.sendSocketNotification("UPDATE", {
cutLine: this.config.cutLine
});
},
getStyles: function() {
return ["melon.css"];
},
socketNotificationReceived: function(notification, payload) {
if (notification === "UPDATE") {
this.chartData = payload.chartData;
this.updateDom();
}
},
scheduleUpdate: function(delay) {
var nextLoad = this.config.updateInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay;
}
var self = this;
setTimeout(function() {
self.updateMelon();
}, nextLoad);
}
});