2023-03-18 01:28:44 +03:00
|
|
|
/**
|
|
|
|
* Set up image popup
|
|
|
|
*
|
2024-04-17 01:10:01 +03:00
|
|
|
* Dependencies: https://github.com/biati-digital/glightbox
|
2023-03-18 01:28:44 +03:00
|
|
|
*/
|
|
|
|
|
2024-07-29 07:17:11 +03:00
|
|
|
const html = document.documentElement;
|
|
|
|
const lightImages = '.popup:not(.dark)';
|
|
|
|
const darkImages = '.popup:not(.light)';
|
|
|
|
let selector = lightImages;
|
|
|
|
|
|
|
|
function updateImages(lightbox) {
|
|
|
|
if (selector === lightImages) {
|
|
|
|
selector = darkImages;
|
|
|
|
} else {
|
|
|
|
selector = lightImages;
|
|
|
|
}
|
|
|
|
|
|
|
|
lightbox.destroy();
|
|
|
|
lightbox = GLightbox({ selector: `${selector}` });
|
|
|
|
}
|
2024-04-17 01:10:01 +03:00
|
|
|
|
2023-03-18 01:28:44 +03:00
|
|
|
export function imgPopup() {
|
2024-07-29 07:17:11 +03:00
|
|
|
if (document.querySelector('.popup') === null) {
|
2023-03-18 01:28:44 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-29 07:17:11 +03:00
|
|
|
if (
|
|
|
|
(html.hasAttribute('data-mode') &&
|
|
|
|
html.getAttribute('data-mode') === 'dark') ||
|
|
|
|
(!html.hasAttribute('data-mode') &&
|
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
|
|
) {
|
|
|
|
selector = darkImages;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lightbox = GLightbox({ selector: `${selector}` });
|
|
|
|
|
|
|
|
if (document.getElementById('mode-toggle')) {
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
if (
|
|
|
|
event.source === window &&
|
|
|
|
event.data &&
|
|
|
|
event.data.direction === ModeToggle.ID
|
|
|
|
) {
|
|
|
|
updateImages(lightbox);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-03-18 01:28:44 +03:00
|
|
|
}
|