Debian Codegraph @

util/doh/_parseURLargs.js

raw symbols SCIP
1 (function(){
2 var
3 boot =
4 // zero to many scripts to load a configuration and/or loader.
5 // i.e. path-to-util/doh/runner.html?boots=path-to/config.js,path-to/require.js
6 ["../../dojo/dojo.js"],
7
8 standardDojoBoot = boot,
9
10 test =
11 // zero to many AMD modules and/or URLs to load; provided by csv URL query parameter="test"
12 // For example, the URL...
13 //
14 // path-to-util/doh/runner.html?test=doh/selfTest,my/path/test.js
15 //
16 // ...will load...
17 //
18 // * the AMD module doh/selfTest
19 // * the plain old Javascript resource my/path/test.js
20 //
21 ["dojo/tests/module"],
22
23 paths =
24 // zero to many path items to pass to the AMD loader; provided by semicolon separated values
25 // for URL query parameter="paths"; each path item has the form <from-path>,<to-path>
26 // i.e. path-to-util/doh/runner.html?paths=my/from/path,my/to/path;my/from/path2,my/to/path2
27 {},
28
29 dohPlugins =
30 // Semicolon separated list of files to load before the tests.
31 // Idea is to override aspects of DOH for reporting purposes.
32 "",
33
34 breakOnError =
35 // boolean; instructs doh to call the debugger upon a test failures; this can be helpful when
36 // trying to isolate exactly where the test failed
37 false,
38
39 async =
40 // boolean; config require.async==true before loading boot; this will have the effect of making
41 // version 1.7+ dojo bootstrap/loader operating in async mode
42 false,
43
44 sandbox =
45 // boolean; use a loader configuration that sandboxes the dojo and dojox objects used by doh
46 false,
47
48 trim = function(text){
49 if(text instanceof Array){
50 for (var result= [], i= 0; i<text.length; i++) {
51 result.push(trim(text[i]));
52 }
53 return result;
54 }else{
55 return text.match(/[^\s]*/)[0];
56 }
57 },
58 packages= [];
59
60 qstr = window.location.search.substr(1);
61
62 if(qstr.length){
63 for(var qparts = qstr.split("&"), x = 0; x < qparts.length; x++){
64 var tp = qparts[x].split("="), name=tp[0], value=(tp[1]||"").replace(/[<>"':\(\)]/g, ""); // replace() to avoid XSS attack
65 //Avoid URLs that use the same protocol but on other domains, for security reasons.
66 if (value.indexOf("//") === 0 || value.indexOf("\\\\") === 0) {
67 throw "Insupported URL";
68 }
69 switch(name){
70 // Note:
71 // * dojoUrl is deprecated, and is a synonym for boot
72 // * testUrl is deprecated, and is a synonym for test
73 // * testModule is deprecated, and is a synonym for test (dots are automatically replaced with slashes)
74 // * registerModulePath is deprecated, and is a synonym for paths
75 case "boot":
76 case "dojoUrl":
77 boot= trim(value.split(","));
78 break;
79
80 case "test":
81 case "testUrl":
82 test= trim(value.split(","));
83 break;
84
85 case "testModule":
86 test= trim(value.replace(/\./g, "/").split(","));
87 break;
88
89 // registerModulePath is deprecated; use "paths"
90 case "registerModulePath":
91 case "paths":
92 for(var path, modules = value.split(";"), i= 0; i<modules.length; i++){
93 path= modules[i].split(",");
94 paths[trim(path[0])]= trim(path[1]);
95 }
96 break;
97
98 case "breakOnError":
99 breakOnError= true;
100 break;
101
102 case "sandbox":
103 sandbox= true;
104 break;
105
106 case "async":
107 async= true;
108 break;
109 case "dohPlugins":
110 dohPlugins=value.split(";");
111 break;
112 case 'mapPackage':
113 var packagesRaw=value.split(';');
114 for (var i = 0; i < packagesRaw.length; i++) {
115 var parts = packagesRaw[i].split(',');
116 packages.push({
117 name: parts[0],
118 location: parts[1]
119 });
120 }
121
122 break;
123 }
124 }
125 }
126
127 var config;
128 if(sandbox){
129 // configure the loader assuming the dojo loader; of course the injected boot(s) can override this config
130 config= {
131 paths: paths,
132 // this config uses the dojo loader's scoping features to sandbox the version of dojo used by doh
133 packages: [{
134 name: 'doh',
135 location: '../util/doh',
136 // here's the magic...every time doh asks for a "dojo" module, it gets mapped to a "dohDojo"
137 // module; same goes for dojox/dohDojox since doh uses dojox
138 packageMap: {dojo:"dohDojo", dojox:"dohDojox"}
139 },{
140 // now define the dohDojo package...
141 name: 'dohDojo',
142 location: '../dojo',
143 packageMap: {dojo: "dohDojo", dojox: "dohDojox"}
144 },{
145 // and the dohDojox package...
146 name: 'dohDojox',
147 location: '../dojox',
148 // and dojox uses dojo...that is, dohDojox...which must be mapped to dohDojo in the context of dohDojox
149 packageMap: {dojo: "dohDojo", dojox: "dohDojox"}
150 }],
151
152 // next, we need to preposition a special configuration for dohDojo
153 cache: {
154 "dohDojo*_base/config": function(){
155 define([], {
156 // this configuration keeps dojo, dijit, and dojox out of the global space
157 scopeMap: [["dojo", "dohDojo"], ["dijit", "dohDijit"], ["dojox", "dohDojox"]],
158 isDebug: true,
159 noGlobals: true
160 });
161 }
162 },
163
164 // control the loader; don't boot global dojo, doh will ask for dojo itself
165 has: {
166 "dojo-sniff": 0,
167 "dojo-loader": 1,
168 "dojo-boot": 0,
169 "dojo-test-sniff": 1
170 },
171
172 // no sniffing; therefore, set the baseUrl
173 baseUrl: "../../dojo",
174
175 deps: ["dohDojo/domReady", "doh"],
176
177 callback: callback,
178
179 async: async
180 };
181 }else{
182 config= {
183 // override non-standard behavior of V1 dojo.js, which sets baseUrl to dojo dir
184 baseUrl: "../..",
185 tlmSiblingOfDojo: false,
186
187 paths: paths,
188 packages: [
189 { name: 'doh', location: 'util/doh' },
190
191 // override non-standard behavior of V1 dojo.js, which remaps these packages
192 'dojo',
193 'dijit',
194 'dojox'
195 ],
196 deps: ["dojo/domReady", "doh/main"],
197 callback: callback,
198 async: async,
199 isDebug: 1
200 };
201 }
202
203 for (var i = 0; i < packages.length; i++) {
204 var isFound = false;
205 for (var j = 0; j < config.packages.length; j++) {
206 if (packages[i].name == config.packages[j].name) {
207 isFound = true;
208 config.packages[j].location = packages[i].location;
209 break;
210 }
211 }
212 if (!isFound) {
213 config.packages.push(packages[i]);
214 }
215 }
216
217 function callback(domReady, doh){
218 domReady(function(){
219 var amdTests = [], module;
220 doh._fixHeight();
221 doh.breakOnError= breakOnError;
222 for (var i = 0, l = test.length; i < l; i++) {
223 module = test[i];
224 if(/\.html$/.test(module)){
225 doh.register(module, require.toUrl(module), 999999);
226 }else{
227 amdTests.push(module);
228 }
229 }
230 require(amdTests, function(){
231 doh.run();
232 });
233 });
234 }
235
236 // load all of the dohPlugins
237 if(dohPlugins){
238 var i = 0;
239 for(i = 0; i < dohPlugins.length; i++){
240 config.deps.push(dohPlugins[i]);
241 }
242 }
243
244 require = config;
245
246 // now script inject any boots
247 for(var e, i = 0; i < boot.length; i++) {
248 if(boot[i]){
249 e = document.createElement("script");
250 e.type = "text/javascript";
251 e.src = boot[i];
252 e.charset = "utf-8";
253 document.getElementsByTagName("head")[0].appendChild(e);
254 }
255 }
256 })();