kernel.js 11 KB

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