Usage
nebula.bufferedWindowLoad(callback)
Parameters
callback
(Required) (Function) The function to run at window load
Default: None
Examples
nebula.bufferedWindowLoad(function(){
//Do something at window load
});
Useful for inside dynamic imports that happen on DOM Ready and need a window load listener inside of them; the window load may happen before the import finished loading.
jQuery(function(){
import('./modules/whatever.js').then(function(module){
nebula.bufferedWindowLoad(function(){ //This may actually happen inside of the module file itself, but for demonstration purposes doing it all here
//Do something at window load
});
});
});
Source File
Located in /assets/js/modules/utilities.js on line 5.
No Hooks
This function does not have any filters or actions available. Request one?nebula.bufferedWindowLoad = function(callback){
//If the window load event has already happened, run the callback immediately
if ( document.readyState === 'complete' ){ //Note: "interactive" = DOM Ready, "complete" = Window Load
return callback();
}
//If the window has not yet loaded, add an event listener to wait for it
window.addEventListener('load', () => callback());
};
Override
To override or disable this JavaScript function, simply redeclare it with the exact same function name. Remember: Some functionality is conditionally loaded via dynamic imports, so if your function is not overriding properly, try listening for a DOM event (described below).
For non-module import functions:
nebula.bufferedWindowLoad = function(callback){
//Write your own code here, leave it blank, or return false.
}
For dynamically imported module function overrides:
jQuery(window).on('load', function(){
nebula.bufferedWindowLoad = function(callback){
//Write your own code here, leave it blank, or return false.
}
});
Custom Nebula DOM events do also exist, so you could also try the following if the Window Load listener does not work:
jQuery(document).on('nebula_module_loaded', function(module){
//Note that the module variable is also available to know which module specifically was imported
if ( typeof nebula.bufferedWindowLoad === 'function' ){
nebula.bufferedWindowLoad = function(callback){
//Write your own code here, leave it blank, or return false.
}
}
});