fix duplicate image IDs and migrate TitleImgParallax to Svelte 5 runes
Replace id="image" with class="image" in both Card and TitleImgParallax components to prevent duplicate IDs when multiple instances appear on the same page. Update TitleImgParallax to use Svelte 5 $props() and $state() runes instead of legacy export let syntax, and modernize event handlers to use onload/onclick attributes.
This commit is contained in:
@@ -95,7 +95,7 @@ const img_name = $derived(imageShortName + ".webp?v=" + recipe.dateModified);
|
|||||||
z-index: 5;
|
z-index: 5;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
#image{
|
.image{
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 255px;
|
height: 255px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
@@ -259,9 +259,9 @@ const img_name = $derived(imageShortName + ".webp?v=" + recipe.dateModified);
|
|||||||
<div class=div_div_image >
|
<div class=div_div_image >
|
||||||
<div class=div_image style="background-image:url(https://bocken.org/static/rezepte/placeholder/{img_name})">
|
<div class=div_image style="background-image:url(https://bocken.org/static/rezepte/placeholder/{img_name})">
|
||||||
<noscript>
|
<noscript>
|
||||||
<img id=image class="backdrop_blur" src="https://bocken.org/static/rezepte/thumb/{img_name}" loading={loading_strat} alt="{recipe.alt}"/>
|
<img class="image backdrop_blur" src="https://bocken.org/static/rezepte/thumb/{img_name}" loading={loading_strat} alt="{recipe.alt}"/>
|
||||||
</noscript>
|
</noscript>
|
||||||
<img class:blur={!isloaded} id=image class="backdrop_blur" src={'https://bocken.org/static/rezepte/thumb/' + imageShortName + '.webp'} loading={loading_strat} alt="{recipe.alt}" on:load={() => isloaded=true}/>
|
<img class="image backdrop_blur" class:blur={!isloaded} src={'https://bocken.org/static/rezepte/thumb/' + imageShortName + '.webp'} loading={loading_strat} alt="{recipe.alt}" on:load={() => isloaded=true}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if showFavoriteIndicator && isFavorite}
|
{#if showFavoriteIndicator && isFavorite}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
export let src
|
|
||||||
export let placeholder_src
|
|
||||||
let isloaded=false
|
|
||||||
let isredirected=false
|
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
let { src, placeholder_src } = $props();
|
||||||
|
|
||||||
|
let isloaded = $state(false);
|
||||||
|
let isredirected = $state(false);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const el = document.querySelector("img")
|
const el = document.querySelector("img")
|
||||||
if(el.complete){
|
if(el?.complete){
|
||||||
isloaded = true
|
isloaded = true
|
||||||
}
|
}
|
||||||
fetch(src, { method: 'HEAD' })
|
fetch(src, { method: 'HEAD' })
|
||||||
@@ -77,7 +79,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#image{
|
.image{
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -124,7 +126,7 @@ div:has(.placeholder){
|
|||||||
height: max(60dvh,600px);
|
height: max(60dvh,600px);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.unblur#image{
|
.unblur.image{
|
||||||
filter: blur(0px) !important;
|
filter: blur(0px) !important;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
@@ -172,17 +174,17 @@ dialog button{
|
|||||||
</style>
|
</style>
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<figure class="image-container">
|
<figure class="image-container">
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
<div class:zoom-in={isloaded && !isredirected} on:click={show_dialog_img}>
|
<div class:zoom-in={isloaded && !isredirected} onclick={show_dialog_img}>
|
||||||
<div class=placeholder style="background-image:url({placeholder_src})" >
|
<div class=placeholder style="background-image:url({placeholder_src})" >
|
||||||
<div class=placeholder_blur>
|
<div class=placeholder_blur>
|
||||||
<img class:unblur={isloaded} id=image {src} on:load={() => {isloaded=true}} alt=""/>
|
<img class="image" class:unblur={isloaded} {src} onload={() => {isloaded=true}} alt=""/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<noscript>
|
<noscript>
|
||||||
<div class=placeholder style="background-image:url({placeholder_src})" >
|
<div class=placeholder style="background-image:url({placeholder_src})" >
|
||||||
<img class="unblur" id=image {src} on:load={() => {isloaded=true}} alt=""/>
|
<img class="image unblur" {src} onload={() => {isloaded=true}} alt=""/>
|
||||||
</div>
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
</div>
|
</div>
|
||||||
@@ -193,7 +195,7 @@ dialog button{
|
|||||||
<dialog id=img_carousel>
|
<dialog id=img_carousel>
|
||||||
<div>
|
<div>
|
||||||
<img class:unblur={isloaded} {src} alt="">
|
<img class:unblur={isloaded} {src} alt="">
|
||||||
<button class=action_button on:keydown={(event) => do_on_key(event, 'Enter', false, close_dialog_img)} on:click={close_dialog_img}>
|
<button class=action_button onkeydown={(event) => do_on_key(event, 'Enter', false, close_dialog_img)} onclick={close_dialog_img}>
|
||||||
<Cross fill=white width=2rem height=2rem></Cross>
|
<Cross fill=white width=2rem height=2rem></Cross>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user