From da6a82df93c942c1b0e87656c4e728d879c40801 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 7 Jul 2023 10:24:04 -0500 Subject: [PATCH] WIP --- static/preload.mjs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/static/preload.mjs b/static/preload.mjs index 0fe41d1..5c24c0b 100644 --- a/static/preload.mjs +++ b/static/preload.mjs @@ -38,8 +38,7 @@ function preloadinate() { document.querySelectorAll("a").forEach(el => { // TODO: this would ideally happen in the background (service worker)? if (el.href.indexOf("#") == -1 && el.href.indexOf(".") == -1 && (el.href.startsWith("https://lyte.dev") || el.href.startsWith("http://localhost:1313"))) { - el.addEventListener("mouseover", (_ev) => putCache(el.href)) - el.addEventListener("click", async (ev) => { + const router = async function(ev) { if (el.href == window.location.href) { ev.preventDefault() return false @@ -61,21 +60,11 @@ function preloadinate() { } else { ev.preventDefault() await putCache(el.href) - const rep = [window.location.href, window.scrollX, window.scrollY] - history.replaceState(rep, "") - console.log("replaceState: ", rep) - if (!loadCache(el.href)) { - window.location.href = el.href - window.location.reload() - return true - } - window.scrollTo(0, 0) - history.pushState([el.href, 0, 0], "", el.href) - preloadinate() - ev.preventDefault() - return false + return router(ev) } - }) + } + el.addEventListener("mouseover", (_ev) => putCache(el.href)) + el.addEventListener("click", router) } }) }