2022-10-20 15:58:52 +00:00
|
|
|
function public_image_index_in_gallery(item, gallery){
|
2022-10-22 02:16:22 +00:00
|
|
|
var imgs = gallery.querySelectorAll("img.h-full")
|
2022-10-20 15:58:52 +00:00
|
|
|
var index;
|
|
|
|
var i = 0;
|
2022-10-21 17:23:00 +00:00
|
|
|
imgs.forEach(function(e){
|
2022-10-20 15:58:52 +00:00
|
|
|
if (e == item)
|
|
|
|
index = i;
|
|
|
|
i += 1;
|
|
|
|
});
|
2022-10-22 02:16:22 +00:00
|
|
|
var all_imgs = gallery.querySelectorAll("img")
|
|
|
|
if (all_imgs.length > imgs.length){
|
|
|
|
var num = imgs.length / 2
|
|
|
|
index = (index < num) ? index : (index - num)
|
|
|
|
}
|
2022-10-20 15:58:52 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:23:00 +00:00
|
|
|
function inspiration_selected(name, name_list){
|
2022-10-20 15:58:52 +00:00
|
|
|
var btn = gradioApp().getElementById("inspiration_select_button")
|
2022-10-21 17:23:00 +00:00
|
|
|
return [gradioApp().getElementById("inspiration_select_button").getAttribute("img-index")];
|
2022-10-22 02:16:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-21 17:23:00 +00:00
|
|
|
function inspiration_click_get_button(){
|
|
|
|
gradioApp().getElementById("inspiration_get_button").click();
|
|
|
|
}
|
2022-10-22 02:16:22 +00:00
|
|
|
|
2022-10-20 15:58:52 +00:00
|
|
|
var inspiration_image_click = function(){
|
|
|
|
var index = public_image_index_in_gallery(this, gradioApp().getElementById("inspiration_gallery"));
|
2022-10-21 17:23:00 +00:00
|
|
|
var btn = gradioApp().getElementById("inspiration_select_button");
|
|
|
|
btn.setAttribute("img-index", index);
|
|
|
|
setTimeout(function(btn){btn.click();}, 10, btn);
|
2022-10-20 15:58:52 +00:00
|
|
|
}
|
2022-10-21 17:23:00 +00:00
|
|
|
|
2022-10-20 15:58:52 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
var mutationObserver = new MutationObserver(function(m){
|
|
|
|
var gallery = gradioApp().getElementById("inspiration_gallery")
|
|
|
|
if (gallery) {
|
|
|
|
var node = gallery.querySelector(".absolute.backdrop-blur.h-full")
|
|
|
|
if (node) {
|
2022-10-22 02:16:22 +00:00
|
|
|
node.style.display = "None";
|
2022-10-21 17:23:00 +00:00
|
|
|
}
|
2022-10-20 15:58:52 +00:00
|
|
|
gallery.querySelectorAll('img').forEach(function(e){
|
|
|
|
e.onclick = inspiration_image_click
|
2022-10-21 17:23:00 +00:00
|
|
|
});
|
2022-10-20 15:58:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
mutationObserver.observe( gradioApp(), { childList:true, subtree:true });
|
|
|
|
});
|