1
Fork 0

Move disabling of volume slider into setVolumeButton.

This commit is contained in:
Juliusz Chroboczek 2020-12-11 19:37:09 +01:00
parent 6a403e1fd9
commit 954c23cc3b
1 changed files with 12 additions and 13 deletions

View File

@ -1125,13 +1125,9 @@ function addCustomControls(media, container, c) {
if(c.kind === 'local') { if(c.kind === 'local') {
volume.remove(); volume.remove();
} else { } else {
let slider = /** @type{HTMLInputElement} */ setVolumeButton(media.muted,
(getVideoButton(controls, "volume-slider")); getVideoButton(controls, "volume-mute"),
slider.disabled = media.muted; getVideoButton(controls, "volume-slider"));
setVolumeButton(
/** @type{HTMLElement} */(volume.firstElementChild),
media.muted,
);
} }
container.appendChild(controls); container.appendChild(controls);
@ -1147,10 +1143,11 @@ function getVideoButton(container, name) {
} }
/** /**
* @param {HTMLElement} button
* @param {boolean} muted * @param {boolean} muted
* @param {HTMLElement} button
* @param {HTMLElement} slider
*/ */
function setVolumeButton(button, muted) { function setVolumeButton(muted, button, slider) {
if(!muted) { if(!muted) {
button.classList.remove("fa-volume-mute"); button.classList.remove("fa-volume-mute");
button.classList.add("fa-volume-up"); button.classList.add("fa-volume-up");
@ -1158,6 +1155,10 @@ function setVolumeButton(button, muted) {
button.classList.remove("fa-volume-up"); button.classList.remove("fa-volume-up");
button.classList.add("fa-volume-mute"); 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; return;
event.preventDefault(); event.preventDefault();
media.muted = !media.muted; media.muted = !media.muted;
let slider = /** @type{HTMLInputElement} */ setVolumeButton(media.muted, target,
(getVideoButton(volume, "volume-slider")); getVideoButton(volume, "volume-slider"));
slider.disabled = media.muted;
setVolumeButton(target, media.muted);
}; };
volume.oninput = function() { volume.oninput = function() {
let slider = /** @type{HTMLInputElement} */ let slider = /** @type{HTMLInputElement} */