From a815c291074b454d4bb1a31067cd363c84df1360 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 12 Dec 2025 19:21:22 +0100 Subject: refactor(frontend): remove JS files --- frontend/index.ts | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 frontend/index.ts (limited to 'frontend') diff --git a/frontend/index.ts b/frontend/index.ts deleted file mode 100644 index d3c974f..0000000 --- a/frontend/index.ts +++ /dev/null @@ -1,47 +0,0 @@ -import htmx from "htmx.org"; - -htmx.config.historyRestoreAsHxRequest = false; -htmx.config.includeIndicatorStyles = false; - -function setupAnchors() { - document.querySelectorAll("a").forEach((e) => { - // stuff related to external links are already handled in the backend - if (!e.href.startsWith(window.location.origin) && /https?:\/\//.test(e.href)) return; - // stuff related to RSS must not be processed by HTMX. - if (e.href.endsWith("/rss/") || e.href.endsWith("/rss")) { - e.target = "_blank"; - return; - } - - if (e.href == window.location.href) e.classList.add("target"); - else e.classList.remove("target"); - - if (e.hasAttribute("hx-trigger")) return; - - e.setAttribute("hx-get", e.href); - e.setAttribute("hx-trigger", "click"); - e.setAttribute("hx-target", "#content"); - e.setAttribute("hx-swap", "outerHTML show:body:top"); - htmx.process(e); - }); -} - -// updating history and window title -document.addEventListener("htmx:afterSettle", (e) => { - if (e.detail.xhr === undefined) return; - const title = e.detail.xhr.getResponseHeader("Updated-Title"); - if (title?.length !== 0) document.title = decodeURIComponent(title).replaceAll("+", " "); - const quote = e.detail.xhr.getResponseHeader("Updated-Quote"); - if (quote?.length !== 0) - document.querySelector("#quote")!.innerHTML = - "« " + decodeURIComponent(quote).replaceAll("+", " ") + " »"; - setupAnchors(); -}); - -document.body.addEventListener("htmx:beforeSwap", function (e) { - if (e.detail.xhr.status !== 404) return; - e.detail.shouldSwap = true; - e.detail.isError = false; -}); - -setupAnchors(); -- cgit v1.2.3