summaryrefslogtreecommitdiffstats
path: root/static/unfold.js
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-04-07 21:10:06 +0300
committerJan Tuomi <jan@jantuomi.fi>2024-04-07 21:10:06 +0300
commitd9a446ac271a0fde70fae17ef3804482f68679a7 (patch)
tree527ceded71b1456ae41c033b6c04c2f1859a4976 /static/unfold.js
parent16875af62740fbc217491042dd34bae890c7b3cc (diff)
Improve unfold.js
Diffstat (limited to 'static/unfold.js')
-rw-r--r--static/unfold.js86
1 files changed, 0 insertions, 86 deletions
diff --git a/static/unfold.js b/static/unfold.js
deleted file mode 100644
index e27dbb5..0000000
--- a/static/unfold.js
+++ /dev/null
@@ -1,86 +0,0 @@
-window.Unfold = {
- activate: function (opts) {
- const separator = opts.separator || "hr";
- const content = opts.content || "main";
- const theme = opts.theme || "moon";
- const revealCdn = opts.revealCdn || "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0";
-
- const contentElem = document.querySelector(content);
- if (!contentElem) {
- console.error(`Unfold: content element not found`);
- return;
- }
-
- const nodes = [...contentElem.childNodes];
-
- const newBody = document.createElement("body");
- newBody.setAttribute("class", "reveal");
- const slides = document.createElement("div");
- slides.setAttribute("class", "slides");
- newBody.appendChild(slides);
-
- const newHead = document.createElement("head");
-
- let currentSlide = document.createElement("section");
- for (const node of nodes) {
- if (node.hasAttribute && node.hasAttribute("data-unfold-hidden")) {
- continue;
- }
-
- if (node.tagName?.toLowerCase() === separator.toLowerCase()) {
- slides.appendChild(currentSlide);
- currentSlide = document.createElement("section");
- } else {
- currentSlide.appendChild(node);
- }
- }
- slides.appendChild(currentSlide);
-
- const revealCssTag = document.createElement("link");
- revealCssTag.rel = "stylesheet";
- revealCssTag.href = `${revealCdn}/css/reveal.min.css`;
- newHead.appendChild(revealCssTag);
-
- const revealThemeCssTag = document.createElement("link");
- revealThemeCssTag.rel = "stylesheet";
- revealThemeCssTag.href = `${revealCdn}/css/theme/${theme}.css`;
- newHead.appendChild(revealThemeCssTag);
-
- const revealJsTag = document.createElement("script");
- revealJsTag.src = `${revealCdn}/js/reveal.min.js`;
- revealJsTag.onload = () => {
- // activate Reveal slideshow
- Reveal.initialize();
- // fix vertical positioning issue that happens often
- setTimeout(() => Reveal.sync(), 100);
- };
- newHead.appendChild(revealJsTag);
-
- document.head.replaceWith(newHead);
- document.body.replaceWith(newBody);
- },
- bind: function (selector, opts = {}) {
- const elem = document.querySelector(selector);
- elem.addEventListener("click", () => {
- Unfold.activate(opts)
- // enable back button by hooking into History API
- const qp = new URLSearchParams(location.search);
- qp.set("unfold", "1");
- history.pushState({}, "", `${location.protocol}//${location.host}${location.pathname}?${qp.toString()}`);
- })
-
- const qp = new URLSearchParams(location.search);
- if (qp.get("unfold") === "1") {
- Unfold.activate(opts)
- }
- }
-}
-
-const previousOnPopState = window.onpopstate;
-window.onpopstate = function() {
- if (typeof previousOnPopState === "function") {
- previousOnPopState();
- }
- location.reload();
-};
-