diff --git a/app.js b/app.js index aad8bcb..78bbbea 100644 --- a/app.js +++ b/app.js @@ -19,18 +19,28 @@ customElements.define( ) class Setup { - async run() { - const sw = navigator.serviceWorker - - sw.addEventListener('controllerchange', () => { - if (this.registration.active) { - window.location.reload(true) + async runWithSw() { + navigator.serviceWorker.addEventListener( + 'controllerchange', + () => { + if (this.registration.active) { + window.location.reload(true) + } } - }) + ) await this.register() this.load() } + async runWithoutSw() { + const layout = document.createElement( + 'm-layout' + ) + layout.csp = undefined + layout.header.menu.handleLinks = true + document.body.appendChild(layout) + } + async register() { try { this.registration = @@ -54,4 +64,4 @@ class Setup { } } -new Setup().run() \ No newline at end of file +new Setup().runWithSw() \ No newline at end of file diff --git a/components/layout.js b/components/layout.js index d95805e..40e1cf9 100644 --- a/components/layout.js +++ b/components/layout.js @@ -36,6 +36,9 @@ export class Layout extends HTMLElement { addEventListener('hashchange', () => { this.load() }) + this.addEventListener('hash-change', () => { + this.load() + }) } load() { diff --git a/components/nav-menu.js b/components/nav-menu.js index 3562d41..713f73d 100644 --- a/components/nav-menu.js +++ b/components/nav-menu.js @@ -4,6 +4,7 @@ export class NavMenu extends HTMLElement { this.attachShadow({mode: 'open'}) this.language = navigator.language this.pages = [] + this.handleLinks = false } connectedCallback() { @@ -42,9 +43,16 @@ export class NavMenu extends HTMLElement { this.renderPageList() this.shadowRoot.addEventListener('click', e => { if (e.target.classList.contains('page')) { + if (this.handleLinks) { + e.preventDefault() + } this.dispatchEvent(new CustomEvent( 'close-menu', {bubbles: true} )) + if (this.handleLinks) { + const hash = '#' + e.target.innerText + location.hash = hash + } } }) } diff --git a/components/page.js b/components/page.js index 71236e3..3e1dd58 100644 --- a/components/page.js +++ b/components/page.js @@ -131,7 +131,7 @@ export class Page extends HTMLElement { } display(value) { - let doc = value + let doc = value || '' if (!(/<\w/).test(doc.substring(0, 30))) { doc = `
` +
         doc.replace("<", "<").replace(">", ">") +
diff --git a/sw.js b/sw.js
index 3c20815..2978397 100644
--- a/sw.js
+++ b/sw.js
@@ -11,7 +11,7 @@ async function initCache() {
     '/dialog/dialog.js',
     '/forms/button-group.js',
     '/menu/dropdown.js',
-  ])
+  ]) //1
 }
 
 self.addEventListener("install", event => {