2024-05-30 12:25:32 +02:00
|
|
|
import { ApplicationController } from '../application_controller';
|
2024-04-08 10:23:07 +02:00
|
|
|
import lightGallery from 'lightgallery';
|
|
|
|
import { LightGallery } from 'lightgallery/lightgallery';
|
|
|
|
import lgThumbnail from 'lightgallery/plugins/thumbnail';
|
|
|
|
import lgZoom from 'lightgallery/plugins/zoom';
|
|
|
|
import lgRotate from 'lightgallery/plugins/rotate';
|
2024-04-30 17:22:29 +02:00
|
|
|
import lgHash from 'lightgallery/plugins/hash';
|
2024-04-08 10:23:07 +02:00
|
|
|
import 'lightgallery/css/lightgallery-bundle.css';
|
|
|
|
|
2024-05-30 12:25:32 +02:00
|
|
|
export default class extends ApplicationController {
|
2024-04-08 10:23:07 +02:00
|
|
|
lightGallery?: LightGallery;
|
|
|
|
|
|
|
|
connect(): void {
|
|
|
|
const options = {
|
2024-04-30 17:22:29 +02:00
|
|
|
plugins: [lgZoom, lgThumbnail, lgRotate, lgHash],
|
2024-04-08 10:23:07 +02:00
|
|
|
flipVertical: false,
|
|
|
|
flipHorizontal: false,
|
|
|
|
animateThumb: false,
|
|
|
|
zoomFromOrigin: false,
|
|
|
|
allowMediaOverlap: true,
|
|
|
|
toggleThumb: true,
|
2024-04-24 10:27:46 +02:00
|
|
|
selector: '.gallery-link',
|
|
|
|
// license key is not mandatory for open source projects but we purchased
|
|
|
|
// an organization license to show our support (see https://www.lightgalleryjs.com/license/)
|
|
|
|
licenseKey: import.meta.env.VITE_LIGHTGALLERY_LICENSE_KEY
|
2024-04-08 10:23:07 +02:00
|
|
|
};
|
|
|
|
|
2024-04-30 17:22:29 +02:00
|
|
|
const gallery = document.querySelector('.gallery');
|
|
|
|
|
|
|
|
if (gallery != null) {
|
|
|
|
gallery.addEventListener('lgBeforeOpen', () => {
|
|
|
|
window.history.pushState({}, 'Gallery opened');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-08 10:23:07 +02:00
|
|
|
this.lightGallery = lightGallery(this.element as HTMLElement, options);
|
|
|
|
|
|
|
|
const downloadIcon = document.querySelector('.lg-download');
|
|
|
|
|
|
|
|
if (downloadIcon != null) {
|
|
|
|
downloadIcon.removeAttribute('target');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnect(): void {
|
|
|
|
this.lightGallery?.destroy();
|
|
|
|
}
|
|
|
|
}
|