added onOptionsAvailable callback for javascript for
This commit is contained in:
parent
99e65ec618
commit
d2097dbdd9
|
@ -299,6 +299,7 @@ onAfterUiUpdate(function() {
|
||||||
var jsdata = textarea.value;
|
var jsdata = textarea.value;
|
||||||
opts = JSON.parse(jsdata);
|
opts = JSON.parse(jsdata);
|
||||||
|
|
||||||
|
executeCallbacks(optionsAvailableCallbacks); /*global optionsAvailableCallbacks*/
|
||||||
executeCallbacks(optionsChangedCallbacks); /*global optionsChangedCallbacks*/
|
executeCallbacks(optionsChangedCallbacks); /*global optionsChangedCallbacks*/
|
||||||
|
|
||||||
Object.defineProperty(textarea, 'value', {
|
Object.defineProperty(textarea, 'value', {
|
||||||
|
|
15
script.js
15
script.js
|
@ -29,6 +29,7 @@ var uiAfterUpdateCallbacks = [];
|
||||||
var uiLoadedCallbacks = [];
|
var uiLoadedCallbacks = [];
|
||||||
var uiTabChangeCallbacks = [];
|
var uiTabChangeCallbacks = [];
|
||||||
var optionsChangedCallbacks = [];
|
var optionsChangedCallbacks = [];
|
||||||
|
var optionsAvailableCallbacks = [];
|
||||||
var uiAfterUpdateTimeout = null;
|
var uiAfterUpdateTimeout = null;
|
||||||
var uiCurrentTab = null;
|
var uiCurrentTab = null;
|
||||||
|
|
||||||
|
@ -77,6 +78,20 @@ function onOptionsChanged(callback) {
|
||||||
optionsChangedCallbacks.push(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) {
|
function executeCallbacks(queue, arg) {
|
||||||
for (const callback of queue) {
|
for (const callback of queue) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue