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