From cee1c3dfd2c67663d39424b1d1a560bb5ff2bbe0 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Tue, 16 Jul 2024 10:42:43 +1000 Subject: [PATCH] cleaning up the global javascript --- wwwroot/index.html | 2 +- wwwroot/js/csharp.js | 47 -------------------------------------------- wwwroot/js/script.js | 32 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 48 deletions(-) delete mode 100644 wwwroot/js/csharp.js create mode 100644 wwwroot/js/script.js diff --git a/wwwroot/index.html b/wwwroot/index.html index bfb0817..6304722 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -18,7 +18,7 @@ - + diff --git a/wwwroot/js/csharp.js b/wwwroot/js/csharp.js deleted file mode 100644 index d18fc90..0000000 --- a/wwwroot/js/csharp.js +++ /dev/null @@ -1,47 +0,0 @@ -window.injectCSharp = async function (helper) { - window.CSHARP = helper -} - - -async function delay(t) { - return new Promise((resolve) => { - setTimeout(resolve, t); - }); -} - -async function removeElementById(id) { - document.getElementById(id)?.remove() -} - -function scrollToId(id) { - const element = document.getElementById(id); - if (element instanceof HTMLElement) { - element.scrollIntoView({ - behavior: "smooth", - block: "start", - inline: "nearest" - }); - } -} - -function toggleDetails(id) { - const element = document.getElementById(id) - if (element instanceof HTMLDetailsElement) - element.open = !element.open -} - -function cacheBust(url) { - fetch(new Request(url), { - headers: new Headers({ - "pragma": "no-cache", - "cache-control": "no-cache" - }), - mode: 'no-cors', - cache: 'no-cache', - }) - .finally(() => { - let els = document.querySelectorAll(`[src="${url}"]`) - els.forEach(el => el.removeAttribute('src')) - els.forEach(el => el.src = url) - }) -} \ No newline at end of file diff --git a/wwwroot/js/script.js b/wwwroot/js/script.js new file mode 100644 index 0000000..5351165 --- /dev/null +++ b/wwwroot/js/script.js @@ -0,0 +1,32 @@ +window.injectCSharp = async function (helper) { window.CSHARP = helper } + +async function delay(t) { return new Promise((resolve) => { setTimeout(resolve, t) }) } + +async function removeElementById(id) { document.getElementById(id)?.remove() } + +function scrollToId(id) { + const element = document.getElementById(id) + if (element instanceof HTMLElement) + element.scrollIntoView({behavior: "smooth",block: "start",inline: "nearest"}) +} + +function toggleDetails(id) { + const element = document.getElementById(id) + if (element instanceof HTMLDetailsElement) element.open = !element.open +} + +function cacheBust(url) { + fetch(new Request(url), { + headers: new Headers({ + "pragma": "no-cache", + "cache-control": "no-cache" + }), + mode: 'no-cors', + cache: 'no-cache', + }) + .finally(() => { + let els = document.querySelectorAll(`[src="${url}"]`) + els.forEach(el => el.removeAttribute('src')) + els.forEach(el => el.src = url) + }) +} \ No newline at end of file