diff options
| author | Tim Keller <tjk@tjkeller.xyz> | 2025-05-05 20:38:42 -0500 |
|---|---|---|
| committer | Tim Keller <tjk@tjkeller.xyz> | 2025-05-05 20:38:42 -0500 |
| commit | e943375d74ce8d48b8ad40b1a5d05437ca4f5c7f (patch) | |
| tree | 36921b2275b14e295e0250ab9509c23c67e5487b /src/pages.js | |
| parent | a3651595531e210916b29f66ac7cce61d5d87670 (diff) | |
| download | immich-frame-e943375d74ce8d48b8ad40b1a5d05437ca4f5c7f.tar.xz immich-frame-e943375d74ce8d48b8ad40b1a5d05437ca4f5c7f.zip | |
add immich api class and page class
Diffstat (limited to 'src/pages.js')
| -rw-r--r-- | src/pages.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/pages.js b/src/pages.js new file mode 100644 index 0000000..7e0bdbc --- /dev/null +++ b/src/pages.js @@ -0,0 +1,35 @@ +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 + } + + constructor(pageContainer, endpoint, f_initialize) { + Page.pages[endpoint] = this + + this.pageContainer = pageContainer + this.endpoint = endpoint + this.initialize = f_initialize + this.visible = false + this.initialized = false + } + + setVisible(visible) { + this.pageContainer.style.display = visible ? null : "none" + this.visible = visible + if (visible && !this.initialized && this.initialize) + this.initialized = this.initialize() + } +} |
