From ffa5ff333eabffe07394fb21bc413d7d238ee651 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 24 Jun 2025 19:23:33 -0500 Subject: move all files to /static --- src/pages.js | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 src/pages.js (limited to 'src/pages.js') diff --git a/src/pages.js b/src/pages.js deleted file mode 100644 index f6a8b9b..0000000 --- a/src/pages.js +++ /dev/null @@ -1,54 +0,0 @@ -const menu = document.querySelector("#menu") - -export default class Page { - static pages = {} - static currentPage = null - - static pathnameCallback() { - const path = window.location.pathname.replace(/\/$/, "") - const page = Page.pages[path] - - if (!page) - throw new Error(`Path '${path}' does not exist`) - - if (Page.currentPage) - Page.currentPage.setVisible(false) - - page.setVisible(true) - Page.currentPage = page - } - - static softRedirect(path) { - window.history.pushState({}, "", path) - Page.pathnameCallback() - } - - constructor(pageContainer, endpoints, f_initialize) { - for (const endpoint of endpoints) - Page.pages[endpoint] = this - - this.pageContainer = pageContainer - this.endpoints = endpoints - this.initialize = f_initialize - this.visible = false - this.initialized = false - } - - setVisible(visible) { - this.pageContainer.classList.toggle("hidden!", !visible) - this.visible = visible - if (this.visible) { - /* initialize page */ - if (!this.initialized && this.initialize) - this.initialized = this.initialize(this.pageContainer) - - /* set selected attribute on the link */ - for (const a of menu.querySelectorAll("a")) { - if (this.endpoints.includes(a.getAttribute("href"))) - a.dataset.selected = "1" - else - delete a.dataset.selected - } - } - } -} -- cgit v1.2.3