mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
javascript: Register callback to be called when the UI is loaded and opts is ready.
/** * Register callback to be called when the UI is loaded and opts is ready. * The callback receives no arguments. */ function onUiLoadedReady(callback) { uiLoadedReadyCallbacks.push(callback); }
This commit is contained in:
parent
801b72b92b
commit
b8923bb65d
16
script.js
16
script.js
@ -27,6 +27,7 @@ function get_uiCurrentTabContent() {
|
|||||||
var uiUpdateCallbacks = [];
|
var uiUpdateCallbacks = [];
|
||||||
var uiAfterUpdateCallbacks = [];
|
var uiAfterUpdateCallbacks = [];
|
||||||
var uiLoadedCallbacks = [];
|
var uiLoadedCallbacks = [];
|
||||||
|
var uiLoadedReadyCallbacks = [];
|
||||||
var uiTabChangeCallbacks = [];
|
var uiTabChangeCallbacks = [];
|
||||||
var optionsChangedCallbacks = [];
|
var optionsChangedCallbacks = [];
|
||||||
var uiAfterUpdateTimeout = null;
|
var uiAfterUpdateTimeout = null;
|
||||||
@ -60,6 +61,14 @@ function onUiLoaded(callback) {
|
|||||||
uiLoadedCallbacks.push(callback);
|
uiLoadedCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register callback to be called when the UI is loaded and opts is ready.
|
||||||
|
* The callback receives no arguments.
|
||||||
|
*/
|
||||||
|
function onUiLoadedReady(callback) {
|
||||||
|
uiLoadedReadyCallbacks.push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register callback to be called when the UI tab is changed.
|
* Register callback to be called when the UI tab is changed.
|
||||||
* The callback receives no arguments.
|
* The callback receives no arguments.
|
||||||
@ -104,7 +113,8 @@ var executedOnLoaded = false;
|
|||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
var mutationObserver = new MutationObserver(function(m) {
|
var mutationObserver = new MutationObserver(function(m) {
|
||||||
if (!executedOnLoaded && gradioApp().querySelector('#txt2img_prompt')) {
|
const firstOnLoaded = !executedOnLoaded && gradioApp().querySelector('#txt2img_prompt')
|
||||||
|
if (firstOnLoaded) {
|
||||||
executedOnLoaded = true;
|
executedOnLoaded = true;
|
||||||
executeCallbacks(uiLoadedCallbacks);
|
executeCallbacks(uiLoadedCallbacks);
|
||||||
}
|
}
|
||||||
@ -116,6 +126,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
uiCurrentTab = newTab;
|
uiCurrentTab = newTab;
|
||||||
executeCallbacks(uiTabChangeCallbacks);
|
executeCallbacks(uiTabChangeCallbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstOnLoaded) {
|
||||||
|
executeCallbacks(uiLoadedReadyCallbacks);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mutationObserver.observe(gradioApp(), {childList: true, subtree: true});
|
mutationObserver.observe(gradioApp(), {childList: true, subtree: true});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user