|
9 | 9 | import { Switch } from '@skeletonlabs/skeleton-svelte'; |
10 | 10 | import { page } from '$app/state'; |
11 | 11 | import { onMount, tick, untrack } from 'svelte'; |
12 | | - import { goto } from '$app/navigation'; |
| 12 | + import { goto, replaceState } from '$app/navigation'; |
13 | 13 | import ApparatPopover from './ApparatPopover.svelte'; |
14 | 14 | import handleFromSigil from '$lib/functions/handleFromSigil'; |
| 15 | + import { browser } from '$app/environment'; |
15 | 16 |
|
16 | 17 | /** @type {{data: import('./$types').PageData}} */ |
17 | 18 | let { data } = $props(); |
|
227 | 228 | tick().then(() => { |
228 | 229 | addApparatTriggerListeners(); |
229 | 230 | addFasskommTriggerListeners(); |
| 231 | + openFasskommFromHash(); |
230 | 232 | }); |
231 | 233 | return Promise.resolve(); |
232 | 234 | }; |
|
285 | 287 | FasskommStore.id = ''; |
286 | 288 | FasskommStore.commentary = ''; |
287 | 289 | }; |
| 290 | + const openFasskommFromHash = () => { |
| 291 | + const id = page.url.hash; |
| 292 | + if (!id) return; |
| 293 | + const el = document.querySelector(`a.fasskommanchor[href="${CSS.escape(id)}"]`); |
| 294 | + if (el instanceof HTMLAnchorElement && el.href) { |
| 295 | + el.click(); |
| 296 | + } |
| 297 | + }; |
288 | 298 |
|
289 | 299 | // Triggers |
290 | 300 | const addFasskommTriggerListeners = () => { |
|
298 | 308 | el.removeEventListener('click', onClickFasskommTrigger); |
299 | 309 | }); |
300 | 310 | }; |
301 | | - const onClickFasskommTrigger = (/** @type { Event } */ ev) => { |
302 | | - if (ev.target instanceof HTMLElement) { |
303 | | - fillFasskommStore(ev.target, false); |
| 311 | +
|
| 312 | + const onClickFasskommTrigger = (ev) => { |
| 313 | + const a = ev.target instanceof HTMLAnchorElement ? ev.target : ev.target?.closest?.('a'); |
| 314 | + if (!a) return; |
| 315 | +
|
| 316 | + ev.preventDefault(); |
| 317 | + const href = a.getAttribute('href'); |
| 318 | +
|
| 319 | + if (browser && href) { |
| 320 | + const next = new URL(href, page.url); |
| 321 | + replaceState(next.href, {}); |
304 | 322 | } |
| 323 | + fillFasskommStore(a, false); |
305 | 324 | }; |
306 | 325 |
|
| 326 | +
|
307 | 327 | // -------------------------------------- |
308 | 328 | // Apparate |
309 | 329 | // -------------------------------------- |
|
409 | 429 | synchro = false; |
410 | 430 | } |
411 | 431 | }); |
| 432 | +
|
| 433 | + let wasFasskommOpen = false; |
| 434 | + $effect(() => { |
| 435 | + if (typeof window === 'undefined') return; |
| 436 | + const isOpen = !!FasskommStore.elTrigger; |
| 437 | + if (wasFasskommOpen && !isOpen && window.location.hash.startsWith('#fasskomm-')) { |
| 438 | + replaceState(`${page.url.pathname}${page.url.search}`, {}); |
| 439 | + } |
| 440 | + wasFasskommOpen = isOpen; |
| 441 | + }); |
| 442 | +
|
412 | 443 | let gotoThirties = $state(Number(data.thirties)); |
413 | 444 | </script> |
414 | 445 |
|
|
0 commit comments