diff --git a/doc/static/markdown_spa.js b/doc/static/markdown_spa.js index c61c8ba..9fe7299 100644 --- a/doc/static/markdown_spa.js +++ b/doc/static/markdown_spa.js @@ -1,47 +1,44 @@ -if (typeof preFetch !== 'function') { function preFetch() {} } -if (typeof postFetch !== 'function') { function postFetch() {} } - async function updatePage(path) { - preFetch(); + preFetch(); - if (typeof updateWithJSON === 'function') { - updateWithJSON(await fetch(path+'index.json').then(r => r.json())); - } else { - let text = await fetch(path).then(r => r.text()); - document.documentElement.innerHTML = text; - } + if (typeof updateWithJSON === "function") { + updateWithJSON(await fetch(path + "index.json").then((r) => r.json())); + } else { + let text = await fetch(path).then((r) => r.text()); + document.documentElement.innerHTML = text; + } - postFetch(); + postFetch(); } postFetch(); let curPath = window.location.pathname; -window.addEventListener('popstate', async _ => { - if (window.location.pathname == curPath) { - return; - } +window.addEventListener("popstate", async (_) => { + if (window.location.pathname == curPath) { + return; + } - curPath = window.location.pathname; - await updatePage(window.location.href); + curPath = window.location.pathname; + await updatePage(window.location.href); }); -window.addEventListener('click', e => { - let targetAnchor = e.target.closest('a'); - if (!targetAnchor || !targetAnchor.hasAttribute("href")) { - return; - } +window.addEventListener("click", (e) => { + let targetAnchor = e.target.closest("a"); + if (!targetAnchor || !targetAnchor.hasAttribute("href")) { + return; + } - href = (targetAnchor) ? targetAnchor.href : e.target.href; - e.preventDefault(); + href = targetAnchor ? targetAnchor.href : e.target.href; + e.preventDefault(); - if (href == window.location.href) { - return; - } + if (href == window.location.href) { + return; + } - if (href.startsWith(window.location.origin)) { - e.preventDefault(); - updatePage(href); - window.history.pushState({}, '', href); - } -}) + if (href.startsWith(window.location.origin)) { + e.preventDefault(); + updatePage(href); + window.history.pushState({}, "", href); + } +}); diff --git a/doc/static/script.js b/doc/static/script.js index 73e0aa5..6467b73 100644 --- a/doc/static/script.js +++ b/doc/static/script.js @@ -1,28 +1,31 @@ -let loader = document.getElementById('loader'); -let input = document.getElementById('show-nav') +let loader = document.getElementById("loader"); +let input = document.getElementById("show-nav"); function preFetch() { - loader.classList.add('active'); + loader.classList.add("active"); } function updateWithJSON(json) { - document.title = `Markdown SPA - ${json.name}`; - document.querySelector('meta[name="description"]').content = json.description; - document.querySelector('#content').innerHTML = `

${json.name}

${json.page_content}` + document.title = `Markdown SPA - ${json.name}`; + document.querySelector('meta[name="description"]').content = json.description; + document.querySelector("#content").innerHTML = + `

${json.name}

${json.page_content}`; } function postFetch() { - for (let h2 of document.getElementsByName('h2')) { - h2.classList.add('anchor'); - h2.id = h2.innerText.toLowerCase().replace(/[^a-z0-9]/g, '-'); + for (let h2 of document.getElementsByTagName("h2")) { + h2.classList.add("anchor"); + h2.id = h2.innerText.toLowerCase().replace(/[^a-z0-9]/g, "-"); - h2.addEventListener('click', e => { - e.target.scrollIntoView(); - history.pushState({}, '', `#${h2.id}`); - navigator.clipboard.writeText(`${window.location.origin}${window.location.pathname}#${h2.id}`); - }); - } + h2.addEventListener("click", (e) => { + e.target.scrollIntoView(); + history.pushState({}, "", `#${h2.id}`); + navigator.clipboard.writeText( + `${window.location.origin}${window.location.pathname}#${h2.id}`, + ); + }); + } - loader.classList.remove('active'); - input.checked = false; + loader.classList.remove("active"); + input.checked = false; }