Commit 7b1db45e authored by yfszzx's avatar yfszzx

images history improvement

parent 1e18a5ff
function init_images_history(){ images_history_tab_list = ["txt2img", "img2img", "extras"]
if (gradioApp().getElementById('txt2img_images_history_first_page') == null) { function images_history_init(){
setTimeout(init_images_history, 1000) if (gradioApp().getElementById('txt2img_images_history_first_page') == null) {
} else { setTimeout(images_history_init, 500)
tab_list = ["txt2img", "img2img"] } else {
for (i in tab_list){ for (i in images_history_tab_list ){
tab = tab_list[i] tab = images_history_tab_list[i]
gradioApp().getElementById(tab + "_images_history_first_page").click() gradioApp().getElementById(tab + '_images_history').classList.add("images_history_gallery")
$(gradioApp().getElementById(tab + '_images_history')).addClass("images_history_gallery") gradioApp().getElementById(tab + '_images_history_set_index').classList.add("images_history_set_index")
item = $(gradioApp().getElementById(tab + '_images_history_set_index'))
item.addClass("images_history_set_index") }
item.hide() gradioApp().getElementById("txt2img_images_history_first_page").click()
} }
} }
setTimeout(images_history_init, 500)
var images_history_button_actions = function(){
if (!this.classList.contains("transform")){
gallery = this.parentElement
while(!gallery.classList.contains("images_history_gallery")){gallery = gallery.parentElement}
buttons = gallery.querySelectorAll(".gallery-item")
i = 0
hidden_list = []
buttons.forEach(function(e){
if (e.style.display == "none"){
hidden_list.push(i)
}
i += 1
})
if (hidden_list.length > 0){
setTimeout(images_history_hide_buttons, 10, hidden_list, gallery)
}
}
images_history_set_image_info(this)
} }
setTimeout(init_images_history, 1000)
onUiUpdate(function(){ onUiUpdate(function(){
fullImg_preview = gradioApp().querySelectorAll('#txt2img_images_history img.w-full') for (i in images_history_tab_list ){
if(fullImg_preview.length > 0){ tab = images_history_tab_list[i]
fullImg_preview.forEach(set_history_index_from_img); buttons = gradioApp().querySelectorAll('#' + tab + '_images_history .gallery-item')
} buttons.forEach(function(bnt){
fullImg_preview = gradioApp().querySelectorAll('#img2img_images_history img.w-full') bnt.addEventListener('click', images_history_button_actions, true)
if(fullImg_preview.length > 0){ });
fullImg_preview.forEach(set_history_index_from_img);
} }
}) })
function images_history_hide_buttons(hidden_list, gallery){
buttons = gallery.querySelectorAll(".gallery-item")
num = 0
buttons.forEach(function(e){
if (e.style.display == "none"){
num += 1
}
})
if (num == hidden_list.length){
setTimeout(images_history_hide_buttons, 10, hidden_list, gallery)
}
for( i in hidden_list){
buttons[hidden_list[i]].style.display = "none"
}
}
function set_history_gallery_index(item){ function images_history_set_image_info(button){
buttons = item.find(".gallery-item") item = button.parentElement
// alert(item.attr("id") + " " + buttons.length) while(item.tagName != "DIV"){item = item.parentElement}
index = -1 buttons = item.querySelectorAll(".gallery-item")
i = 0 index = -1
buttons.each(function(){ i = 0
if($(this).hasClass("!ring-2")){ index = i } buttons.forEach(function(e){
i += 1 if(e==button){index = i}
}) if(e.style.display != "none"){
if (index == -1){ i += 1
setTimeout(set_history_gallery_index, 10, item) }
} else { })
item = item.find(".images_history_set_index").first() gallery = button.parentElement
item.attr("img_index", index) while(!gallery.classList.contains("images_history_gallery")){gallery = gallery.parentElement}
item.click() set_btn = gallery.querySelector(".images_history_set_index")
} set_btn.setAttribute("img_index", index)
set_btn.click()
} }
function set_history_index_from_img(e){
if(e && e.parentElement.tagName == 'BUTTON'){
bnt = $(e).parent()
if (bnt.hasClass("transform")){
bnt.off("click").on("click",function(){
set_history_gallery_index($(this).parents(".images_history_gallery").first())
})
} else {
bnt.off("mousedown").on("mousedown", function(){
set_history_gallery_index($(this).parents(".images_history_gallery").first())
})
} function images_history_get_current_img(tabname, image_path, files){
} s = gradioApp().getElementById(tabname + '_images_history_set_index').getAttribute("img_index")
return [s, image_path, files]
} }
function images_history_get_current_img(is_image2image, image_path, files){
head = is_image2image?"img2img":"txt2img" function images_history_delete(tabname, img_path, img_file_name, page_index, filenames, image_index){
s = $(gradioApp().getElementById(head + '_images_history_set_index')).attr("img_index") image_index = parseInt(image_index)
return [s, image_path, files] tab = gradioApp().getElementById(tabname + '_images_history')
set_btn = tab.querySelector(".images_history_set_index")
buttons = []
tab.querySelectorAll(".gallery-item").forEach(function(e){
if (e.style.display != 'none'){
buttons.push(e)
}
})
img_num = buttons.length / 2
if (img_num == 1){
setTimeout(function(tabname){
gradioApp().getElementById(tabname + '_images_history_renew_page').click()
}, 30, tabname)
} else {
buttons[image_index].style.display = 'none'
buttons[image_index + img_num].style.display = 'none'
if (image_index >= img_num - 1){
console.log(buttons.length, img_num)
btn = buttons[img_num - 2]
} else {
btn = buttons[image_index + 1]
}
setTimeout(function(btn){btn.click()}, 30, btn)
}
return [tabname, img_path, img_file_name, page_index, filenames, image_index]
} }
function images_history_turnpage(img_path, page_index, image_index, tabname){
buttons = gradioApp().getElementById(tabname + '_images_history').querySelectorAll(".gallery-item")
buttons.forEach(function(elem) {
elem.style.display = 'block'
})
return [img_path, page_index, image_index, tabname]
}
This diff is collapsed.
This diff is collapsed.
...@@ -463,3 +463,6 @@ input[type="range"]{ ...@@ -463,3 +463,6 @@ input[type="range"]{
max-width: 32em; max-width: 32em;
padding: 0; padding: 0;
} }
.images-history-hidden{
display: none;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment