aboutsummaryrefslogtreecommitdiff
path: root/javascript/inspiration.js
blob: e1c0e11406d37347da32cc075ee1326de9bffeb9 (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
function public_image_index_in_gallery(item, gallery){
    var index;
    var i = 0;
    gallery.querySelectorAll("img").forEach(function(e){
        if (e == item)
            index = i;
        i += 1;
    });
    return index;
}

function inspiration_selected(name, types, name_list){
    var btn = gradioApp().getElementById("inspiration_select_button")
    return [gradioApp().getElementById("inspiration_select_button").getAttribute("img-index"), types];
}    
var inspiration_image_click = function(){
    var index =  public_image_index_in_gallery(this, gradioApp().getElementById("inspiration_gallery"));
    var btn = gradioApp().getElementById("inspiration_select_button")
    btn.setAttribute("img-index", index)
    setTimeout(function(btn){btn.click();}, 10, btn)
}

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) {
                node.style.display = "None"; //parentNode.removeChild(node) 
            }
            
            gallery.querySelectorAll('img').forEach(function(e){    
                e.onclick = inspiration_image_click
        }) 

        }


    });
    mutationObserver.observe( gradioApp(), { childList:true, subtree:true });

});