/public/javascripts/dojo/release/dojo/dojo/_base/_loader/bootstrap.js

http://enginey.googlecode.com/ · JavaScript · 462 lines · 119 code · 32 blank · 311 comment · 35 complexity · 78f09dc318e8197cb7c8bb1cfdf72c3c MD5 · raw file

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