2021-12-22 10:52:02 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", _ => {
|
|
|
|
Promise.all([initMermaid(), setSlidesContent()])
|
|
|
|
.then(() => {
|
|
|
|
return initReveal()
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
subscribeToEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
async function setSlidesContent() {
|
|
|
|
let resp = await fetch("/slides")
|
|
|
|
let contentText = await resp.text()
|
|
|
|
let parser = new DOMParser()
|
|
|
|
let contentDocument = parser.parseFromString(contentText, 'text/html')
|
|
|
|
for (let mermaidElem of contentDocument.getElementsByClassName("mermaid")) {
|
|
|
|
let insertSVG = (svgCode, _) => {
|
|
|
|
mermaidElem.innerHTML = svgCode
|
|
|
|
}
|
|
|
|
|
|
|
|
mermaid.mermaidAPI.render('mermaid', mermaidElem.innerText, insertSVG)
|
|
|
|
}
|
|
|
|
document.getElementById("content-root").innerHTML = contentDocument.documentElement.innerHTML
|
|
|
|
}
|
|
|
|
|
2021-12-22 19:19:05 +00:00
|
|
|
async function getRevealConfig() {
|
2021-12-22 10:52:02 +00:00
|
|
|
let resp = await fetch('/api/v1/config/reveal')
|
2021-12-22 19:19:05 +00:00
|
|
|
return await resp.json()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function initReveal() {
|
|
|
|
let cfg = await getRevealConfig()
|
2021-12-22 10:52:02 +00:00
|
|
|
Reveal.initialize({
|
|
|
|
controls: cfg.controls,
|
2021-12-22 21:31:45 +00:00
|
|
|
controlsLayout: cfg.controlsLayout,
|
2021-12-22 10:52:02 +00:00
|
|
|
progress: cfg.progress,
|
|
|
|
history: cfg.history,
|
|
|
|
center: cfg.center,
|
|
|
|
slideNumber: cfg.slideNumber,
|
|
|
|
transition: cfg.transition,
|
2022-02-16 13:18:08 +00:00
|
|
|
width: cfg.width,
|
|
|
|
height: cfg.height,
|
2021-12-22 10:52:02 +00:00
|
|
|
hash: true,
|
|
|
|
pdfSeparateFragments: false,
|
|
|
|
menu: {
|
|
|
|
numbers: cfg.menu.numbers,
|
|
|
|
useTextContentForMissingTitles: cfg.menu.useTextContentForMissingTitles,
|
2021-12-22 21:31:45 +00:00
|
|
|
transitions: cfg.menu.transitions,
|
|
|
|
hideMissingTitles: cfg.hideMissingTitles,
|
|
|
|
markers: cfg.menu.markers,
|
|
|
|
openButton: cfg.menu.openButton,
|
2021-12-22 10:52:02 +00:00
|
|
|
custom: [
|
|
|
|
{
|
|
|
|
title: 'Print',
|
|
|
|
icon: '<i class="fas fa-print"></i>',
|
|
|
|
content: '<a href="/?print-pdf">Go to print view<a/>'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
themes: [
|
|
|
|
{name: 'Beige', theme: '/reveal/dist/theme/beige.css'},
|
|
|
|
{name: 'Black', theme: '/reveal/dist/theme/black.css'},
|
|
|
|
{name: 'Blood', theme: '/reveal/dist/theme/blood.css'},
|
|
|
|
{name: 'League', theme: '/reveal/dist/theme/league.css'},
|
|
|
|
{name: 'Moon', theme: '/reveal/dist/theme/moon.css'},
|
|
|
|
{name: 'Night', theme: '/reveal/dist/theme/night.css'},
|
|
|
|
{name: 'Serif', theme: '/reveal/dist/theme/serif.css'},
|
|
|
|
{name: 'Simple', theme: '/reveal/dist/theme/simple.css'},
|
|
|
|
{name: 'Sky', theme: '/reveal/dist/theme/sky.css'},
|
|
|
|
{name: 'Solarized', theme: '/reveal/dist/theme/solarized.css'},
|
|
|
|
{name: 'White', theme: '/reveal/dist/theme/white.css'}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [RevealHighlight, RevealNotes, RevealMenu]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function initMermaid() {
|
|
|
|
let resp = await fetch('/api/v1/config/mermaid')
|
|
|
|
let cfg = await resp.json()
|
|
|
|
mermaid.parseError = (err, hash) => {
|
|
|
|
console.error(`Failed to parse Mermaid diagraph: ${err} - ${hash}`)
|
|
|
|
}
|
|
|
|
mermaid.initialize({
|
|
|
|
startOnLoad: false,
|
|
|
|
theme: cfg.theme,
|
|
|
|
securityLevel: 'loose',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function subscribeToEvents() {
|
2022-03-15 13:53:24 +00:00
|
|
|
let eventSource = new EventSource("/api/v1/events");
|
2021-12-22 10:52:02 +00:00
|
|
|
|
2022-03-15 13:53:24 +00:00
|
|
|
eventSource.onopen = (() => {
|
2021-12-22 21:31:45 +00:00
|
|
|
console.debug("eventsource connection open");
|
2021-12-22 10:52:02 +00:00
|
|
|
})
|
|
|
|
|
2022-03-15 13:53:24 +00:00
|
|
|
eventSource.onerror = (ev => {
|
2021-12-22 10:52:02 +00:00
|
|
|
if (ev.target.readyState === 0) {
|
2021-12-22 21:31:45 +00:00
|
|
|
console.debug("reconnecting to eventsource");
|
2021-12-22 10:52:02 +00:00
|
|
|
} else {
|
2021-12-22 21:31:45 +00:00
|
|
|
console.error("eventsource error", ev);
|
2021-12-22 10:52:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-03-15 13:53:24 +00:00
|
|
|
eventSource.onmessage = (ev => {
|
2021-12-22 10:52:02 +00:00
|
|
|
let obj = JSON.parse(ev.data);
|
2021-12-22 19:19:05 +00:00
|
|
|
switch (true) {
|
|
|
|
case obj.forceReload:
|
2022-03-15 13:53:24 +00:00
|
|
|
eventSource.close()
|
2021-12-22 19:19:05 +00:00
|
|
|
window.location.reload()
|
|
|
|
break
|
|
|
|
case obj.reloadConfig:
|
|
|
|
getRevealConfig().then(cfg => {
|
|
|
|
Reveal.configure(cfg)
|
|
|
|
})
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
switch (true) {
|
|
|
|
case obj.file.endsWith(".css"):
|
|
|
|
let cssLink = document.querySelector(`link[rel=stylesheet][id="${obj.fileNameHash}"]`);
|
|
|
|
cssLink.href = `${obj.file}?ts=${obj.ts}`
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
let elem = document.getElementById(obj.fileNameHash);
|
|
|
|
if (elem !== null) {
|
|
|
|
elem.src = `${obj.file}?ts=${obj.ts}`
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 10:52:02 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|