Implemented a ready function that is only invoked once all ignite elements on a page are ready.
This commit is contained in:
@ -205,6 +205,29 @@ class IgniteRenderingContext {
|
||||
}
|
||||
}
|
||||
|
||||
static ready(callback) {
|
||||
//Setup the callbacks if it's not init'd.
|
||||
if (!IgniteRenderingContext.ReadyCallbacks) {
|
||||
IgniteRenderingContext.ReadyCallbacks = [];
|
||||
}
|
||||
|
||||
//Add this ignite callback.
|
||||
IgniteRenderingContext.ReadyCallbacks.push(callback);
|
||||
|
||||
//Clear the existing timer if there is one.
|
||||
if (IgniteRenderingContext.ReadyTimer) {
|
||||
clearTimeout(IgniteRenderingContext.ReadyTimer);
|
||||
}
|
||||
|
||||
//Set a new timeout, it will only run once all elements are ready because
|
||||
//of the way single threaded timers work.
|
||||
IgniteRenderingContext.ReadyTimer = setTimeout(() => {
|
||||
IgniteRenderingContext.ReadyCallbacks.forEach((ready) => ready.invoke());
|
||||
IgniteRenderingContext.ReadyCallbacks = [];
|
||||
IgniteRenderingContext.ReadyTimer = null;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
static get rendering() {
|
||||
if (IgniteRenderingContext.RenderCount && IgniteRenderingContext.RenderCount > 0) {
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user