-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-TouchSwipe.js
executable file
·140 lines (113 loc) · 4.02 KB
/
MMM-TouchSwipe.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* global Module */
/* Magic Mirror
* Module: MMM-TouchSwipe
*
* By Buzz Kc
* MIT Licensed.
*/
Module.register("MMM-TouchSwipe", {
defaults: {
helpText: 'Swipe Here',
dimmerOverride: false,
dimmerOverrideValue: 120,
hideScreendimmer: false
},
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function() {
var self = this;
var dataRequest = null;
var dataNotification = null;
//Flag for check if module is loaded
this.loaded = false;
self.updateDom();
},
getDom: function() {
var self = this;
// create element wrapper for show into the module
var wrapper = document.createElement("div");
wrapper.setAttribute("id", "touchSwipeContainer");
wrapper.setAttribute("class", "touchSwipeContainer");
var dimAuto = document.createElement("div");
dimAuto.setAttribute("id", "touchSwipeDimAutoContainer");
dimAuto.setAttribute("class", "touchSwipeDimAutoContainer");
if (!this.config.hideScreendimmer) {
var auto = document.createElement("button");
auto.innerHTML = "Auto Dim";
auto.setAttribute("class", "touchAutoDim");
auto.addEventListener("click", function() { self.sendNotification("MMM-Screendimmer_RESUME", null); });
dimAuto.appendChild(auto);
}
var homeIcon = document.createElement("button");
homeIcon.setAttribute("class", "touchSwipeHome");
homeIcon.addEventListener("click", function() {self.sendNotification('PAGE_CHANGED', 0);});
var prevIcon = document.createElement("button");
prevIcon.setAttribute("class", "touchSwipePrev");
prevIcon.addEventListener("click", function() {self.sendNotification('PAGE_DECREMENT', 1);});
var nextIcon = document.createElement("button");
nextIcon.setAttribute("class", "touchSwipeNext");
nextIcon.addEventListener("click", function() {self.sendNotification('PAGE_INCREMENT', 1);});
var dimNav = document.createElement("div");
dimNav.setAttribute("id", "touchSwipeDimNavContainer");
dimNav.setAttribute("class", "touchSwipeDimNavContainer");
if (!this.config.hideScreendimmer) {
var b = document.createElement("button");
b.innerHTML = "-";
b.addEventListener("click", function() {document.getElementById("dimNumber").stepDown(1); self.sendNotification("MMM-Screendimmer_OVERRIDE", document.getElementById("dimNumber").value);});
b.setAttribute("id", "dimDownDirectionButton");
b.setAttribute("class", "dimButton");
dimNav.appendChild(b);
var input = document.createElement("input");
input.type='number';
input.setAttribute('min', 10);
input.setAttribute('max', 255);
input.setAttribute('step', 15);
input.setAttribute('id', 'dimNumber');
input.setAttribute('class', 'dimNumber');
input.value = this.config.dimmerOverrideValue;
dimNav.appendChild(input);
var b = document.createElement("button");
b.innerHTML = "+";
b.addEventListener("click", function() {document.getElementById("dimNumber").stepUp(1); self.sendNotification("MMM-Screendimmer_OVERRIDE", document.getElementById("dimNumber").value);});
b.setAttribute("id", "dimUpDirectionButton");
b.setAttribute("class", "dimButton");
dimNav.appendChild(b);
}
wrapper.appendChild(dimAuto);
wrapper.appendChild(prevIcon);
wrapper.appendChild(homeIcon);
wrapper.appendChild(nextIcon);
wrapper.appendChild(dimNav);
return wrapper;
},
getScripts: function() {
return [
];
},
getStyles: function () {
return [
"MMM-TouchSwipe.css",
];
},
// Load translations files
getTranslations: function() {
//FIXME: This can be load a one file javascript definition
return {
en: "translations/en.json",
es: "translations/es.json"
};
},
// socketNotificationReceived from helper
socketNotificationReceived: function (notification, payload) {
if(notification === "MMM-TouchSwipe-NOTIFICATION_TEST") {
// set dataNotification
this.dataNotification = payload;
this.updateDom();
}
},
notificationReceived: function(notification, payload, sender) {
if (notification === "MMM-Screendimmer_CURRENT_VALUE") {
this.config.dimmerOverrideValue = payload;
this.updateDom();
}
}
});