-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-CustomText.js
52 lines (44 loc) · 1.17 KB
/
MMM-CustomText.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
/* global Log, Module */
/* MagicMirror²
* Module: MMM-CustomText
*
* By dathbe
* MIT Licensed.
*/
Module.register("MMM-CustomText", {
// Default config.
defaults: {
animationSpeed: 2 * 1000,
uniqueID: null,
initialMessage: "No notification received yet"
},
// Define required scripts.
getStyles () {
return ["MMM-CustomText.css"];
},
// Define start sequence.
start () {
this.notification = false;
this.messageText = this.config.initialMessage;
},
// dom generator.
getDom () {
const self = this;
// create html
const wrapper = document.createElement("div");
wrapper.className = "CustomTextDiv"
wrapper.innerHTML = self.messageText;
if (self.messageText == "") {
wrapper.style.display = 'none';
}
return wrapper;
},
notificationReceived (notification, payload, sender) {
if(notification === "CUSTOMTEXT_UPDATE" && (payload.uniqueID == this.config.uniqueID || !this.config.uniqueID)) {
Log.debug(`Received notification: ${notification} with payload.message: ${payload.message} from sender: ${sender}`);
this.messageText = payload.message;
this.notification = true;
this.updateDom(this.config.animationSpeed);
}
},
});