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;
|
|
|
|
|
2024-08-19 16:05:39 +03:00
|
|
|
function updateImages(current, reverse) {
|
2024-07-29 07:17:11 +03:00
|
|
|
if (selector === lightImages) {
|
|
|
|
selector = darkImages;
|
|
|
|
} else {
|
|
|
|
selector = lightImages;
|
|
|
|
}
|
|
|
|
|
2024-08-19 16:05:39 +03:00
|
|
|
if (reverse === null) {
|
|
|
|
reverse = GLightbox({ selector: `${selector}` });
|
|
|
|
}
|
|
|
|
|
|
|
|
[current, reverse] = [reverse, current];
|
2024-07-29 07:17:11 +03:00
|
|
|
}
|
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-08-19 16:05:39 +03:00
|
|
|
const hasDualImages = !(
|
|
|
|
document.querySelector('.popup.light') === null &&
|
|
|
|
document.querySelector('.popup.dark') === null
|
|
|
|
);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-08-19 16:05:39 +03:00
|
|
|
let current = GLightbox({ selector: `${selector}` });
|
|
|
|
|
|
|
|
if (hasDualImages && document.getElementById('mode-toggle')) {
|
|
|
|
let reverse = null;
|
2024-07-29 07:17:11 +03:00
|
|
|
|
|
|
|
window.addEventListener('message', (event) => {
|
|
|
|
if (
|
|
|
|
event.source === window &&
|
|
|
|
event.data &&
|
|
|
|
event.data.direction === ModeToggle.ID
|
|
|
|
) {
|
2024-08-19 16:05:39 +03:00
|
|
|
updateImages(current, reverse);
|
2024-07-29 07:17:11 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-03-18 01:28:44 +03:00
|
|
|
}
|