]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/ready.js.uncompressed.js
1 define("dojo/ready", ["./_base/kernel", "./has", "require", "./domReady", "./_base/lang"], function(dojo
, has
, require
, domReady
, lang
) {
5 // This module defines the dojo.ready API.
8 // This module should be unnecessary in dojo 2.0
10 // truthy if DOMContentLoaded or better (e.g., window.onload fired) has been achieved
13 // a function to call to cause onLoad to be called when all requested modules have been loaded
14 requestCompleteSignal
,
16 // The queue of functions waiting to execute as soon as dojo.ready conditions satisfied
19 // prevent recursion in onLoad
20 onLoadRecursiveGuard
= 0,
22 handleDomReady = function(){
24 dojo
._postLoad
= dojo
.config
.afterOnLoad
= true;
26 requestCompleteSignal(onLoad
);
30 // run the next function queued with dojo.ready
32 if(isDomReady
&& !onLoadRecursiveGuard
&& loadQ
.length
){
33 //guard against recursions into this function
34 onLoadRecursiveGuard
= 1;
35 var f
= loadQ
.shift();
39 // FIXME: signal the error via require.on
41 onLoadRecursiveGuard
= 0;
43 onLoadRecursiveGuard
= 0;
45 requestCompleteSignal(onLoad
);
50 // define requireCompleteSignal; impl depends on loader
52 require
.on("idle", onLoad
);
53 requestCompleteSignal = function(){
56 } // else do nothing, onLoad will be called with the next idle signal
59 // RequireJS or similar
60 requestCompleteSignal = function(){
61 // the next function call will fail if you don't have a loader with require.ready
62 // in that case, either fix your loader, use dojo's loader, or don't call dojo.ready;
63 require
.ready(onLoad
);
67 var ready
= dojo
.ready
= dojo
.addOnLoad = function(priority
, context
, callback
){
68 // summary: Add a function to execute on DOM content loaded and all requested modules have arrived and been evaluated.
70 // The order in which to exec this callback relative to other callbacks, defaults to 1000
71 // context: Object?|Function
72 // The context in which to run execute callback, or a callback if not using context
73 // callback: Function?
74 // The function to execute.
77 // Simple DOM and Modules ready syntax
78 // | dojo.ready(function(){ alert("Dom ready!"); });
82 // | dojo.ready(2, function(){ alert("low priority ready!"); })
86 // | dojo.ready(foo, function(){
87 // | // in here, this == foo
91 // Using dojo.hitch style args:
92 // | var foo = { dojoReady: function(){ console.warn(this, "dojo dom and modules ready."); } };
93 // | dojo.ready(foo, "dojoReady");
95 var hitchArgs
= lang
._toArray(arguments
);
96 if(typeof priority
!= "number"){
103 callback
= callback
?
104 lang
.hitch
.apply(dojo
, hitchArgs
) :
108 callback
.priority
= priority
;
109 for(var i
= 0; i
< loadQ
.length
&& priority
>= loadQ
[i
].priority
; i
++){}
110 loadQ
.splice(i
, 0, callback
);
111 requestCompleteSignal();
114 true || has
.add("dojo-config-addOnLoad", 1);
116 var dca
= dojo
.config
.addOnLoad
;
118 ready
[(lang
.isArray(dca
) ? "apply" : "call")](dojo
, dca
);
122 if(1 && dojo
.config
.parseOnLoad
&& !dojo
.isAsync
){
123 ready(99, function(){
125 dojo
.deprecated("Add explicit require(['dojo/parser']);", "", "2.0");
126 require(["dojo/parser"]);
132 domReady(handleDomReady
);