From a2b5f179512a7eb1c91835f50dc725a262252ce6 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Mon, 26 Aug 2024 10:46:43 +0900 Subject: [PATCH] fix modalImageViewer preview/result flicker --- javascript/imageviewer.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/javascript/imageviewer.js b/javascript/imageviewer.js index 9b23f4700b3..979d05de5ba 100644 --- a/javascript/imageviewer.js +++ b/javascript/imageviewer.js @@ -13,6 +13,7 @@ function showModal(event) { if (modalImage.style.display === 'none') { lb.style.setProperty('background-image', 'url(' + source.src + ')'); } + updateModalImage(); lb.style.display = "flex"; lb.focus(); @@ -31,21 +32,26 @@ function negmod(n, m) { return ((n % m) + m) % m; } +function updateModalImage() { + const modalImage = gradioApp().getElementById("modalImage"); + let currentButton = selected_gallery_button(); + let preview = gradioApp().querySelectorAll('.livePreview > img'); + if (opts.js_live_preview_in_modal_lightbox && preview.length > 0) { + // show preview image if available + modalImage.src = preview[preview.length - 1].src; + } else if (currentButton?.children?.length > 0 && modalImage.src != currentButton.children[0].src) { + modalImage.src = currentButton.children[0].src; + if (modalImage.style.display === 'none') { + const modal = gradioApp().getElementById("lightboxModal"); + modal.style.setProperty('background-image', `url(${modalImage.src})`); + } + } +} + function updateOnBackgroundChange() { const modalImage = gradioApp().getElementById("modalImage"); if (modalImage && modalImage.offsetParent) { - let currentButton = selected_gallery_button(); - let preview = gradioApp().querySelectorAll('.livePreview > img'); - if (opts.js_live_preview_in_modal_lightbox && preview.length > 0) { - // show preview image if available - modalImage.src = preview[preview.length - 1].src; - } else if (currentButton?.children?.length > 0 && modalImage.src != currentButton.children[0].src) { - modalImage.src = currentButton.children[0].src; - if (modalImage.style.display === 'none') { - const modal = gradioApp().getElementById("lightboxModal"); - modal.style.setProperty('background-image', `url(${modalImage.src})`); - } - } + updateModalImage(); } }