From e1cbac3034100e26ff02ee6c094fde16b90337cf Mon Sep 17 00:00:00 2001 From: Humberto Alfonso Díaz Date: Fri, 5 Jul 2019 14:21:47 +0200 Subject: OPT Improve chair and fan code --- src/index.html | 8 ++++---- src/js/chair.js | 18 ++++++++---------- src/js/fan_speed.js | 17 ++++++++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/index.html b/src/index.html index 45a53d0..17293c9 100644 --- a/src/index.html +++ b/src/index.html @@ -12,8 +12,8 @@
- - + +
FAN SPEED @@ -21,7 +21,7 @@
- + @@ -35,7 +35,7 @@ A/C
- + diff --git a/src/js/chair.js b/src/js/chair.js index ceed88c..b1a3dbb 100644 --- a/src/js/chair.js +++ b/src/js/chair.js @@ -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 diff --git a/src/js/fan_speed.js b/src/js/fan_speed.js index cc81fe0..4c8349e 100644 --- a/src/js/fan_speed.js +++ b/src/js/fan_speed.js @@ -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 -- cgit 1.2.3-korg