diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-01 10:14:20 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-01 10:14:20 +0200 |
commit | 3fa55dba1b0ca408a10e7456a6d4308dd114c2f6 (patch) | |
tree | f1f378662406a5f091816ca97c3f1ccfb5210eef /server/src/routes/ui/style/transition.js | |
parent | d857684dd6358fb5ff979ca09ac78b5649b0f411 (diff) | |
download | jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar.bz2 jellything-3fa55dba1b0ca408a10e7456a6d4308dd114c2f6.tar.zst |
move stylesheets and refactor js bundler
Diffstat (limited to 'server/src/routes/ui/style/transition.js')
-rw-r--r-- | server/src/routes/ui/style/transition.js | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/server/src/routes/ui/style/transition.js b/server/src/routes/ui/style/transition.js deleted file mode 100644 index 7d39176..0000000 --- a/server/src/routes/ui/style/transition.js +++ /dev/null @@ -1,75 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2023 metamuffin <metamuffin.org> -*/ -/// <reference lib="dom" /> - -const duration = 0.2 -globalThis.addEventListener("load", () => { - patch_page() -}) - -globalThis.addEventListener("popstate", (_e) => { - transition_to(window.location.href, true) - // transition_to(_e.state.href, true) -}) - -function patch_page() { - document.querySelectorAll("a").forEach(el => { - el.addEventListener("click", async ev => { - ev.preventDefault() - await transition_to(el.href) - }) - }) -} - -async function transition_to(href, back) { - const trigger_load = prepare_load(href, back) - await fade(false) - trigger_load() -} - -function prepare_load(href, back) { - const r_promise = fetch(href) - return async () => { - let rt = "" - try { - const r = await r_promise - if (!r.ok) return document.body.innerHTML = "<h1>error</h1>" - rt = await r.text() - } catch (e) { - console.error(e) - return - } - const [head, body] = rt.split("<head>")[1].split("</head>") - document.head.innerHTML = head - document.body.outerHTML = body - fade(true) - // if (!back) window.history.pushState({href}, "", href) - if (!back) window.history.pushState({}, "", href) - patch_page() - } -} - -function fade(dir) { - const overlay = document.createElement("div") - overlay.style.position = "absolute" - overlay.style.left = "0px" - overlay.style.top = "0px" - overlay.style.width = "100vw" - overlay.style.height = "100vh" - overlay.style.backgroundColor = dir ? "black" : "transparent" - overlay.style.transition = `background-color ${duration}s` - overlay.style.zIndex = 99999; - setTimeout(() => { - overlay.style.backgroundColor = dir ? "transparent" : "black" - }, 0) - document.body.appendChild(overlay) - return new Promise(res => { - setTimeout(() => { - if (dir) document.body.removeChild(overlay) - res() - }, duration * 1000) - }) -}
\ No newline at end of file |