diff options
author | Aarni Koskela <akx@iki.fi> | 2023-05-25 06:05:06 +0000 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2023-05-25 06:09:01 +0000 |
commit | bc53ecf298478ecd9d01a78ece50fea06a609d6a (patch) | |
tree | 1ecc98756a997f688fceb0625bab44f2c8d48f58 /script.js | |
parent | 54696dce056ece694bbca3f6c0252532fdd05bbd (diff) | |
download | stable-diffusion-webui-gfx803-bc53ecf298478ecd9d01a78ece50fea06a609d6a.tar.gz stable-diffusion-webui-gfx803-bc53ecf298478ecd9d01a78ece50fea06a609d6a.tar.bz2 stable-diffusion-webui-gfx803-bc53ecf298478ecd9d01a78ece50fea06a609d6a.zip |
Add onAfterUiUpdate callback
Diffstat (limited to 'script.js')
-rw-r--r-- | script.js | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -19,9 +19,11 @@ function get_uiCurrentTabContent() { } var uiUpdateCallbacks = []; +var uiAfterUpdateCallbacks = []; var uiLoadedCallbacks = []; var uiTabChangeCallbacks = []; var optionsChangedCallbacks = []; +var uiAfterUpdateTimeout = null; var uiCurrentTab = null; /** @@ -33,6 +35,18 @@ function onUiUpdate(callback) { } /** + * Register callback to be called soon after UI updates. + * The callback receives no arguments. + * + * This is preferred over `onUiUpdate` if you don't need + * access to the MutationRecords, as your function will + * not be called quite as often. + */ +function onAfterUiUpdate(callback) { + uiAfterUpdateCallbacks.push(callback); +} + +/** * Register callback to be called when the UI is loaded. * The callback receives no arguments. */ @@ -66,6 +80,18 @@ function executeCallbacks(queue, arg) { } } } + +/** + * Schedule the execution of the callbacks registered with onAfterUiUpdate. + * The callbacks are executed after a short while, unless another call to this function + * is made before that time. IOW, the callbacks are executed only once, even + * when there are multiple mutations observed. + */ +function scheduleAfterUiUpdateCallbacks() { + clearTimeout(uiAfterUpdateTimeout); + uiAfterUpdateTimeout = setTimeout(function() { + executeCallbacks(uiAfterUpdateCallbacks); + }, 200); } var executedOnLoaded = false; @@ -78,6 +104,7 @@ document.addEventListener("DOMContentLoaded", function() { } executeCallbacks(uiUpdateCallbacks, m); + scheduleAfterUiUpdateCallbacks(); const newTab = get_uiCurrentTab(); if (newTab && (newTab !== uiCurrentTab)) { uiCurrentTab = newTab; |