42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
function onlyPlayOneIn(container) {
|
|
container.addEventListener(
|
|
"play",
|
|
function (event) {
|
|
audio_elements = container.getElementsByTagName("audio");
|
|
for (i = 0; i < audio_elements.length; i++) {
|
|
audio_element = audio_elements[i];
|
|
if (audio_element !== event.target) {
|
|
audio_element.pause();
|
|
}
|
|
}
|
|
},
|
|
true
|
|
);
|
|
}
|
|
|
|
function renderJSButtons() {
|
|
// If JS is disabled this won't run and therefore JS-powered buttons won't be displayed
|
|
let blockToggle = document.getElementsByClassName("block-toggle");
|
|
for (let i = 0; i < blockToggle.length; i++) {
|
|
blockToggle[i].style.display = "block";
|
|
// Accessibility is important!!!
|
|
blockToggle[i].ariaHidden = "false";
|
|
}
|
|
}
|
|
|
|
function blockToggle(id) {
|
|
var blockID = document.getElementById(id);
|
|
|
|
if (blockID.style.display === "block") {
|
|
blockID.style.display = "none";
|
|
blockID.ariaHidden = "true";
|
|
} else {
|
|
blockID.style.display = "block";
|
|
blockID.ariaHidden = "false";
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
onlyPlayOneIn(document.body);
|
|
renderJSButtons();
|
|
});
|