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 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-11-16 17:49:55 +03:00
|
|
|
if (Theme.visualState === Theme.DARK) {
|
2024-07-29 07:17:11 +03:00
|
|
|
selector = darkImages;
|
|
|
|
}
|
|
|
|
|
2024-08-19 16:05:39 +03:00
|
|
|
let current = GLightbox({ selector: `${selector}` });
|
|
|
|
|
2024-11-16 17:49:55 +03:00
|
|
|
if (hasDualImages && Theme.switchable) {
|
2024-08-19 16:05:39 +03:00
|
|
|
let reverse = null;
|
2024-07-29 07:17:11 +03:00
|
|
|
|
|
|
|
window.addEventListener('message', (event) => {
|
2024-11-16 17:49:55 +03:00
|
|
|
if (event.source === window && event.data && event.data.id === Theme.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
|
|
|
}
|