Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
automatic1111
GitHub Repository: automatic1111/stable-diffusion-webui
Path: blob/master/javascript/generationParams.js
3055 views
1
// attaches listeners to the txt2img and img2img galleries to update displayed generation param text when the image changes
2
3
let txt2img_gallery, img2img_gallery, modal = undefined;
4
onAfterUiUpdate(function() {
5
if (!txt2img_gallery) {
6
txt2img_gallery = attachGalleryListeners("txt2img");
7
}
8
if (!img2img_gallery) {
9
img2img_gallery = attachGalleryListeners("img2img");
10
}
11
if (!modal) {
12
modal = gradioApp().getElementById('lightboxModal');
13
modalObserver.observe(modal, {attributes: true, attributeFilter: ['style']});
14
}
15
});
16
17
let modalObserver = new MutationObserver(function(mutations) {
18
mutations.forEach(function(mutationRecord) {
19
let selectedTab = gradioApp().querySelector('#tabs div button.selected')?.innerText;
20
if (mutationRecord.target.style.display === 'none' && (selectedTab === 'txt2img' || selectedTab === 'img2img')) {
21
gradioApp().getElementById(selectedTab + "_generation_info_button")?.click();
22
}
23
});
24
});
25
26
function attachGalleryListeners(tab_name) {
27
var gallery = gradioApp().querySelector('#' + tab_name + '_gallery');
28
gallery?.addEventListener('click', () => gradioApp().getElementById(tab_name + "_generation_info_button").click());
29
gallery?.addEventListener('keydown', (e) => {
30
if (e.keyCode == 37 || e.keyCode == 39) { // left or right arrow
31
gradioApp().getElementById(tab_name + "_generation_info_button").click();
32
}
33
});
34
return gallery;
35
}
36
37