Skip to content

Commit

Permalink
Merge branch 'photoswipe' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Jan 14, 2024
2 parents 9426199 + b6721fa commit 6582d93
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/services/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const fullscreenIconsHtml = `<svg aria-hidden="true" class="pswp__icn" viewBox="
function initLightbox() {
const lightbox = new PhotoSwipeLightbox({
clickToCloseNonZoomable: false,
tapAction(_, event) {
// Close lightbox on background tap
if (event.target.classList.contains('pswp__item')) {
this.close();
} else {
// Toggle controls (default behavior)
this.element?.classList.toggle('pswp--ui-visible');
}
},
pswpModule: () => import('photoswipe'),
});

Expand Down Expand Up @@ -61,6 +70,19 @@ function initLightbox() {
lightbox.on('close', () => fsApi.isFullscreen() && fsApi.exit());
});

lightbox.on('bindEvents', () => {
const h = (e) => {
e.preventDefault();
lightbox.pswp.close();
};
window.addEventListener('scroll', h, { passive: false });
document.addEventListener('wheel', h, { passive: false });
lightbox.on('destroy', () => {
window.removeEventListener('scroll', h, { passive: false });
document.removeEventListener('wheel', h, { passive: false });
});
});

// Add filters for the correct open/close animation
lightbox.addFilter('placeholderSrc', (placeholderSrc, content) => {
const thumb = document.getElementById(content.data.pid);
Expand Down

0 comments on commit 6582d93

Please sign in to comment.