gallery improvements

This commit is contained in:
lightling 2025-04-17 22:54:41 -04:00
parent 9dd1047c0f
commit 31ace99b7a
Signed by: lightling
GPG key ID: F1F29650D537C773
2 changed files with 42 additions and 10 deletions

View file

@ -3,8 +3,10 @@ import {
computed, computed,
onMounted, onMounted,
ref, ref,
useTemplateRef,
} from 'vue' } from 'vue'
import PrimeVueCarousel from 'primevue/carousel' import PrimeVueCarousel from 'primevue/carousel'
import PrimeVueImage from 'primevue/image'
import { marked } from 'marked' import { marked } from 'marked'
import type { import type {
GalleryEntry, GalleryEntry,
@ -27,6 +29,7 @@ const emits = defineEmits<{
(e: 'loaded'): void (e: 'loaded'): void
}>() }>()
const imageRef = useTemplateRef<HTMLImageElement>('image-ref' as any)
const ready = ref(false) const ready = ref(false)
const resolved = ref({} as GalleryEntry) const resolved = ref({} as GalleryEntry)
const currentRoute = getCurrentRoute() const currentRoute = getCurrentRoute()
@ -48,9 +51,9 @@ const fields = computed(() => {
}) })
const variants = computed(() => (resolved.value as GalleryEntryWithVariants).variants) const variants = computed(() => (resolved.value as GalleryEntryWithVariants).variants)
const currentSelection = defineModel('currentSelection', { type: Number, default: 0 }) const currentSelection = defineModel('currentSelection', { type: Number, default: 0 })
const currentUrl = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].url) const currentUrl = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value]?.url)
const currentAlt = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].alternativeText) const currentAlt = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value]?.alternativeText)
const currentCaption = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].caption) const currentCaption = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value]?.caption)
const carouselResponsiveOptions = [ const carouselResponsiveOptions = [
{ {
breakpoint: '800px', breakpoint: '800px',
@ -60,7 +63,29 @@ const carouselResponsiveOptions = [
] ]
const onVariantSelected = (event: Event, id: number) => { const onVariantSelected = (event: Event, id: number) => {
if (id === currentSelection.value) {
return
}
// prevent resizing from image swap by storing the previous width/height
if (!!imageRef.value) {
imageRef.value.style.width = `${imageRef.value.clientWidth}px`
imageRef.value.style.height = `${imageRef.value.clientHeight}px`
}
// remove the image for a frame so that it won't get stuck on the old one while the new one loads
currentSelection.value = -1
requestAnimationFrame(() => {
currentSelection.value = id currentSelection.value = id
// allow a second for the image to load before unsetting the width/height
setTimeout(() => {
if (!!imageRef.value) {
imageRef.value.style.width = `unset`
imageRef.value.style.height = `unset`
}
}, 1000)
})
} }
onMounted(async () => { onMounted(async () => {
@ -84,10 +109,14 @@ onMounted(async () => {
v-if='ready' v-if='ready'
) )
.view-outlet .view-outlet
img( .image-wrapper(
ref='image-ref'
)
PrimeVueImage(
:src='currentUrl' :src='currentUrl'
:title='currentCaption || currentAlt || description' :title='currentCaption || currentAlt || description'
:alt='currentAlt || currentCaption || description' :alt='currentAlt || currentCaption || description'
preview
) )
PrimeVueCarousel( PrimeVueCarousel(
:value='variants' :value='variants'
@ -122,5 +151,8 @@ onMounted(async () => {
</template> </template>
<style lang="sass"> <style lang="sass">
.p-carousel
img
cursor: pointer
max-width: 100%
</style> </style>

View file

@ -101,7 +101,7 @@ onMounted(async () => {
:class='[template]' :class='[template]'
) )
Transition Transition
.navigation( .list-controls(
v-if='ready' v-if='ready'
) )
.input.labeled-checkbox( .input.labeled-checkbox(