Prettier
This commit is contained in:
@@ -29,9 +29,11 @@ if (themeToggle) {
|
||||
const dialog = document.querySelector('dialog.lightbox');
|
||||
const lbContent = dialog?.querySelector('.lb-content');
|
||||
const lbCaption = dialog?.querySelector('#lb-caption, .lb-caption');
|
||||
let lightboxOpener = null;
|
||||
|
||||
function openLightbox(name, type, caption) {
|
||||
if (!dialog || !lbContent || !lbCaption) return;
|
||||
lightboxOpener = document.activeElement;
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
if (type === 'video') {
|
||||
@@ -55,6 +57,10 @@ function openLightbox(name, type, caption) {
|
||||
|
||||
function closeLightbox() {
|
||||
if (!dialog) return;
|
||||
if (lightboxOpener && typeof lightboxOpener.focus === 'function') {
|
||||
lightboxOpener.focus();
|
||||
}
|
||||
lightboxOpener = null;
|
||||
document.body.style.overflow = '';
|
||||
if (lbContent) lbContent.innerHTML = '';
|
||||
if (lbCaption) lbCaption.textContent = '';
|
||||
@@ -73,8 +79,8 @@ if (dialog) {
|
||||
});
|
||||
dialog.addEventListener('close', closeLightbox);
|
||||
dialog.addEventListener('cancel', closeLightbox);
|
||||
dialog.addEventListener('click', () => {
|
||||
if (e.target === dialog) dialog.close();
|
||||
dialog.addEventListener('click', (e) => {
|
||||
if (e.target === dialog) closeLightbox();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user