reorganize js callbacks and startup sequence

This commit is contained in:
Vladimir Mandic
2024-04-04 18:26:51 -04:00
parent 77db12765d
commit 9d04255b54
22 changed files with 98 additions and 80 deletions
+3 -7
View File
@@ -3,8 +3,6 @@
// Counts open and closed brackets (round, square, curly) in the prompt and negative prompt text boxes in the txt2img and img2img tabs.
// If there's a mismatch, the keyword counter turns red and if you hover on it, a tooltip tells you what's wrong.
let promptCheckerInitialized = false;
function checkBrackets(textArea, counterElt) {
const counts = {};
const errors = [];
@@ -25,17 +23,15 @@ function setupBracketChecking(idPrompt, idCounter) {
const textarea = gradioApp().querySelector(`#${idPrompt} > label > textarea`);
const counter = gradioApp().getElementById(idCounter);
if (!textarea || !counter) return;
if (!promptCheckerInitialized) log('initPromptChecker');
promptCheckerInitialized = true;
textarea.addEventListener('input', () => checkBrackets(textarea, counter));
}
onAfterUiUpdate(() => {
if (promptCheckerInitialized) return;
async function initPromptChecker() {
log('initPromptChecker');
setupBracketChecking('txt2img_prompt', 'txt2img_token_counter');
setupBracketChecking('txt2img_neg_prompt', 'txt2img_negative_token_counter');
setupBracketChecking('img2img_prompt', 'img2img_token_counter');
setupBracketChecking('img2img_neg_prompt', 'img2img_negative_token_counter');
setupBracketChecking('control_prompt', 'control_token_counter');
setupBracketChecking('control_neg_prompt', 'control_negative_token_counter');
});
}