fix: remove extra dual-mode images from lightbox (#1883)
This commit is contained in:
parent
b641b36480
commit
5c5910f1fc
1 changed files with 38 additions and 3 deletions
|
@ -4,12 +4,47 @@
|
||||||
* Dependencies: https://github.com/biati-digital/glightbox
|
* Dependencies: https://github.com/biati-digital/glightbox
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const IMG_CLASS = 'popup';
|
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}` });
|
||||||
|
}
|
||||||
|
|
||||||
export function imgPopup() {
|
export function imgPopup() {
|
||||||
if (document.getElementsByClassName(IMG_CLASS).length === 0) {
|
if (document.querySelector('.popup') === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLightbox({ selector: `.${IMG_CLASS}` });
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue