diff --git a/assets/ts/gallery.ts b/assets/ts/gallery.ts index 74b6153..208194f 100644 --- a/assets/ts/gallery.ts +++ b/assets/ts/gallery.ts @@ -21,16 +21,16 @@ class StackGallery { private items: PhotoSwipeItem[] = []; constructor(container: HTMLElement, galleryUID = 1) { + if (window.PhotoSwipe == undefined) { + console.error("PhotoSwipe lib not loaded."); + return; + } + this.galleryUID = galleryUID; StackGallery.createGallery(container); this.loadItems(container); - - StackGallery.loadPS().then(() => { - const pswp = document.querySelector('.pswp') as HTMLDivElement; - pswp.style.removeProperty('display'); - this.bindClick(); - }); + this.bindClick(); } private loadItems(container: HTMLElement) { @@ -109,20 +109,6 @@ class StackGallery { } } - /** - * Load PhotoSwipe library dynamically - */ - public static loadPS() { - const tasks = [ - loadScript("https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"), - loadScript("https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"), - loadStyle("https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css"), - loadStyle("https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css") - ]; - - return Promise.all(tasks); - } - public open(index: number) { const pswp = document.querySelector('.pswp') as HTMLDivElement; const ps = new window.PhotoSwipe(pswp, window.PhotoSwipeUI_Default, this.items, { diff --git a/layouts/partials/article/components/photoswipe.html b/layouts/partials/article/components/photoswipe.html index 290872c..ed1c677 100644 --- a/layouts/partials/article/components/photoswipe.html +++ b/layouts/partials/article/components/photoswipe.html @@ -1,5 +1,5 @@ -
\ No newline at end of file + + + + + + + \ No newline at end of file