Merge pull request #8940 from space-nuko/fix-send-to-img2img
Fix Send to img2img buttons
This commit is contained in:
commit
a89af2325d
@ -32,13 +32,7 @@ function negmod(n, m) {
|
|||||||
function updateOnBackgroundChange() {
|
function updateOnBackgroundChange() {
|
||||||
const modalImage = gradioApp().getElementById("modalImage")
|
const modalImage = gradioApp().getElementById("modalImage")
|
||||||
if (modalImage && modalImage.offsetParent) {
|
if (modalImage && modalImage.offsetParent) {
|
||||||
let allcurrentButtons = gradioApp().querySelectorAll(".gallery-item.transition-all.\\!ring-2")
|
let currentButton = selected_gallery_button();
|
||||||
let currentButton = null
|
|
||||||
allcurrentButtons.forEach(function(elem) {
|
|
||||||
if (elem.parentElement.offsetParent) {
|
|
||||||
currentButton = elem;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (currentButton?.children?.length > 0 && modalImage.src != currentButton.children[0].src) {
|
if (currentButton?.children?.length > 0 && modalImage.src != currentButton.children[0].src) {
|
||||||
modalImage.src = currentButton.children[0].src;
|
modalImage.src = currentButton.children[0].src;
|
||||||
@ -50,22 +44,10 @@ function updateOnBackgroundChange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function modalImageSwitch(offset) {
|
function modalImageSwitch(offset) {
|
||||||
var allgalleryButtons = gradioApp().querySelectorAll(".gradio-gallery .thumbnail-item")
|
var galleryButtons = all_gallery_buttons();
|
||||||
var galleryButtons = []
|
|
||||||
allgalleryButtons.forEach(function(elem) {
|
|
||||||
if (elem.parentElement.offsetParent) {
|
|
||||||
galleryButtons.push(elem);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (galleryButtons.length > 1) {
|
if (galleryButtons.length > 1) {
|
||||||
var allcurrentButtons = gradioApp().querySelectorAll(".gradio-gallery .thumbnail-item.selected")
|
var currentButton = selected_gallery_button();
|
||||||
var currentButton = null
|
|
||||||
allcurrentButtons.forEach(function(elem) {
|
|
||||||
if (elem.parentElement.offsetParent) {
|
|
||||||
currentButton = elem;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var result = -1
|
var result = -1
|
||||||
galleryButtons.forEach(function(v, i) {
|
galleryButtons.forEach(function(v, i) {
|
||||||
|
@ -7,9 +7,31 @@ function set_theme(theme){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function all_gallery_buttons() {
|
||||||
|
var allGalleryButtons = gradioApp().querySelectorAll('[style="display: block;"].tabitem div[id$=_gallery].gradio-gallery .thumbnails > .thumbnail-item.thumbnail-small');
|
||||||
|
var visibleGalleryButtons = [];
|
||||||
|
allGalleryButtons.forEach(function(elem) {
|
||||||
|
if (elem.parentElement.offsetParent) {
|
||||||
|
visibleGalleryButtons.push(elem);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return visibleGalleryButtons;
|
||||||
|
}
|
||||||
|
|
||||||
|
function selected_gallery_button() {
|
||||||
|
var allCurrentButtons = gradioApp().querySelectorAll('[style="display: block;"].tabitem div[id$=_gallery].gradio-gallery .thumbnail-item.thumbnail-small.selected');
|
||||||
|
var visibleCurrentButton = null;
|
||||||
|
allCurrentButtons.forEach(function(elem) {
|
||||||
|
if (elem.parentElement.offsetParent) {
|
||||||
|
visibleCurrentButton = elem;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return visibleCurrentButton;
|
||||||
|
}
|
||||||
|
|
||||||
function selected_gallery_index(){
|
function selected_gallery_index(){
|
||||||
var buttons = gradioApp().querySelectorAll('[style="display: block;"].tabitem div[id$=_gallery] .gallery-item')
|
var buttons = all_gallery_buttons();
|
||||||
var button = gradioApp().querySelector('[style="display: block;"].tabitem div[id$=_gallery] .gallery-item.\\!ring-2')
|
var button = selected_gallery_button();
|
||||||
|
|
||||||
var result = -1
|
var result = -1
|
||||||
buttons.forEach(function(v, i){ if(v==button) { result = i } })
|
buttons.forEach(function(v, i){ if(v==button) { result = i } })
|
||||||
@ -18,14 +40,18 @@ function selected_gallery_index(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extract_image_from_gallery(gallery){
|
function extract_image_from_gallery(gallery){
|
||||||
if(gallery.length == 1){
|
if (gallery.length == 0){
|
||||||
return [gallery[0]]
|
return [null];
|
||||||
|
}
|
||||||
|
if (gallery.length == 1){
|
||||||
|
return [gallery[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
index = selected_gallery_index()
|
index = selected_gallery_index()
|
||||||
|
|
||||||
if (index < 0 || index >= gallery.length){
|
if (index < 0 || index >= gallery.length){
|
||||||
return [null]
|
// Use the first image in the gallery as the default
|
||||||
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [gallery[index]];
|
return [gallery[index]];
|
||||||
|
Loading…
Reference in New Issue
Block a user