1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2026-06-22 07:48:42 +00:00
Files
jekyll-theme-chirpy/_javascript/modules/components/img-popup.js
T
Cotes Chung 7496dd41fa feat(theme): persist user theme preferences (#2756)
- Migrate theme persistence from `sessionStorage` to `localStorage`
- Rename theme HTML attribute to `data-bs-theme` for Bootstrap compatibility
- Trim and compile CSS according to the chosen theme mode
2026-06-17 23:20:12 +08:00

55 lines
1.1 KiB
JavaScript

/**
* Set up image popup
*
* Dependencies: https://github.com/biati-digital/glightbox
*/
const lightImages = '.popup:not(.dark)';
const darkImages = '.popup:not(.light)';
let selector = lightImages;
function swapImages(current, reverse) {
if (selector === lightImages) {
selector = darkImages;
} else {
selector = lightImages;
}
if (reverse === null) {
reverse = GLightbox({ selector: `${selector}` });
}
return [reverse, current];
}
export function imgPopup() {
if (document.querySelector('.popup') === null) {
return;
}
const hasDualImages = !(
document.querySelector('.popup.light') === null &&
document.querySelector('.popup.dark') === null
);
if (Theme.isDark) {
selector = darkImages;
}
let current = GLightbox({ selector: `${selector}` });
if (hasDualImages && Theme.isToggleable) {
let reverse = null;
window.addEventListener('message', (event) => {
if (
event.source === window &&
event.data &&
event.data.id === Theme.eventId
) {
[current, reverse] = swapImages(current, reverse);
}
});
}
}