diff options
author | Humberto Alfonso Díaz <humberto.alfonso@asvito.es> | 2019-09-23 11:32:30 +0200 |
---|---|---|
committer | Lorenzo Tilve <ltilve@igalia.com> | 2020-02-04 09:42:15 +0100 |
commit | 783be0ef4f7302ca722ab3224f2c9a98e355b8da (patch) | |
tree | 3885f63801f453638f868c4b76ff0fc5d6a6c8e3 /src/js/sliders.js | |
parent | 202c99424446aaf2145932f02dca00209e7a6888 (diff) |
FUNCT Add support to modify sliders
Diffstat (limited to 'src/js/sliders.js')
-rw-r--r-- | src/js/sliders.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/js/sliders.js b/src/js/sliders.js new file mode 100644 index 0000000..624e8e4 --- /dev/null +++ b/src/js/sliders.js @@ -0,0 +1,56 @@ +this.sliders = {}; + +function getRootNode(node) { + while(!node.hasAttribute('slider-id') && node.parentNode) { + return getRootNode(node.parentNode); + } + + if( node.hasAttribute('slider-id') ) { + return node; + } else { + return false; + } +} + +function getValue(node) { + node = getRootNode(node); + if( node ) { + return parseInt(node.getAttribute('value')); + } else { + return false; + } +} + +function setValue(node, value) { + node = getRootNode(node); + if( node ){ + value = Math.max(Math.min(value, 100), 0); + node.setAttribute('value', value); + node.getElementsByTagName('progress')[0].value = value; + node.getElementsByTagName('input')[0].value = value; + node.getElementsByClassName('value')[0].innerHTML = value+'%'; + } +} + +function init(sliders) { + console.log(sliders); +} + +function increase(node) { + setValue(node, getValue(node)+5); +} + +function decrease(node) { + setValue(node, getValue(node)-5); +} + +function change(node) { + setValue(node, node.value); +} + +module.exports = { + init: init, + increase: increase, + decrease: decrease, + change: change +}
\ No newline at end of file |