aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/volume.js
diff options
context:
space:
mode:
authorRoger Zanoni <rzanoni@igalia.com>2022-11-11 16:53:15 +0100
committerRoger Zanoni <rzanoni@igalia.com>2022-11-11 16:54:34 +0100
commit38587cf96c096a204cd742fff9fea4f8e465393a (patch)
tree18b18d18bba8c93140186cc7db5b462408ea9f2c /src/js/volume.js
parentc189320ab6810d4c916fa8f697a9452f3a8976a4 (diff)
Adapt the mixer demo to use kuksa.val service
Bug-AGL: SPEC-4599 Signed-off-by: Roger Zanoni <rzanoni@igalia.com> Change-Id: If8308d3402c11ac3acc7dc11c11ed042f014b87e
Diffstat (limited to 'src/js/volume.js')
-rw-r--r--src/js/volume.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/js/volume.js b/src/js/volume.js
new file mode 100644
index 0000000..0bbb481
--- /dev/null
+++ b/src/js/volume.js
@@ -0,0 +1,55 @@
+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;
+ }
+}
+
+export 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+'%';
+ }
+}
+
+// TODO: right now there's only one PATHS
+// if it gets update to use multiple volume controls
+// all the below functions need to be update to use
+// the correct paths/elements
+export function increase(node) {
+ KUKSA.set(PATHS.volume, getValue(node)+5);
+}
+
+export function decrease(node) {
+ KUKSA.set(PATHS.volume, getValue(node)-5);
+}
+
+export function change(node) {
+ KUKSA.set(PATHS.volume, node.value);
+}
+
+export function update(path, value) {
+ setValue(document.getElementById('progress-MAIN'), value);
+}
+
+export function init() {
+ KUKSA.set(PATHS.volume, 20);
+}