summaryrefslogtreecommitdiff
path: root/static/src/pages.js
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2025-06-24 19:23:33 -0500
committerTim Keller <tjk@tjkeller.xyz>2025-06-24 19:23:33 -0500
commitffa5ff333eabffe07394fb21bc413d7d238ee651 (patch)
tree007b506aca746fda9040ea4f0ffa8d6578e86f7e /static/src/pages.js
parent09e9193b6be6e2eae7ffbfbfedd15ac22bab0022 (diff)
downloadimmich-frame-ffa5ff333eabffe07394fb21bc413d7d238ee651.tar.xz
immich-frame-ffa5ff333eabffe07394fb21bc413d7d238ee651.zip
move all files to /static
Diffstat (limited to 'static/src/pages.js')
-rw-r--r--static/src/pages.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/static/src/pages.js b/static/src/pages.js
new file mode 100644
index 0000000..f6a8b9b
--- /dev/null
+++ b/static/src/pages.js
@@ -0,0 +1,54 @@
+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
+ }
+ }
+ }
+}