zwischenstand

This commit is contained in:
2025-10-02 09:03:39 +00:00
parent 099530b7c8
commit f3dc0dc9bd
52 changed files with 994 additions and 5602 deletions

View File

@@ -1,21 +1,25 @@
import type { Action } from "svelte/action"
import { overlays } from "./store"
export const spaLink: Action<HTMLAnchorElement> = (node) => {
const onClick = (event: MouseEvent) => {
if (node.dataset.spaPrevent && node.dataset.spaPrevent !== "false") {
return
}
const anchor = event.currentTarget as HTMLAnchorElement
if ((anchor.target === "" || anchor.target === "_self") && anchor.href.startsWith(window.location.origin)) {
const isSelfTarget = anchor.target === "" || anchor.target === "_self"
if (isSelfTarget && anchor.href.startsWith(window.location.origin)) {
event.preventDefault()
const nextUrl = anchor.pathname + anchor.search + anchor.hash
const currentUrl = window.location.pathname + window.location.search + window.location.hash
const newUrl = anchor.pathname + anchor.search + anchor.hash
if (currentUrl === newUrl) {
window.scrollTo(0, 0)
if (nextUrl === currentUrl) {
window.scrollTo({ top: 0, behavior: "smooth" })
return
}
spaNavigate(anchor.pathname + anchor.search + anchor.hash)
spaNavigate(nextUrl)
}
}
@@ -29,26 +33,15 @@ export const spaLink: Action<HTMLAnchorElement> = (node) => {
}
export const spaNavigate = (to: string, options?: { replace?: boolean }) => {
overlays.update((current) => [])
window.scrollTo(0, 0)
//scroll to top of page
setTimeout(
() => {
window.scrollTo(0, 0)
},
100
)
if (options?.replace) {
window.history.replaceState(null, "", to)
} else {
window.history.pushState(null, "", to)
}
window.scrollTo({ top: 0, behavior: "smooth" })
}
export const spaBack = () => {
window.history.back()
}
// TODO: spaLinks container for containing {@html ...}