added onOptionsAvailable callback for javascript for

This commit is contained in:
AUTOMATIC1111 2024-06-09 21:33:32 +03:00
parent 99e65ec618
commit d2097dbdd9
2 changed files with 16 additions and 0 deletions

View File

@ -299,6 +299,7 @@ onAfterUiUpdate(function() {
var jsdata = textarea.value;
opts = JSON.parse(jsdata);
executeCallbacks(optionsAvailableCallbacks); /*global optionsAvailableCallbacks*/
executeCallbacks(optionsChangedCallbacks); /*global optionsChangedCallbacks*/
Object.defineProperty(textarea, 'value', {

View File

@ -29,6 +29,7 @@ var uiAfterUpdateCallbacks = [];
var uiLoadedCallbacks = [];
var uiTabChangeCallbacks = [];
var optionsChangedCallbacks = [];
var optionsAvailableCallbacks = [];
var uiAfterUpdateTimeout = null;
var uiCurrentTab = null;
@ -77,6 +78,20 @@ function onOptionsChanged(callback) {
optionsChangedCallbacks.push(callback);
}
/**
* Register callback to be called when the options (in opts global variable) are available.
* The callback receives no arguments.
* If you register the callback after the options are available, it's just immediately called.
*/
function onOptionsAvailable(callback) {
if (Object.keys(opts).length != 0) {
callback();
return;
}
optionsAvailableCallbacks.push(callback);
}
function executeCallbacks(queue, arg) {
for (const callback of queue) {
try {