Skip to content

Commit

Permalink
javascript: Register callback to be called when the UI is loaded and …
Browse files Browse the repository at this point in the history
…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);
}
  • Loading branch information
bluelovers authored Jun 3, 2024
1 parent 801b72b commit b8923bb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function get_uiCurrentTabContent() {
var uiUpdateCallbacks = [];
var uiAfterUpdateCallbacks = [];
var uiLoadedCallbacks = [];
var uiLoadedReadyCallbacks = [];
var uiTabChangeCallbacks = [];
var optionsChangedCallbacks = [];
var uiAfterUpdateTimeout = null;
Expand Down Expand Up @@ -60,6 +61,14 @@ function onUiLoaded(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.
* The callback receives no arguments.
Expand Down Expand Up @@ -104,7 +113,8 @@ var executedOnLoaded = false;

document.addEventListener("DOMContentLoaded", function() {
var mutationObserver = new MutationObserver(function(m) {
if (!executedOnLoaded && gradioApp().querySelector('#txt2img_prompt')) {
const firstOnLoaded = !executedOnLoaded && gradioApp().querySelector('#txt2img_prompt')

Check failure on line 116 in script.js

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon
if (firstOnLoaded) {
executedOnLoaded = true;
executeCallbacks(uiLoadedCallbacks);
}
Expand All @@ -116,6 +126,10 @@ document.addEventListener("DOMContentLoaded", function() {
uiCurrentTab = newTab;
executeCallbacks(uiTabChangeCallbacks);
}

if (firstOnLoaded) {
executeCallbacks(uiLoadedReadyCallbacks);
}
});
mutationObserver.observe(gradioApp(), {childList: true, subtree: true});
});
Expand Down

0 comments on commit b8923bb

Please sign in to comment.