-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VID-706: Add button to enable sound in live player
- Loading branch information
Daniel Thies
committed
Oct 18, 2023
1 parent
8f419fb
commit 3f1ef0e
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Audio control listner | ||
* | ||
* @package videotimeplugin_live | ||
* @module videotimeplugin_live/audioswitch | ||
* @copyright 2023 bdecent gmbh <https://bdecent.de> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Handle click event | ||
* | ||
* @param {Event} e Click event | ||
*/ | ||
const handleClick = e => { | ||
const button = e.target.closest('[data-contextid] button[data-audio]'); | ||
|
||
if (button) { | ||
const action = button.getAttribute('data-audio'), | ||
contextid = button.closest('[data-contextid]').getAttribute('data-contextid'); | ||
|
||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
document.querySelectorAll('[data-contextid] button[data-audio]').forEach(button => { | ||
if (button.getAttribute('data-audio') === action) { | ||
button.classList.add('hidden'); | ||
} else { | ||
button.classList.remove('hidden'); | ||
} | ||
}); | ||
|
||
document.querySelectorAll(`[data-contextid="${contextid}"] audio`).forEach(audio => { | ||
audio.setAttribute('volume', action === 'disable' ? 0 : 1); | ||
audio.muted = (action === 'disable'); | ||
}); | ||
} | ||
}; | ||
|
||
export default { | ||
/** | ||
* Add listener | ||
*/ | ||
init: function() { | ||
document.removeEventListener('click', handleClick); | ||
document.addEventListener('click', handleClick); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters