File tree 1 file changed +38
-3
lines changed
_javascript/modules/components
1 file changed +38
-3
lines changed Original file line number Diff line number Diff line change 4
4
* Dependencies: https://github.com/biati-digital/glightbox
5
5
*/
6
6
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
+ }
8
22
9
23
export function imgPopup ( ) {
10
- if ( document . getElementsByClassName ( IMG_CLASS ) . length === 0 ) {
24
+ if ( document . querySelector ( '.popup' ) === null ) {
11
25
return ;
12
26
}
13
27
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
+ }
15
50
}
You can’t perform that action at this time.
0 commit comments