diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dojo/ready.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dojo/ready.js.uncompressed.js')
-rw-r--r-- | lib/dojo/ready.js.uncompressed.js | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/lib/dojo/ready.js.uncompressed.js b/lib/dojo/ready.js.uncompressed.js new file mode 100644 index 000000000..454a24a9f --- /dev/null +++ b/lib/dojo/ready.js.uncompressed.js @@ -0,0 +1,136 @@ +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; +}); |