Skip to content

Commit

Permalink
fix modalImageViewer preview/result flicker
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w committed Aug 26, 2024
1 parent 4823909 commit a2b5f17
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions javascript/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
}
}

Expand Down

0 comments on commit a2b5f17

Please sign in to comment.