@@ -13,6 +13,7 @@ function showModal(event) {
13
13
if ( modalImage . style . display === 'none' ) {
14
14
lb . style . setProperty ( 'background-image' , 'url(' + source . src + ')' ) ;
15
15
}
16
+ updateModalImage ( ) ;
16
17
lb . style . display = "flex" ;
17
18
lb . focus ( ) ;
18
19
@@ -31,21 +32,26 @@ function negmod(n, m) {
31
32
return ( ( n % m ) + m ) % m ;
32
33
}
33
34
35
+ function updateModalImage ( ) {
36
+ const modalImage = gradioApp ( ) . getElementById ( "modalImage" ) ;
37
+ let currentButton = selected_gallery_button ( ) ;
38
+ let preview = gradioApp ( ) . querySelectorAll ( '.livePreview > img' ) ;
39
+ if ( opts . js_live_preview_in_modal_lightbox && preview . length > 0 ) {
40
+ // show preview image if available
41
+ modalImage . src = preview [ preview . length - 1 ] . src ;
42
+ } else if ( currentButton ?. children ?. length > 0 && modalImage . src != currentButton . children [ 0 ] . src ) {
43
+ modalImage . src = currentButton . children [ 0 ] . src ;
44
+ if ( modalImage . style . display === 'none' ) {
45
+ const modal = gradioApp ( ) . getElementById ( "lightboxModal" ) ;
46
+ modal . style . setProperty ( 'background-image' , `url(${ modalImage . src } )` ) ;
47
+ }
48
+ }
49
+ }
50
+
34
51
function updateOnBackgroundChange ( ) {
35
52
const modalImage = gradioApp ( ) . getElementById ( "modalImage" ) ;
36
53
if ( modalImage && modalImage . offsetParent ) {
37
- let currentButton = selected_gallery_button ( ) ;
38
- let preview = gradioApp ( ) . querySelectorAll ( '.livePreview > img' ) ;
39
- if ( opts . js_live_preview_in_modal_lightbox && preview . length > 0 ) {
40
- // show preview image if available
41
- modalImage . src = preview [ preview . length - 1 ] . src ;
42
- } else if ( currentButton ?. children ?. length > 0 && modalImage . src != currentButton . children [ 0 ] . src ) {
43
- modalImage . src = currentButton . children [ 0 ] . src ;
44
- if ( modalImage . style . display === 'none' ) {
45
- const modal = gradioApp ( ) . getElementById ( "lightboxModal" ) ;
46
- modal . style . setProperty ( 'background-image' , `url(${ modalImage . src } )` ) ;
47
- }
48
- }
54
+ updateModalImage ( ) ;
49
55
}
50
56
}
51
57
0 commit comments