OPT Improve chair and fan code
authorHumberto Alfonso Díaz <humberto.alfonso@asvito.es>
Fri, 5 Jul 2019 12:21:47 +0000 (14:21 +0200)
committerLorenzo Tilve <ltilve@igalia.com>
Tue, 4 Feb 2020 08:42:15 +0000 (09:42 +0100)
src/index.html
src/js/chair.js
src/js/fan_speed.js

index 45a53d0..17293c9 100644 (file)
@@ -12,8 +12,8 @@
             </div>
             <div class="fanSpeed">
                 <div class="fanSpeedContainer">
-                    <input id="FanSpeedInput" type="range" min="1" value="1" max="100" onchange="FANSPEED.update(this.value)">
-                    <progress id="FanSpeedProgress" value="1" max="100"></progress>
+                    <input id="FanSpeed" type="range" min="1" value="1" max="100" onchange="FANSPEED.set(this)">
+                    <progress value="1" max="100"></progress>
                 </div>
                 <div class="label">
                     FAN SPEED
@@ -21,7 +21,7 @@
             </div>
         </div>
         <div class="center">
-            <a id="LeftChair" value="0" href="#" class="seat left item button" onclick="CHAIR.left()">
+            <a id="LeftChair" value="0" href="#" class="seat left item button" onclick="CHAIR.left(this)">
                 <img class="off" src="../images/HMI_HVAC_Left_Chair_OFF.svg"/>
                 <img class="one two" src="../images/HMI_HVAC_Left_Chair_ON.svg"/>
                 <img class="off" src="../images/HMI_HVAC_ChairIndicator_OFF.svg"/>
@@ -35,7 +35,7 @@
                     A/C
                 </div>
             </a>
-            <a id="RightChair" value="0" href="#" class="seat right item button" onclick="CHAIR.right()">
+            <a id="RightChair" value="0" href="#" class="seat right item button" onclick="CHAIR.right(this)">
                 <img class="off" src="../images/HMI_HVAC_Right_Chair_OFF.svg"/>
                 <img class="one two" src="../images/HMI_HVAC_Right_Chair_ON.svg"/>
                 <img class="off" src="../images/HMI_HVAC_ChairIndicator_OFF.svg"/>
index ceed88c..b1a3dbb 100644 (file)
@@ -1,19 +1,17 @@
 var left = 0;
 var right = 0;
 
+function update(node, value){
+    node.setAttribute('value', value);
+}
+
 module.exports = {
-    update_left: function() {
-        document.getElementById('LeftChair').setAttribute('value', left);
-    },
-    left: function() {
+    left: function(node) {
         left = (left + 1) % 3;
-        this.update_left();
-    },
-    update_right: function() {
-        document.getElementById('RightChair').setAttribute('value', right);
+        update(node, left);
     },
-    right: function() {
+    right: function(node) {
         right = (right + 1) % 3;
-        this.update_right();
+        update(node, right);
     },
 }
\ No newline at end of file
index cc81fe0..4c8349e 100644 (file)
@@ -1,10 +1,13 @@
-module.exports = {
-    set: function(value) {
-        document.getElementById('FanSpeedProgress').value = value;
-        document.getElementById('FanSpeedInput').value = value;
-    },
-    update: function( value ) {
-        this.set(value);
+var value = 0;
+
+function update(node, value) {
+    node.value = value;
+    node.parentNode.getElementsByTagName('progress')[0].value = value;
+}
 
+module.exports = {
+    set: function(node) {
+        value = node.value;
+        update(node, value);
     }
 }
\ No newline at end of file