From 954c23cc3badccf6956bb936d08e0ff663dfa89e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 11 Dec 2020 19:37:09 +0100 Subject: [PATCH] Move disabling of volume slider into setVolumeButton. --- static/galene.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/static/galene.js b/static/galene.js index 81e8c36..495b944 100644 --- a/static/galene.js +++ b/static/galene.js @@ -1125,13 +1125,9 @@ function addCustomControls(media, container, c) { if(c.kind === 'local') { volume.remove(); } else { - let slider = /** @type{HTMLInputElement} */ - (getVideoButton(controls, "volume-slider")); - slider.disabled = media.muted; - setVolumeButton( - /** @type{HTMLElement} */(volume.firstElementChild), - media.muted, - ); + setVolumeButton(media.muted, + getVideoButton(controls, "volume-mute"), + getVideoButton(controls, "volume-slider")); } container.appendChild(controls); @@ -1147,10 +1143,11 @@ function getVideoButton(container, name) { } /** - * @param {HTMLElement} button * @param {boolean} muted + * @param {HTMLElement} button + * @param {HTMLElement} slider */ -function setVolumeButton(button, muted) { +function setVolumeButton(muted, button, slider) { if(!muted) { button.classList.remove("fa-volume-mute"); button.classList.add("fa-volume-up"); @@ -1158,6 +1155,10 @@ function setVolumeButton(button, muted) { button.classList.remove("fa-volume-up"); button.classList.add("fa-volume-mute"); } + + if(!(slider instanceof HTMLInputElement)) + throw new Error("Couldn't find volume slider"); + slider.disabled = muted; } /** @@ -1174,10 +1175,8 @@ function registerControlHandlers(media, container) { return; event.preventDefault(); media.muted = !media.muted; - let slider = /** @type{HTMLInputElement} */ - (getVideoButton(volume, "volume-slider")); - slider.disabled = media.muted; - setVolumeButton(target, media.muted); + setVolumeButton(media.muted, target, + getVideoButton(volume, "volume-slider")); }; volume.oninput = function() { let slider = /** @type{HTMLInputElement} */