124 lines
3.1 KiB
Vue
124 lines
3.1 KiB
Vue
<script setup>
|
|
import {computed, onMounted, onUnmounted, ref, watch} from "vue";
|
|
import 'photoswipe/style.css';
|
|
import "photoswipe-dynamic-caption-plugin/photoswipe-dynamic-caption-plugin.css";
|
|
import PhotoSwipeDynamicCaption from "../../../node_modules/photoswipe-dynamic-caption-plugin/photoswipe-dynamic-caption-plugin.esm";
|
|
import PhotoCaption from "components/photos/PhotoCaption.vue";
|
|
import PhotoSwipeLightbox from "../../../node_modules/photoswipe/dist/photoswipe-lightbox.esm"
|
|
import PhotoSwipe from "../../../node_modules/photoswipe/dist/photoswipe.esm"
|
|
import {useRoute, useRouter} from "vue-router";
|
|
import {usePhotosStore} from "stores/Photos";
|
|
|
|
const props = defineProps({
|
|
galleryId: {
|
|
type: String,
|
|
required: false,
|
|
default: () => "photogallery"
|
|
},
|
|
photos: {
|
|
type: Array,
|
|
required: true
|
|
}
|
|
})
|
|
|
|
|
|
const route = useRoute();
|
|
const $router = useRouter();
|
|
|
|
let $lightbox = ref(null);
|
|
|
|
const initLightbox = () => {
|
|
if ($lightbox.value && $lightbox.value.pswp) {
|
|
// lightbox already initialized
|
|
return
|
|
}
|
|
|
|
$lightbox.value = new PhotoSwipeLightbox({
|
|
gallery: '#' + props.galleryId,
|
|
children: 'a',
|
|
pswpModule: () => PhotoSwipe,
|
|
});
|
|
|
|
let captionPlugin = new PhotoSwipeDynamicCaption($lightbox.value, {
|
|
type: 'auto',
|
|
});
|
|
|
|
$lightbox.value.init();
|
|
}
|
|
|
|
onMounted(() => {
|
|
initLightbox();
|
|
|
|
// todo: tohle nefunguje, sice se galerie zavre, ale i tak se user presmeruje na predchozi stranku
|
|
window.onpopstate = function (e) {
|
|
if (!$lightbox.value || !$lightbox.value.pswp) {
|
|
initLightbox();
|
|
}
|
|
|
|
if ($lightbox.value && $lightbox.value.pswp)
|
|
$lightbox.value.pswp.close();
|
|
};
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
if ($lightbox.value) {
|
|
$lightbox.value.destroy();
|
|
$lightbox.value = null;
|
|
}
|
|
});
|
|
|
|
const openedPhoto = computed(() => usePhotosStore().openedPhoto);
|
|
watch(() => [openedPhoto.value, $lightbox.value], () => {
|
|
if (!$lightbox.value || !openedPhoto.value) return;
|
|
|
|
const idx = props.photos.findIndex(p => p.id === openedPhoto.value.id);
|
|
if (idx >= 0) {
|
|
$lightbox.value.loadAndOpen(idx);
|
|
usePhotosStore().setOpenedPhoto(null);
|
|
}
|
|
}, {immediate: true});
|
|
|
|
const isCollapsed = ref(false);
|
|
</script>
|
|
|
|
<template>
|
|
<div :id="galleryId" :class="{row: true, collapsed: isCollapsed}">
|
|
<div
|
|
v-for="photo in photos" :key="photo.id"
|
|
style="min-height: 100px"
|
|
class="col-6 col-sm-4 col-md-4 col-lg-3 q-pa-sm"
|
|
>
|
|
<a
|
|
:href="photo.url"
|
|
:data-pswp-width="photo.width"
|
|
:data-pswp-height="photo.height"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
<q-img
|
|
spinner-color="primary"
|
|
class="rounded-borders"
|
|
:src="photo.thumbnailUrl"
|
|
alt=""
|
|
>
|
|
<div class="absolute-bottom" v-if="photo.name !== ''">
|
|
{{ photo.name }}
|
|
</div>
|
|
</q-img>
|
|
<PhotoCaption :photo="photo"/>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- <q-btn @click="isCollapsed=!isCollapsed">{{isCollapsed ? 'Sbalit' : "Rozbalit"}}</q-btn>-->
|
|
|
|
|
|
</template>
|
|
|
|
<style>
|
|
.collapsed {
|
|
max-height: 50px;
|
|
overflow: hidden
|
|
}
|
|
</style>
|