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 18, 2024
2 parents 027c366 + 9b21e0f commit cce373e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/services/lightbox-actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import pswpModule from 'photoswipe';
import 'photoswipe/photoswipe.css';
import '../../styles/shared/lighbox.scss';
import { getFullscreenAPI } from '../utils/fullscreen';
import { pinnedElements, unscrollTo } from './unscroll';

const prevHotKeys = ['a', 'ф', 'h', 'р', '4'];
const nextHotKeys = ['d', 'в', 'k', 'л', '6'];
Expand Down Expand Up @@ -150,6 +151,19 @@ function initLightbox() {
data.onDeactivate?.call(data, element);
});

// Compensate unwanted scroll after closing lightbox, which happens in some
// mobile browsers.
let pinnedEls = [];
lightbox.on('close', () => {
pinnedElements.capture();
pinnedEls = [...pinnedElements];
});
lightbox.on('destroy', () => {
const h = () => unscrollTo(pinnedEls);
window.addEventListener('scroll', h, { once: true });
setTimeout(() => window.removeEventListener('scroll', h, { once: true }), 500);
});

// Init
lightbox.init();
return lightbox;
Expand Down

0 comments on commit cce373e

Please sign in to comment.