aboutsummaryrefslogtreecommitdiffstats
path: root/javascript/images_history.js
blob: 93d2b89ab4143363cc40147709974b5f110d2b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function init_images_history(){ 
	if (gradioApp().getElementById('txt2img_images_history_first_page') == null) {
		setTimeout(init_images_history, 1000)
	} else {
		tab_list = ["txt2img", "img2img"]
		for (i in tab_list){
			tab = tab_list[i]
			gradioApp().getElementById(tab + "_images_history_first_page").click()
			$(gradioApp().getElementById(tab + '_images_history')).addClass("images_history_gallery")
			item = $(gradioApp().getElementById(tab + '_images_history_set_index'))
			item.addClass("images_history_set_index")
			item.hide()
		}		
	}
	
}
setTimeout(init_images_history, 1000)
onUiUpdate(function(){
    fullImg_preview = gradioApp().querySelectorAll('#txt2img_images_history img.w-full')
        if(fullImg_preview.length > 0){
	    	fullImg_preview.forEach(set_history_index_from_img);
    }
    fullImg_preview = gradioApp().querySelectorAll('#img2img_images_history img.w-full')
        if(fullImg_preview.length > 0){
	    	fullImg_preview.forEach(set_history_index_from_img);
    }
})

function set_history_gallery_index(item){
	buttons = item.find(".gallery-item")
	// alert(item.attr("id") + " " + buttons.length)
	index = -1
	i = 0
	buttons.each(function(){
		if($(this).hasClass("!ring-2")){ index = i }
		i += 1
	})
	if (index == -1){
		setTimeout(set_history_gallery_index, 10, item)     
	} else {
		item = item.find(".images_history_set_index").first()
    	item.attr("img_index", index)
    	item.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(is_image2image, image_path, files){
	head = is_image2image?"img2img":"txt2img"
	s =  $(gradioApp().getElementById(head + '_images_history_set_index')).attr("img_index")
	return [s, image_path, files]
}