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() } }