source: Dev/branches/rest-dojo-ui/client/dojo/_base/kernel.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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