From e8a8e5fb5af98ad37c147a934126e373d872491f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 4 Dec 2017 12:21:41 +0100 Subject: [PATCH] Fixed a problem that caused tabs to reload pages --- scripts/AnimeNotifier.ts | 6 ++++++ scripts/Application.ts | 10 +++++----- sw/service-worker.ts | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 0c748e24..e9efa575 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -52,6 +52,7 @@ export class AnimeNotifier { // Never remove src property on diffs Diff.persistentAttributes.add("src") + // Is intersection observer supported? if("IntersectionObserver" in window) { // Enable lazy load this.visibilityObserver = new IntersectionObserver( @@ -451,6 +452,11 @@ export class AnimeNotifier { element.removeEventListener(oldAction.trigger, oldAction.handler) } + // This prevents default actions on links + if(actionTrigger === "click" && element.tagName === "A") { + element.onclick = null + } + if(!(actionName in actions)) { this.statusMessage.showError(`Action '${actionName}' has not been defined`) continue diff --git a/scripts/Application.ts b/scripts/Application.ts index 197efc1c..bd677c52 100644 --- a/scripts/Application.ts +++ b/scripts/Application.ts @@ -154,21 +154,21 @@ export class Application { for(let i = 0; i < links.length; i++) { let link = links[i] as HTMLElement - - // link.classList.remove(this.ajaxClass) - let self = this + link.onclick = function(e) { // Middle mouse button should have standard behaviour - if(e.which === 2) + if(e.which === 2) { return + } let url = this.getAttribute("href") e.preventDefault() - if(!url || url === self.currentPath) + if(!url || url === self.currentPath) { return + } // Load requested page self.load(url) diff --git a/sw/service-worker.ts b/sw/service-worker.ts index f41e5635..68840065 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -113,8 +113,6 @@ class MyServiceWorker { return evt.respondWith(this.fromNetwork(request)) } - console.log("Fetch:", request.url) - // Clear cache on authentication and fetch it normally if(request.url.includes("/auth/") || request.url.includes("/logout")) { return evt.respondWith(caches.delete(this.cache.version).then(() => fetch(request)))