-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-Profilepicture.js
executable file
·79 lines (72 loc) · 2.42 KB
/
MMM-Profilepicture.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
/* global Module */
/* Magic Mirror
* Module: MMM-Profilepicture
*
* By Erik Pettersson - http://www.snille.net
* MIT Licensed.
*/
Module.register("MMM-Profilepicture",{
requiresVersion: "2.1.0",
defaults: {
// Transparency of the picture.
opacity: 0.2,
// Maximum width of the picture.
maxWidth: "100%",
// Maximum height of the picture.
maxHeight: "100%",
// The URL to the picture.
url: false,
// Time to update the picture (if you replace the image from another system), if set to false, it never updates.
updateInterval: false,
// Speed of the fade when updating/reloading the picture.
fadeSpeed: 800,
// ID of this module (if you want to remotely refresh just this modules picture), set to false to always update on the "REFRESHPICTURE" notification.
id: false,
},
// Refresh the picture if the notification "REFRESHPICTURE(x)" arrives.
notificationReceived: function (notification, payload, sender) {
var self = this;
if (self.config.id !== false ) {
if (notification === "REFRESHPICTURE" + self.config.id) {
this.updateDom(self.config.fadeSpeed || 0);
}
} else {
if (notification === "REFRESHPICTURE") {
this.updateDom(self.config.fadeSpeed || 0);
}
}
},
// Checks if the URL config is set. If not uses the default picture.
start: function () {
if (this.config.url === false) {
Log.info("No URL set under config, using dafault profile image: " + this.data.path + "pictures/carbon.jpg");
this.config.url = "./" + this.data.path + "pictures/carbon.jpg";
}
// Auto update if set.
if (this.config.updateInterval !== false) {
var self = this;
setInterval(function() {
self.updateDom(self.config.fadeSpeed || 0);
},
this.config.updateInterval);
}
},
// Displays the picture.
getDom: function () {
var wrapper = document.createElement("div");
if (this.config.id) {
// Add the ID to be able to style the picture with CSS / ID.
wrapper.className = "mmm-profilepicture"+this.config.id;
} else {
wrapper.className = "mmm-profilepicture";
}
var image = document.createElement("img");
image.src = this.config.url + "?" + new Date().getTime();
image.id = "mmm-profilepicture";
image.style.maxWidth = this.config.maxWidth;
image.style.maxHeight = this.config.maxHeight;
image.style.opacity = this.config.opacity;
wrapper.appendChild(image);
return wrapper;
}
});