]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/_base/_loader/bootstrap.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojo / _base / _loader / bootstrap.js
1 /*=====
2 // note:
3 //              'djConfig' does not exist under 'dojo.*' so that it can be set before the
4 //              'dojo' variable exists.
5 // note:
6 //              Setting any of these variables *after* the library has loaded does
7 //              nothing at all.
8
9 djConfig = {
10         // summary:
11         //              Application code can set the global 'djConfig' prior to loading
12         //              the library to override certain global settings for how dojo works.
13         //
14         // isDebug: Boolean
15         //              Defaults to `false`. If set to `true`, ensures that Dojo provides
16         //              extende debugging feedback via Firebug. If Firebug is not available
17         //              on your platform, setting `isDebug` to `true` will force Dojo to
18         //              pull in (and display) the version of Firebug Lite which is
19         //              integrated into the Dojo distribution, thereby always providing a
20         //              debugging/logging console when `isDebug` is enabled. Note that
21         //              Firebug's `console.*` methods are ALWAYS defined by Dojo. If
22         //              `isDebug` is false and you are on a platform without Firebug, these
23         //              methods will be defined as no-ops.
24         isDebug: false,
25         // debugAtAllCosts: Boolean
26         //              Defaults to `false`. If set to `true`, this triggers an alternate
27         //              mode of the package system in which dependencies are detected and
28         //              only then are resources evaluated in dependency order via
29         //              `<script>` tag inclusion. This may double-request resources and
30         //              cause problems with scripts which expect `dojo.require()` to
31         //              preform synchronously. `debugAtAllCosts` can be an invaluable
32         //              debugging aid, but when using it, ensure that all code which
33         //              depends on Dojo modules is wrapped in `dojo.addOnLoad()` handlers.
34         //              Due to the somewhat unpredictable side-effects of using
35         //              `debugAtAllCosts`, it is strongly recommended that you enable this
36         //              flag as a last resort. `debugAtAllCosts` has no effect when loading
37         //              resources across domains. For usage information, see the
38         //              [Dojo Book](http://dojotoolkit.org/book/book-dojo/part-4-meta-dojo-making-your-dojo-code-run-faster-and-better/debugging-facilities/deb)
39         debugAtAllCosts: false,
40         // locale: String
41         //              The locale to assume for loading localized resources in this page,
42         //              specified according to [RFC 3066](http://www.ietf.org/rfc/rfc3066.txt).
43         //              Must be specified entirely in lowercase, e.g. `en-us` and `zh-cn`.
44         //              See the documentation for `dojo.i18n` and `dojo.requireLocalization`
45         //              for details on loading localized resources. If no locale is specified,
46         //              Dojo assumes the locale of the user agent, according to `navigator.userLanguage`
47         //              or `navigator.language` properties.
48         locale: undefined,
49         // extraLocale: Array
50         //              No default value. Specifies additional locales whose
51         //              resources should also be loaded alongside the default locale when
52         //              calls to `dojo.requireLocalization()` are processed.
53         extraLocale: undefined,
54         // baseUrl: String
55         //              The directory in which `dojo.js` is located. Under normal
56         //              conditions, Dojo auto-detects the correct location from which it
57         //              was loaded. You may need to manually configure `baseUrl` in cases
58         //              where you have renamed `dojo.js` or in which `<base>` tags confuse
59         //              some browsers (e.g., IE 6). The variable `dojo.baseUrl` is assigned
60         //              either the value of `djConfig.baseUrl` if one is provided or the
61         //              auto-detected root if not. Other modules are located relative to
62         //              this path.
63         baseUrl: undefined,
64         // modulePaths: Object
65         //              A map of module names to paths relative to `dojo.baseUrl`. The
66         //              key/value pairs correspond directly to the arguments which
67         //              `dojo.registerModulePath` accepts. Specifiying
68         //              `djConfig.modulePaths = { "foo": "../../bar" }` is the equivalent
69         //              of calling `dojo.registerModulePath("foo", "../../bar");`. Multiple
70         //              modules may be configured via `djConfig.modulePaths`.
71         modulePaths: {},
72 }
73 =====*/
74
75 (function(){
76         // firebug stubs
77
78         // if((!this["console"])||(!console["firebug"])){
79
80         if(!this["console"]){
81                 this.console = {
82                         log: function(){} // no-op
83                 };
84         }
85
86         var cn = [
87                 "assert", "count", "debug", "dir", "dirxml", "error", "group",
88                 "groupEnd", "info", "profile", "profileEnd", "time", "timeEnd",
89                 "trace", "warn", "log" 
90         ];
91         var i=0, tn;
92         while((tn=cn[i++])){
93                 if(!console[tn]){
94                         (function(){
95                                 var tcn = tn+"";
96                                 console[tcn] = function(){ 
97                                         var a = Array.apply({}, arguments);
98                                         a.unshift(tcn+":");
99                                         console.log(a.join(" "));
100                                 }
101                         })();
102                 }
103         }
104
105         //TODOC:  HOW TO DOC THIS?
106         // dojo is the root variable of (almost all) our public symbols -- make sure it is defined.
107         if(typeof dojo == "undefined"){
108                 this.dojo = {
109                         _scopeName: "dojo",
110                         _scopePrefix: "",
111                         _scopePrefixArgs: "",
112                         _scopeSuffix: "",
113                         _scopeMap: {},
114                         _scopeMapRev: {}
115                 };
116         }
117
118         var d = dojo;
119
120         //Need placeholders for dijit and dojox for scoping code.
121         if(typeof dijit == "undefined"){
122                 this.dijit = {_scopeName: "dijit"};
123         }
124         if(typeof dojox == "undefined"){
125                 this.dojox = {_scopeName: "dojox"};
126         }
127         
128         if(!d._scopeArgs){
129                 d._scopeArgs = [dojo, dijit, dojox];
130         }
131
132 /*=====
133 dojo.global = {
134         //      summary:
135         //              Alias for the global scope
136         //              (e.g. the window object in a browser).
137         //      description:
138         //              Refer to 'dojo.global' rather than referring to window to ensure your
139         //              code runs correctly in contexts other than web browsers (e.g. Rhino on a server).
140 }
141 =====*/
142         d.global = this;
143
144         d.config =/*===== djConfig = =====*/{
145                 isDebug: false,
146                 debugAtAllCosts: false
147         };
148
149         if(typeof djConfig != "undefined"){
150                 for(var opt in djConfig){
151                         d.config[opt] = djConfig[opt];
152                 }
153         }
154
155         var _platforms = ["Browser", "Rhino", "Spidermonkey", "Mobile"];
156         var t;
157         while((t=_platforms.shift())){
158                 d["is"+t] = false;
159         }
160
161 /*=====
162         // Override locale setting, if specified
163         dojo.locale = {
164                 // summary: the locale as defined by Dojo (read-only)
165         };
166 =====*/
167         dojo.locale = d.config.locale;
168         
169         var rev = "$Rev: 13707 $".match(/\d+/);
170
171         dojo.version = {
172                 // summary: 
173                 //              version number of dojo
174                 //      major: Integer
175                 //              Major version. If total version is "1.2.0beta1", will be 1
176                 //      minor: Integer
177                 //              Minor version. If total version is "1.2.0beta1", will be 2
178                 //      patch: Integer
179                 //              Patch version. If total version is "1.2.0beta1", will be 0
180                 //      flag: String
181                 //              Descriptor flag. If total version is "1.2.0beta1", will be "beta1"
182                 //      revision: Number
183                 //              The SVN rev from which dojo was pulled
184                 major: 1, minor: 1, patch: 1, flag: "",
185                 revision: rev ? +rev[0] : 999999, //FIXME: use NaN?
186                 toString: function(){
187                         with(d.version){
188                                 return major + "." + minor + "." + patch + flag + " (" + revision + ")";        // String
189                         }
190                 }
191         }
192
193         // Register with the OpenAjax hub
194         if(typeof OpenAjax != "undefined"){
195                 OpenAjax.hub.registerLibrary(dojo._scopeName, "http://dojotoolkit.org", d.version.toString());
196         }
197
198         dojo._mixin = function(/*Object*/ obj, /*Object*/ props){
199                 // summary:
200                 //              Adds all properties and methods of props to obj. This addition
201                 //              is "prototype extension safe", so that instances of objects
202                 //              will not pass along prototype defaults.
203                 var tobj = {};
204                 for(var x in props){
205                         // the "tobj" condition avoid copying properties in "props"
206                         // inherited from Object.prototype.  For example, if obj has a custom
207                         // toString() method, don't overwrite it with the toString() method
208                         // that props inherited from Object.prototype
209                         if(tobj[x] === undefined || tobj[x] != props[x]){
210                                 obj[x] = props[x];
211                         }
212                 }
213                 // IE doesn't recognize custom toStrings in for..in
214                 if(d["isIE"] && props){
215                         var p = props.toString;
216                         if(typeof p == "function" && p != obj.toString && p != tobj.toString &&
217                                 p != "\nfunction toString() {\n    [native code]\n}\n"){
218                                         obj.toString = props.toString;
219                         }
220                 }
221                 return obj; // Object
222         }
223
224         dojo.mixin = function(/*Object*/obj, /*Object...*/props){
225                 // summary:     
226                 //              Adds all properties and methods of props to obj and returns the
227                 //              (now modified) obj.
228                 //      description:
229                 //              `dojo.mixin` can mix multiple source objects into a
230                 //              destionation object which is then returned. Unlike regular
231                 //              `for...in` iteration, `dojo.mixin` is also smart about avoiding
232                 //              extensions which other toolkits may unwisely add to the root
233                 //              object prototype
234                 //      obj:
235                 //              The object to mix properties into. Also the return value.
236                 //      props:
237                 //              One or more objects whose values are successively copied into
238                 //              obj. If more than one of these objects contain the same value,
239                 //              the one specified last in the function call will "win".
240                 //      example:
241                 //              make a shallow copy of an object
242                 //      |       var copy = dojo.mixin({}, source);
243                 //      example:
244                 //              many class constructors often take an object which specifies
245                 //              values to be configured on the object. In this case, it is
246                 //              often simplest to call `dojo.mixin` on the `this` object:
247                 //      |       dojo.declare("acme.Base", null, {
248                 //      |               constructor: function(properties){
249                 //      |                       // property configuration:
250                 //      |                       dojo.mixin(this, properties);
251                 //      |       
252                 //      |                       console.debug(this.quip);
253                 //      |                       //  ...
254                 //      |               },
255                 //      |               quip: "I wasn't born yesterday, you know - I've seen movies.",
256                 //      |               // ...
257                 //      |       });
258                 //      |
259                 //      |       // create an instance of the class and configure it
260                 //      |       var b = new acme.Base({quip: "That's what it does!" });
261                 //      example:
262                 //              copy in properties from multiple objects
263                 //      |       var flattened = dojo.mixin(
264                 //      |               {
265                 //      |                       name: "Frylock",
266                 //      |                       braces: true,
267                 //      |               }
268                 //      |               {
269                 //      |                       name: "Carl Brutanananadilewski"
270                 //      |               }
271                 //      |       );
272                 //      |       
273                 //      |       // will print "Carl Brutanananadilewski"
274                 //      |       console.debug(flattened.name);
275                 //      |       // will print "true"
276                 //      |       console.debug(flattened.braces);
277                 for(var i=1, l=arguments.length; i<l; i++){
278                         d._mixin(obj, arguments[i]);
279                 }
280                 return obj; // Object
281         }
282
283         dojo._getProp = function(/*Array*/parts, /*Boolean*/create, /*Object*/context){
284                 var obj=context || d.global;
285                 for(var i=0, p; obj && (p=parts[i]); i++){
286                         if(i == 0 && this._scopeMap[p]){
287                                 p = this._scopeMap[p];
288                         }
289                         obj = (p in obj ? obj[p] : (create ? obj[p]={} : undefined));
290                 }
291                 return obj; // mixed
292         }
293
294         dojo.setObject = function(/*String*/name, /*Object*/value, /*Object?*/context){
295                 // summary: 
296                 //              Set a property from a dot-separated string, such as "A.B.C"
297                 //      description: 
298                 //              Useful for longer api chains where you have to test each object in
299                 //              the chain, or when you have an object reference in string format.
300                 //              Objects are created as needed along `path`. Returns the passed
301                 //              value if setting is successful or `undefined` if not.
302                 //      name:   
303                 //              Path to a property, in the form "A.B.C".
304                 //      context:
305                 //              Optional. Object to use as root of path. Defaults to
306                 //              `dojo.global`.
307                 //      example:
308                 //              set the value of `foo.bar.baz`, regardless of whether
309                 //              intermediate objects already exist:
310                 //      |       dojo.setObject("foo.bar.baz", value);
311                 //      example:
312                 //              without `dojo.setObject`, we often see code like this:
313                 //      |       // ensure that intermediate objects are available
314                 //      |       if(!obj["parent"]){ obj.parent = {}; }
315                 //      |       if(!obj.parent["child"]){ obj.parent.child= {}; }
316                 //      |       // now we can safely set the property
317                 //      |       obj.parent.child.prop = "some value";
318                 //              wheras with `dojo.setObject`, we can shorten that to:
319                 //      |       dojo.setObject("parent.child.prop", "some value", obj);
320                 var parts=name.split("."), p=parts.pop(), obj=d._getProp(parts, true, context);
321                 return obj && p ? (obj[p]=value) : undefined; // Object
322         }
323
324         dojo.getObject = function(/*String*/name, /*Boolean*/create, /*Object*/context){
325                 // summary: 
326                 //              Get a property from a dot-separated string, such as "A.B.C"
327                 //      description: 
328                 //              Useful for longer api chains where you have to test each object in
329                 //              the chain, or when you have an object reference in string format.
330                 //      name:   
331                 //              Path to an property, in the form "A.B.C".
332                 //      context:
333                 //              Optional. Object to use as root of path. Defaults to
334                 //              'dojo.global'. Null may be passed.
335                 //      create: 
336                 //              Optional. Defaults to `false`. If `true`, Objects will be
337                 //              created at any point along the 'path' that is undefined.
338                 return d._getProp(name.split("."), create, context); // Object
339         }
340
341         dojo.exists = function(/*String*/name, /*Object?*/obj){
342                 //      summary: 
343                 //              determine if an object supports a given method
344                 //      description: 
345                 //              useful for longer api chains where you have to test each object in
346                 //              the chain
347                 //      name:   
348                 //              Path to an object, in the form "A.B.C".
349                 //      obj:
350                 //              Object to use as root of path. Defaults to
351                 //              'dojo.global'. Null may be passed.
352                 //      example:
353                 //      |       // define an object
354                 //      |       var foo = {
355                 //      |               bar: { }
356                 //      |       };
357                 //      |
358                 //      |       // search the global scope
359                 //      |       dojo.exists("foo.bar"); // true
360                 //      |       dojo.exists("foo.bar.baz"); // false
361                 //      |
362                 //      |       // search from a particular scope
363                 //      |       dojo.exists("bar", foo); // true
364                 //      |       dojo.exists("bar.baz", foo); // false
365                 return !!d.getObject(name, false, obj); // Boolean
366         }
367
368
369         dojo["eval"] = function(/*String*/ scriptFragment){
370                 //      summary: 
371                 //              Perform an evaluation in the global scope. Use this rather than
372                 //              calling 'eval()' directly.
373                 //      description: 
374                 //              Placed in a separate function to minimize size of trapped
375                 //              exceptions. Calling eval() directly from some other scope may
376                 //              complicate tracebacks on some platforms.
377                 //      return:
378                 //              The result of the evaluation. Often `undefined`
379
380
381                 // note:
382                 //       - JSC eval() takes an optional second argument which can be 'unsafe'.
383                 //       - Mozilla/SpiderMonkey eval() takes an optional second argument which is the
384                 //       scope object for new symbols.
385
386                 // FIXME: investigate Joseph Smarr's technique for IE:
387                 //              http://josephsmarr.com/2007/01/31/fixing-eval-to-use-global-scope-in-ie/
388                 //      see also:
389                 //              http://trac.dojotoolkit.org/ticket/744
390                 return d.global.eval ? d.global.eval(scriptFragment) : eval(scriptFragment);    // Object
391         }
392
393         /*=====
394                 dojo.deprecated = function(behaviour, extra, removal){
395                         //      summary: 
396                         //              Log a debug message to indicate that a behavior has been
397                         //              deprecated.
398                         //      behaviour: String
399                         //              The API or behavior being deprecated. Usually in the form
400                         //              of "myApp.someFunction()".
401                         //      extra: String?
402                         //              Text to append to the message. Often provides advice on a
403                         //              new function or facility to achieve the same goal during
404                         //              the deprecation period.
405                         //      removal: String?
406                         //              Text to indicate when in the future the behavior will be
407                         //              removed. Usually a version number.
408                         //      example:
409                         //      |       dojo.deprecated("myApp.getTemp()", "use myApp.getLocaleTemp() instead", "1.0");
410                 }
411
412                 dojo.experimental = function(moduleName, extra){
413                         //      summary: Marks code as experimental.
414                         //      description: 
415                         //              This can be used to mark a function, file, or module as
416                         //              experimental.  Experimental code is not ready to be used, and the
417                         //              APIs are subject to change without notice.  Experimental code may be
418                         //              completed deleted without going through the normal deprecation
419                         //              process.
420                         //      moduleName: String
421                         //              The name of a module, or the name of a module file or a specific
422                         //              function
423                         //      extra: String?
424                         //              some additional message for the user
425                         //      example:
426                         //      |       dojo.experimental("dojo.data.Result");
427                         //      example:
428                         //      |       dojo.experimental("dojo.weather.toKelvin()", "PENDING approval from NOAA");
429                 }
430         =====*/
431
432         //Real functions declared in dojo._firebug.firebug.
433         d.deprecated = d.experimental = function(){};
434
435 })();
436 // vim:ai:ts=4:noet