@@ -13,6 +13,7 @@ function showModal(event) {
1313 if ( modalImage . style . display === 'none' ) {
1414 lb . style . setProperty ( 'background-image' , 'url(' + source . src + ')' ) ;
1515 }
16+ updateModalImage ( ) ;
1617 lb . style . display = "flex" ;
1718 lb . focus ( ) ;
1819
@@ -31,21 +32,26 @@ function negmod(n, m) {
3132 return ( ( n % m ) + m ) % m ;
3233}
3334
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+
3451function updateOnBackgroundChange ( ) {
3552 const modalImage = gradioApp ( ) . getElementById ( "modalImage" ) ;
3653 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 ( ) ;
4955 }
5056}
5157
0 commit comments