mirror of
https://github.com/Kugelschieber/schnittfest.git
synced 2026-11-12 09:02:01 +01:00
39 lines
913 B
JavaScript
39 lines
913 B
JavaScript
import { initNav } from "./nav.js";
|
|
import { initReveal } from "./reveal.js";
|
|
import { initTimecode } from "./timecode.js";
|
|
|
|
document.documentElement.classList.add("js");
|
|
|
|
const components = {
|
|
nav: initNav,
|
|
reveal: initReveal,
|
|
timecode: initTimecode,
|
|
};
|
|
|
|
function init(root = document) {
|
|
root.querySelectorAll("[data-component]").forEach((el) => {
|
|
if (el.dataset.componentReady) {
|
|
return;
|
|
}
|
|
|
|
const fn = components[el.dataset.component];
|
|
|
|
if (fn) {
|
|
fn(el);
|
|
el.dataset.componentReady = "true";
|
|
}
|
|
});
|
|
}
|
|
|
|
if (document.readyState === "loading") {
|
|
document.addEventListener("DOMContentLoaded", start);
|
|
} else {
|
|
start();
|
|
}
|
|
|
|
function start() {
|
|
init();
|
|
// the admin UI swaps element HTML in place after edits
|
|
new MutationObserver(() => init()).observe(document.body, { childList: true, subtree: true });
|
|
}
|