kernel.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. define(["../has", "./config", "require", "module"], function(has, config, require, module){
  2. // module:
  3. // dojo/_base/kernel
  4. // This module is the foundational module of the dojo boot sequence; it defines the dojo object.
  5. var
  6. // loop variables for this module
  7. i, p,
  8. // create dojo, dijit, and dojox
  9. // FIXME: in 2.0 remove dijit, dojox being created by dojo
  10. global = (function () { return this; })(),
  11. dijit = {},
  12. dojox = {},
  13. dojo = {
  14. // summary:
  15. // This module is the foundational module of the dojo boot sequence; it defines the dojo object.
  16. // notice dojo takes ownership of the value of the config module
  17. config:config,
  18. global:global,
  19. dijit:dijit,
  20. dojox:dojox
  21. };
  22. // Configure the scope map. For a 100% AMD application, the scope map is not needed other than to provide
  23. // a _scopeName property for the dojo, dijit, and dojox root object so those packages can create
  24. // unique names in the global space.
  25. //
  26. // Built, legacy modules use the scope map to allow those modules to be expressed as if dojo, dijit, and dojox,
  27. // where global when in fact they are either global under different names or not global at all. In v1.6-, the
  28. // config variable "scopeMap" was used to map names as used within a module to global names. This has been
  29. // subsumed by the AMD map configuration variable which can relocate packages to different names. For backcompat,
  30. // only the "*" mapping is supported. See http://livedocs.dojotoolkit.org/developer/design/loader#legacy-cross-domain-mode for details.
  31. //
  32. // The following computations contort the packageMap for this dojo instance into a scopeMap.
  33. var scopeMap =
  34. // a map from a name used in a legacy module to the (global variable name, object addressed by that name)
  35. // always map dojo, dijit, and dojox
  36. {
  37. dojo:["dojo", dojo],
  38. dijit:["dijit", dijit],
  39. dojox:["dojox", dojox]
  40. },
  41. packageMap =
  42. // the package map for this dojo instance; note, a foreign loader or no pacakgeMap results in the above default config
  43. (require.map && require.map[module.id.match(/[^\/]+/)[0]]),
  44. item;
  45. // process all mapped top-level names for this instance of dojo
  46. for(p in packageMap){
  47. if(scopeMap[p]){
  48. // mapped dojo, dijit, or dojox
  49. scopeMap[p][0] = packageMap[p];
  50. }else{
  51. // some other top-level name
  52. scopeMap[p] = [packageMap[p], {}];
  53. }
  54. }
  55. // publish those names to _scopeName and, optionally, the global namespace
  56. for(p in scopeMap){
  57. item = scopeMap[p];
  58. item[1]._scopeName = item[0];
  59. if(!config.noGlobals){
  60. global[item[0]] = item[1];
  61. }
  62. }
  63. dojo.scopeMap = scopeMap;
  64. /*===== dojo.__docParserConfigureScopeMap(scopeMap); =====*/
  65. // FIXME: dojo.baseUrl and dojo.config.baseUrl should be deprecated
  66. dojo.baseUrl = dojo.config.baseUrl = require.baseUrl;
  67. dojo.isAsync = !has("dojo-loader") || require.async;
  68. dojo.locale = config.locale;
  69. var rev = "$Rev: f4fef70 $".match(/[0-9a-f]{7,}/);
  70. dojo.version = {
  71. // summary:
  72. // Version number of the Dojo Toolkit
  73. // description:
  74. // Hash about the version, including
  75. //
  76. // - major: Integer: Major version. If total version is "1.2.0beta1", will be 1
  77. // - minor: Integer: Minor version. If total version is "1.2.0beta1", will be 2
  78. // - patch: Integer: Patch version. If total version is "1.2.0beta1", will be 0
  79. // - flag: String: Descriptor flag. If total version is "1.2.0beta1", will be "beta1"
  80. // - revision: Number: The Git rev from which dojo was pulled
  81. major: 1, minor: 10, patch: 4, flag: "",
  82. revision: rev ? rev[0] : NaN,
  83. toString: function(){
  84. var v = dojo.version;
  85. return v.major + "." + v.minor + "." + v.patch + v.flag + " (" + v.revision + ")"; // String
  86. }
  87. };
  88. // If has("extend-dojo") is truthy, then as a dojo module is defined it should push it's definitions
  89. // into the dojo object, and conversely. In 2.0, it will likely be unusual to augment another object
  90. // as a result of defining a module. This has feature gives a way to force 2.0 behavior as the code
  91. // is migrated. Absent specific advice otherwise, set extend-dojo to truthy.
  92. has.add("extend-dojo", 1);
  93. (Function("d", "d.eval = function(){return d.global.eval ? d.global.eval(arguments[0]) : eval(arguments[0]);}"))(dojo);
  94. /*=====
  95. dojo.eval = function(scriptText){
  96. // summary:
  97. // A legacy method created for use exclusively by internal Dojo methods. Do not use this method
  98. // directly unless you understand its possibly-different implications on the platforms your are targeting.
  99. // description:
  100. // Makes an attempt to evaluate scriptText in the global scope. The function works correctly for browsers
  101. // that support indirect eval.
  102. //
  103. // As usual, IE does not. On IE, the only way to implement global eval is to
  104. // use execScript. Unfortunately, execScript does not return a value and breaks some current usages of dojo.eval.
  105. // This implementation uses the technique of executing eval in the scope of a function that is a single scope
  106. // frame below the global scope; thereby coming close to the global scope. Note carefully that
  107. //
  108. // dojo.eval("var pi = 3.14;");
  109. //
  110. // will define global pi in non-IE environments, but define pi only in a temporary local scope for IE. If you want
  111. // to define a global variable using dojo.eval, write something like
  112. //
  113. // dojo.eval("window.pi = 3.14;")
  114. // scriptText:
  115. // The text to evaluation.
  116. // returns:
  117. // The result of the evaluation. Often `undefined`
  118. };
  119. =====*/
  120. if(has("host-rhino")){
  121. dojo.exit = function(exitcode){
  122. quit(exitcode);
  123. };
  124. }else{
  125. dojo.exit = function(){
  126. };
  127. }
  128. has.add("dojo-guarantee-console",
  129. // ensure that console.log, console.warn, etc. are defined
  130. 1
  131. );
  132. if(has("dojo-guarantee-console")){
  133. typeof console != "undefined" || (console = {});
  134. // Be careful to leave 'log' always at the end
  135. var cn = [
  136. "assert", "count", "debug", "dir", "dirxml", "error", "group",
  137. "groupEnd", "info", "profile", "profileEnd", "time", "timeEnd",
  138. "trace", "warn", "log"
  139. ];
  140. var tn;
  141. i = 0;
  142. while((tn = cn[i++])){
  143. if(!console[tn]){
  144. (function(){
  145. var tcn = tn + "";
  146. console[tcn] = ('log' in console) ? function(){
  147. var a = Array.prototype.slice.call(arguments);
  148. a.unshift(tcn + ":");
  149. console["log"](a.join(" "));
  150. } : function(){};
  151. console[tcn]._fake = true;
  152. })();
  153. }
  154. }
  155. }
  156. has.add("dojo-debug-messages",
  157. // include dojo.deprecated/dojo.experimental implementations
  158. !!config.isDebug
  159. );
  160. dojo.deprecated = dojo.experimental = function(){};
  161. if(has("dojo-debug-messages")){
  162. dojo.deprecated = function(/*String*/ behaviour, /*String?*/ extra, /*String?*/ removal){
  163. // summary:
  164. // Log a debug message to indicate that a behavior has been
  165. // deprecated.
  166. // behaviour: String
  167. // The API or behavior being deprecated. Usually in the form
  168. // of "myApp.someFunction()".
  169. // extra: String?
  170. // Text to append to the message. Often provides advice on a
  171. // new function or facility to achieve the same goal during
  172. // the deprecation period.
  173. // removal: String?
  174. // Text to indicate when in the future the behavior will be
  175. // removed. Usually a version number.
  176. // example:
  177. // | dojo.deprecated("myApp.getTemp()", "use myApp.getLocaleTemp() instead", "1.0");
  178. var message = "DEPRECATED: " + behaviour;
  179. if(extra){ message += " " + extra; }
  180. if(removal){ message += " -- will be removed in version: " + removal; }
  181. console.warn(message);
  182. };
  183. dojo.experimental = function(/* String */ moduleName, /* String? */ extra){
  184. // summary:
  185. // Marks code as experimental.
  186. // description:
  187. // This can be used to mark a function, file, or module as
  188. // experimental. Experimental code is not ready to be used, and the
  189. // APIs are subject to change without notice. Experimental code may be
  190. // completed deleted without going through the normal deprecation
  191. // process.
  192. // moduleName: String
  193. // The name of a module, or the name of a module file or a specific
  194. // function
  195. // extra: String?
  196. // some additional message for the user
  197. // example:
  198. // | dojo.experimental("dojo.data.Result");
  199. // example:
  200. // | dojo.experimental("dojo.weather.toKelvin()", "PENDING approval from NOAA");
  201. var message = "EXPERIMENTAL: " + moduleName + " -- APIs subject to change without notice.";
  202. if(extra){ message += " " + extra; }
  203. console.warn(message);
  204. };
  205. }
  206. has.add("dojo-modulePaths",
  207. // consume dojo.modulePaths processing
  208. 1
  209. );
  210. if(has("dojo-modulePaths")){
  211. // notice that modulePaths won't be applied to any require's before the dojo/_base/kernel factory is run;
  212. // this is the v1.6- behavior.
  213. if(config.modulePaths){
  214. dojo.deprecated("dojo.modulePaths", "use paths configuration");
  215. var paths = {};
  216. for(p in config.modulePaths){
  217. paths[p.replace(/\./g, "/")] = config.modulePaths[p];
  218. }
  219. require({paths:paths});
  220. }
  221. }
  222. has.add("dojo-moduleUrl",
  223. // include dojo.moduleUrl
  224. 1
  225. );
  226. if(has("dojo-moduleUrl")){
  227. dojo.moduleUrl = function(/*String*/module, /*String?*/url){
  228. // summary:
  229. // Returns a URL relative to a module.
  230. // example:
  231. // | var pngPath = dojo.moduleUrl("acme","images/small.png");
  232. // | console.dir(pngPath); // list the object properties
  233. // | // create an image and set it's source to pngPath's value:
  234. // | var img = document.createElement("img");
  235. // | img.src = pngPath;
  236. // | // add our image to the document
  237. // | dojo.body().appendChild(img);
  238. // example:
  239. // you may de-reference as far as you like down the package
  240. // hierarchy. This is sometimes handy to avoid lengthy relative
  241. // urls or for building portable sub-packages. In this example,
  242. // the `acme.widget` and `acme.util` directories may be located
  243. // under different roots (see `dojo.registerModulePath`) but the
  244. // the modules which reference them can be unaware of their
  245. // relative locations on the filesystem:
  246. // | // somewhere in a configuration block
  247. // | dojo.registerModulePath("acme.widget", "../../acme/widget");
  248. // | dojo.registerModulePath("acme.util", "../../util");
  249. // |
  250. // | // ...
  251. // |
  252. // | // code in a module using acme resources
  253. // | var tmpltPath = dojo.moduleUrl("acme.widget","templates/template.html");
  254. // | var dataPath = dojo.moduleUrl("acme.util","resources/data.json");
  255. dojo.deprecated("dojo.moduleUrl()", "use require.toUrl", "2.0");
  256. // require.toUrl requires a filetype; therefore, just append the suffix "/*.*" to guarantee a filetype, then
  257. // remove the suffix from the result. This way clients can request a url w/out a filetype. This should be
  258. // rare, but it maintains backcompat for the v1.x line (note: dojo.moduleUrl will be removed in v2.0).
  259. // Notice * is an illegal filename so it won't conflict with any real path map that may exist the paths config.
  260. var result = null;
  261. if(module){
  262. result = require.toUrl(module.replace(/\./g, "/") + (url ? ("/" + url) : "") + "/*.*").replace(/\/\*\.\*/, "") + (url ? "" : "/");
  263. }
  264. return result;
  265. };
  266. }
  267. dojo._hasResource = {}; // for backward compatibility with layers built with 1.6 tooling
  268. return dojo;
  269. });