2022-11-10 11:07:41 -07:00
|
|
|
// attaches listeners to the txt2img and img2img galleries to update displayed generation param text when the image changes
|
|
|
|
|
|
|
|
let txt2img_gallery, img2img_gallery, modal = undefined;
|
2023-05-25 00:09:13 -06:00
|
|
|
onAfterUiUpdate(function() {
|
2022-11-10 11:07:41 -07:00
|
|
|
if (!txt2img_gallery) {
|
|
|
|
txt2img_gallery = attachGalleryListeners("txt2img");
|
|
|
|
}
|
|
|
|
if (!img2img_gallery) {
|
|
|
|
img2img_gallery = attachGalleryListeners("img2img");
|
|
|
|
}
|
|
|
|
if (!modal) {
|
|
|
|
modal = gradioApp().getElementById('lightboxModal');
|
2023-05-18 00:59:10 -06:00
|
|
|
modalObserver.observe(modal, {attributes: true, attributeFilter: ['style']});
|
2022-11-10 11:07:41 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let modalObserver = new MutationObserver(function(mutations) {
|
|
|
|
mutations.forEach(function(mutationRecord) {
|
2023-04-03 11:28:20 -06:00
|
|
|
let selectedTab = gradioApp().querySelector('#tabs div button.selected')?.innerText;
|
|
|
|
if (mutationRecord.target.style.display === 'none' && (selectedTab === 'txt2img' || selectedTab === 'img2img')) {
|
|
|
|
gradioApp().getElementById(selectedTab + "_generation_info_button")?.click();
|
2023-05-17 06:46:58 -06:00
|
|
|
}
|
2022-11-10 11:07:41 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function attachGalleryListeners(tab_name) {
|
2023-04-30 13:08:52 -06:00
|
|
|
var gallery = gradioApp().querySelector('#' + tab_name + '_gallery');
|
2022-11-10 11:07:41 -07:00
|
|
|
gallery?.addEventListener('click', () => gradioApp().getElementById(tab_name + "_generation_info_button").click());
|
|
|
|
gallery?.addEventListener('keydown', (e) => {
|
|
|
|
if (e.keyCode == 37 || e.keyCode == 39) { // left or right arrow
|
|
|
|
gradioApp().getElementById(tab_name + "_generation_info_button").click();
|
2023-05-17 06:46:58 -06:00
|
|
|
}
|
2022-11-10 11:07:41 -07:00
|
|
|
});
|
|
|
|
return gallery;
|
|
|
|
}
|