-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
MMM-SimpleLogo.js
60 lines (56 loc) · 1.98 KB
/
MMM-SimpleLogo.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
Module.register("MMM-SimpleLogo", {
// Default module config.
defaults: {
text: "Simple Logo",
fileUrl: "modules/MMM-SimpleLogo/public/logo.png",
width: "200px",
position: "left",
refreshInterval: 0
},
start: function() {
if (this.config.refreshInterval > 0) {
var self = this;
var imgsrc = self.config.fileUrl;
this.interval = setInterval(function() {
img = document.querySelector(".simple-logo__container img[src*='" + imgsrc + "']");
imgsrc = self.config.fileUrl;
if(!imgsrc.includes("?"))
imgsrc += '?' + Date.now();
else
imgsrc += '&' + Date.now();
img.setAttribute('src', imgsrc);
}, this.config.refreshInterval);
}
},
getStyles: function () {
return [
this.file('css/mmm-simplelogo.css')
];
},
notificationReceived: function(notification, payload) {
if (notification == "SIMPLE_LOGO_UPDATE") {
// stop auto-refresh (if any)
if (this.config.refreshInterval > 0) {
clearInterval(this.interval);
}
// update with new parameters
for (var attr in payload) this.config[attr] = payload[attr];
// restart auto-refresh (if any)
this.start();
this.updateDom();
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = 'simple-logo__container';
wrapper.classList.add(this.config.position);
wrapper.style.width = this.config.width;
var text = document.createTextNode(this.config.text);
wrapper.appendChild(text);
var img = document.createElement("img");
img.setAttribute('src', this.config.fileUrl);
wrapper.appendChild(img);
return wrapper;
}
});