File tree Expand file tree Collapse file tree 1 file changed +38
-3
lines changed
_javascript/modules/components Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Original file line number Diff line number Diff line change 44 * Dependencies: https://github.com/biati-digital/glightbox
55 */
66
7- const IMG_CLASS = 'popup' ;
7+ const html = document . documentElement ;
8+ const lightImages = '.popup:not(.dark)' ;
9+ const darkImages = '.popup:not(.light)' ;
10+ let selector = lightImages ;
11+
12+ function updateImages ( lightbox ) {
13+ if ( selector === lightImages ) {
14+ selector = darkImages ;
15+ } else {
16+ selector = lightImages ;
17+ }
18+
19+ lightbox . destroy ( ) ;
20+ lightbox = GLightbox ( { selector : `${ selector } ` } ) ;
21+ }
822
923export function imgPopup ( ) {
10- if ( document . getElementsByClassName ( IMG_CLASS ) . length === 0 ) {
24+ if ( document . querySelector ( '.popup' ) === null ) {
1125 return ;
1226 }
1327
14- GLightbox ( { selector : `.${ IMG_CLASS } ` } ) ;
28+ if (
29+ ( html . hasAttribute ( 'data-mode' ) &&
30+ html . getAttribute ( 'data-mode' ) === 'dark' ) ||
31+ ( ! html . hasAttribute ( 'data-mode' ) &&
32+ window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches )
33+ ) {
34+ selector = darkImages ;
35+ }
36+
37+ let lightbox = GLightbox ( { selector : `${ selector } ` } ) ;
38+
39+ if ( document . getElementById ( 'mode-toggle' ) ) {
40+ window . addEventListener ( 'message' , ( event ) => {
41+ if (
42+ event . source === window &&
43+ event . data &&
44+ event . data . direction === ModeToggle . ID
45+ ) {
46+ updateImages ( lightbox ) ;
47+ }
48+ } ) ;
49+ }
1550}
You can’t perform that action at this time.
0 commit comments