Path: blob/master/javascript/generationParams.js
3055 views
// attaches listeners to the txt2img and img2img galleries to update displayed generation param text when the image changes12let txt2img_gallery, img2img_gallery, modal = undefined;3onAfterUiUpdate(function() {4if (!txt2img_gallery) {5txt2img_gallery = attachGalleryListeners("txt2img");6}7if (!img2img_gallery) {8img2img_gallery = attachGalleryListeners("img2img");9}10if (!modal) {11modal = gradioApp().getElementById('lightboxModal');12modalObserver.observe(modal, {attributes: true, attributeFilter: ['style']});13}14});1516let modalObserver = new MutationObserver(function(mutations) {17mutations.forEach(function(mutationRecord) {18let selectedTab = gradioApp().querySelector('#tabs div button.selected')?.innerText;19if (mutationRecord.target.style.display === 'none' && (selectedTab === 'txt2img' || selectedTab === 'img2img')) {20gradioApp().getElementById(selectedTab + "_generation_info_button")?.click();21}22});23});2425function attachGalleryListeners(tab_name) {26var gallery = gradioApp().querySelector('#' + tab_name + '_gallery');27gallery?.addEventListener('click', () => gradioApp().getElementById(tab_name + "_generation_info_button").click());28gallery?.addEventListener('keydown', (e) => {29if (e.keyCode == 37 || e.keyCode == 39) { // left or right arrow30gradioApp().getElementById(tab_name + "_generation_info_button").click();31}32});33return gallery;34}353637