You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tt-rss/lib/dojo/ready.js.uncompressed.js

137 lines
3.6 KiB
JavaScript

define("dojo/ready", ["./_base/kernel", "./has", "require", "./domReady", "./_base/lang"], function(dojo, has, require, domReady, lang){
// module:
// dojo/ready
// note:
// This module should be unnecessary in dojo 2.0
var
// truthy if DOMContentLoaded or better (e.g., window.onload fired) has been achieved
isDomReady = 0,
// a function to call to cause onLoad to be called when all requested modules have been loaded
requestCompleteSignal,
// The queue of functions waiting to execute as soon as dojo.ready conditions satisfied
loadQ = [],
// prevent recursion in onLoad
onLoadRecursiveGuard = 0,
handleDomReady = function(){
isDomReady = 1;
dojo._postLoad = dojo.config.afterOnLoad = true;
if(loadQ.length){
requestCompleteSignal(onLoad);
}
},
// run the next function queued with dojo.ready
onLoad = function(){
if(isDomReady && !onLoadRecursiveGuard && loadQ.length){
//guard against recursions into this function
onLoadRecursiveGuard = 1;
var f = loadQ.shift();
try{
f();
}
// FIXME: signal the error via require.on
finally{
onLoadRecursiveGuard = 0;
}
onLoadRecursiveGuard = 0;
if(loadQ.length){
requestCompleteSignal(onLoad);
}
}
};
require.on("idle", onLoad);
requestCompleteSignal = function(){
if(require.idle()){
onLoad();
} // else do nothing, onLoad will be called with the next idle signal
};
var ready = dojo.ready = dojo.addOnLoad = function(priority, context, callback){
// summary:
// Add a function to execute on DOM content loaded and all requested modules have arrived and been evaluated.
// In most cases, the `domReady` plug-in should suffice and this method should not be needed.
// priority: Integer?
// The order in which to exec this callback relative to other callbacks, defaults to 1000
// context: Object?|Function
// The context in which to run execute callback, or a callback if not using context
// callback: Function?
// The function to execute.
//
// example:
// Simple DOM and Modules ready syntax
// | require(["dojo/ready"], function(ready){
// | ready(function(){ alert("Dom ready!"); });
// | });
//
// example:
// Using a priority
// | require(["dojo/ready"], function(ready){
// | ready(2, function(){ alert("low priority ready!"); })
// | });
//
// example:
// Using context
// | require(["dojo/ready"], function(ready){
// | ready(foo, function(){
// | // in here, this == foo
// | });
// | });
//
// example:
// Using dojo/hitch style args:
// | require(["dojo/ready"], function(ready){
// | var foo = { dojoReady: function(){ console.warn(this, "dojo dom and modules ready."); } };
// | ready(foo, "dojoReady");
// | });
var hitchArgs = lang._toArray(arguments);
if(typeof priority != "number"){
callback = context;
context = priority;
priority = 1000;
}else{
hitchArgs.shift();
}
callback = callback ?
lang.hitch.apply(dojo, hitchArgs) :
function(){
context();
};
callback.priority = priority;
for(var i = 0; i < loadQ.length && priority >= loadQ[i].priority; i++){}
loadQ.splice(i, 0, callback);
requestCompleteSignal();
};
1 || has.add("dojo-config-addOnLoad", 1);
if( 1 ){
var dca = dojo.config.addOnLoad;
if(dca){
ready[(lang.isArray(dca) ? "apply" : "call")](dojo, dca);
}
}
if( 1 && dojo.config.parseOnLoad && !dojo.isAsync){
ready(99, function(){
if(!dojo.parser){
dojo.deprecated("Add explicit require(['dojo/parser']);", "", "2.0");
require(["dojo/parser"]);
}
});
}
if( 1 ){
domReady(handleDomReady);
}else{
handleDomReady();
}
return ready;
});