bootstrap1_wev8.js
18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/*
Copyright (c) 2004-2005, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
/**
* @file bootstrap1.js
*
* bootstrap file that runs before hostenv_*.js file.
*
* @author Copyright 2004 Mark D. Anderson (mda@discerning.com)
* @author Licensed under the Academic Free License 2.1 http://www.opensource.org/licenses/afl-2.1.php
*
* $Id: bootstrap1_wev8.js 2555 2005-12-20 00:26:24Z alex $
*/
/**
* The global djConfig can be set prior to loading the library, to override
* certain settings. It does not exist under dojo.* so that it can be set
* before the dojo variable exists. Setting any of these variables *after* the
* library has loaded does nothing at all. The variables that can be set are
* as follows:
*/
/**
* dj_global is an alias for the top-level global object in the host
* environment (the "window" object in a browser).
*/
var dj_global = this; //typeof window == 'undefined' ? this : window;
function dj_undef(name, obj){
if(!obj){ obj = dj_global; }
return (typeof obj[name] == "undefined");
}
if(dj_undef("djConfig")){
var djConfig = {};
}
/**
* dojo is the root variable of (almost all) our public symbols.
*/
var dojo;
if(dj_undef("dojo")){ dojo = {}; }
dojo.version = {
major: 0, minor: 2, patch: 1, flag: "",
revision: Number("$Rev: 2555 $".match(/[0-9]+/)[0]),
toString: function() {
with (dojo.version) {
return major + "." + minor + "." + patch + flag + " (" + revision + ")";
}
}
};
/*
* evaluate a string like "A.B" without using eval.
*/
dojo.evalObjPath = function(objpath, create){
// fast path for no periods
if(typeof objpath != "string"){ return dj_global; }
if(objpath.indexOf('.') == -1){
if((dj_undef(objpath, dj_global))&&(create)){
dj_global[objpath] = {};
}
return dj_global[objpath];
}
var syms = objpath.split(/\./);
var obj = dj_global;
for(var i=0;i<syms.length;++i){
if(!create){
obj = obj[syms[i]];
if((typeof obj == 'undefined')||(!obj)){
return obj;
}
}else{
if(dj_undef(syms[i], obj)){
obj[syms[i]] = {};
}
obj = obj[syms[i]];
}
}
return obj;
};
// ****************************************************************
// global public utils
// ****************************************************************
/*
* utility to print an Error.
* TODO: overriding Error.prototype.toString won't accomplish this?
* ... since natively generated Error objects do not always reflect such things?
*/
dojo.errorToString = function(excep){
return ((!dj_undef("message", excep)) ? excep.message : (dj_undef("description", excep) ? excep : excep.description ));
};
/**
* Throws an Error object given the string err. For now, will also do a println
* to the user first.
*/
dojo.raise = function(message, excep){
if(excep){
message = message + ": "+dojo.errorToString(excep);
}
var he = dojo.hostenv;
if((!dj_undef("hostenv", dojo))&&(!dj_undef("println", dojo.hostenv))){
dojo.hostenv.println("FATAL: " + message);
}
throw Error(message);
};
dj_throw = dj_rethrow = function(m, e){
dojo.deprecated("dj_throw and dj_rethrow deprecated, use dojo.raise instead");
dojo.raise(m, e);
};
/**
* Produce a line of debug output.
* Does nothing unless djConfig.isDebug is true.
* varargs, joined with ''.
* Caller should not supply a trailing "\n".
*/
dojo.debug = function(){
if (!djConfig.isDebug) { return; }
var args = arguments;
if(dj_undef("println", dojo.hostenv)){
dojo.raise("dojo.debug not available (yet?)");
}
var isJUM = dj_global["jum"] && !dj_global["jum"].isBrowser;
var s = [(isJUM ? "": "DEBUG: ")];
for(var i=0;i<args.length;++i){
if(!false && args[i] instanceof Error){
var msg = "[" + args[i].name + ": " + dojo.errorToString(args[i]) +
(args[i].fileName ? ", file: " + args[i].fileName : "") +
(args[i].lineNumber ? ", line: " + args[i].lineNumber : "") + "]";
} else {
try {
var msg = String(args[i]);
} catch(e) {
if(dojo.render.html.ie) {
var msg = "[ActiveXObject]";
} else {
var msg = "[unknown]";
}
}
}
s.push(msg);
}
if(isJUM){ // this seems to be the only way to get JUM to "play nice"
jum.debug(s.join(" "));
}else{
dojo.hostenv.println(s.join(" "));
}
}
/**
* this is really hacky for now - just
* display the properties of the object
**/
dojo.debugShallow = function(obj){
if (!djConfig.isDebug) { return; }
dojo.debug('------------------------------------------------------------');
dojo.debug('Object: '+obj);
for(i in obj){
dojo.debug(i + ': ' + obj[i]);
}
dojo.debug('------------------------------------------------------------');
}
var dj_debug = dojo.debug;
/**
* We put eval() in this separate function to keep down the size of the trapped
* evaluation context.
*
* Note that:
* - JSC eval() takes an optional second argument which can be 'unsafe'.
* - Mozilla/SpiderMonkey eval() takes an optional second argument which is the
* scope object for new symbols.
*/
function dj_eval(s){ return dj_global.eval ? dj_global.eval(s) : eval(s); }
/**
* Convenience for throwing an exception because some function is not
* implemented.
*/
dj_unimplemented = dojo.unimplemented = function(funcname, extra){
// FIXME: need to move this away from dj_*
var mess = "'" + funcname + "' not implemented";
if((!dj_undef(extra))&&(extra)){ mess += " " + extra; }
dojo.raise(mess);
}
/**
* Convenience for informing of deprecated behaviour.
*/
dj_deprecated = dojo.deprecated = function(behaviour, extra, removal){
var mess = "DEPRECATED: " + behaviour;
if(extra){ mess += " " + extra; }
if(removal){ mess += " -- will be removed in version: " + removal; }
dojo.debug(mess);
}
/**
* Does inheritance
*/
dojo.inherits = function(subclass, superclass){
if(typeof superclass != 'function'){
dojo.raise("superclass: "+superclass+" borken");
}
subclass.prototype = new superclass();
subclass.prototype.constructor = subclass;
subclass.superclass = superclass.prototype;
// DEPRICATED: super is a reserved word, use 'superclass'
subclass['super'] = superclass.prototype;
}
dj_inherits = function(subclass, superclass){
dojo.deprecated("dj_inherits deprecated, use dojo.inherits instead");
dojo.inherits(subclass, superclass);
}
// an object that authors use determine what host we are running under
dojo.render = (function(){
function vscaffold(prefs, names){
var tmp = {
capable: false,
support: {
builtin: false,
plugin: false
},
prefixes: prefs
};
for(var x in names){
tmp[x] = false;
}
return tmp;
}
return {
name: "",
ver: dojo.version,
os: { win: false, linux: false, osx: false },
html: vscaffold(["html"], ["ie", "opera", "khtml", "safari", "moz"]),
svg: vscaffold(["svg"], ["corel", "adobe", "batik"]),
vml: vscaffold(["vml"], ["ie"]),
swf: vscaffold(["Swf", "Flash", "Mm"], ["mm"]),
swt: vscaffold(["Swt"], ["ibm"])
};
})();
// ****************************************************************
// dojo.hostenv methods that must be defined in hostenv_*.js
// ****************************************************************
/**
* The interface definining the interaction with the EcmaScript host environment.
*/
/*
* None of these methods should ever be called directly by library users.
* Instead public methods such as loadModule should be called instead.
*/
dojo.hostenv = (function(){
// default configuration options
var config = {
isDebug: false,
allowQueryConfig: false,
baseScriptUri: "",
baseRelativePath: "",
libraryScriptUri: "",
iePreventClobber: false,
ieClobberMinimal: true,
preventBackButtonFix: true,
searchIds: [],
parseWidgets: true
};
if (typeof djConfig == "undefined") { djConfig = config; }
else {
for (var option in config) {
if (typeof djConfig[option] == "undefined") {
djConfig[option] = config[option];
}
}
}
var djc = djConfig;
function _def(obj, name, def){
return (dj_undef(name, obj) ? def : obj[name]);
}
return {
name_: '(unset)',
version_: '(unset)',
pkgFileName: "__package__",
// for recursion protection
loading_modules_: {},
loaded_modules_: {},
addedToLoadingCount: [],
removedFromLoadingCount: [],
inFlightCount: 0,
modulePrefixes_: {
dojo: {name: "dojo", value: "src"}
},
setModulePrefix: function(module, prefix){
this.modulePrefixes_[module] = {name: module, value: prefix};
},
getModulePrefix: function(module){
var mp = this.modulePrefixes_;
if((mp[module])&&(mp[module]["name"])){
return mp[module].value;
}
return module;
},
getTextStack: [],
loadUriStack: [],
loadedUris: [],
// lookup cache for modules.
// NOTE: this is partially redundant a private variable in the jsdown
// implementation, but we don't want to couple the two.
// modules_ : {},
post_load_: false,
modulesLoadedListeners: [],
/**
* Return the name of the hostenv.
*/
getName: function(){ return this.name_; },
/**
* Return the version of the hostenv.
*/
getVersion: function(){ return this.version_; },
/**
* Read the plain/text contents at the specified uri. If getText() is
* not implemented, then it is necessary to override loadUri() with an
* implementation that doesn't rely on it.
*/
getText: function(uri){
dojo.unimplemented('getText', "uri=" + uri);
},
/**
* return the uri of the script that defined this function
* private method that must be implemented by the hostenv.
*/
getLibraryScriptUri: function(){
// FIXME: need to implement!!!
dojo.unimplemented('getLibraryScriptUri','');
}
};
})();
/**
* Display a line of text to the user.
* The line argument should not contain a trailing "\n"; that is added by the
* implementation.
*/
//dojo.hostenv.println = function(line) {}
// ****************************************************************
// dojo.hostenv methods not defined in hostenv_*.js
// ****************************************************************
/**
* Return the base script uri that other scripts are found relative to.
* It is either the empty string, or a non-empty string ending in '/'.
*/
dojo.hostenv.getBaseScriptUri = function(){
if(djConfig.baseScriptUri.length){
return djConfig.baseScriptUri;
}
var uri = new String(djConfig.libraryScriptUri||djConfig.baseRelativePath);
if (!uri) { dojo.raise("Nothing returned by getLibraryScriptUri(): " + uri); }
var lastslash = uri.lastIndexOf('/');
djConfig.baseScriptUri = djConfig.baseRelativePath;
return djConfig.baseScriptUri;
}
/**
* Set the base script uri.
*/
// In JScript .NET, see interface System._AppDomain implemented by
// System.AppDomain.CurrentDomain. Members include AppendPrivatePath,
// RelativeSearchPath, BaseDirectory.
dojo.hostenv.setBaseScriptUri = function(uri){ djConfig.baseScriptUri = uri }
/**
* Loads and interprets the script located at relpath, which is relative to the
* script root directory. If the script is found but its interpretation causes
* a runtime exception, that exception is not caught by us, so the caller will
* see it. We return a true value if and only if the script is found.
*
* For now, we do not have an implementation of a true search path. We
* consider only the single base script uri, as returned by getBaseScriptUri().
*
* @param relpath A relative path to a script (no leading '/', and typically
* ending in '.js').
* @param module A module whose existance to check for after loading a path.
* Can be used to determine success or failure of the load.
*/
dojo.hostenv.loadPath = function(relpath, module /*optional*/, cb /*optional*/){
if((relpath.charAt(0) == '/')||(relpath.match(/^\w+:/))){
dojo.raise("relpath '" + relpath + "'; must be relative");
}
var uri = this.getBaseScriptUri() + relpath;
if(djConfig.cacheBust && dojo.render.html.capable) { uri += "?" + djConfig.cacheBust.replace(/\W+/g,""); }
try{
return ((!module) ? this.loadUri(uri, cb) : this.loadUriAndCheck(uri, module, cb));
}catch(e){
dojo.debug(e);
return false;
}
}
/**
* Reads the contents of the URI, and evaluates the contents.
* Returns true if it succeeded. Returns false if the URI reading failed.
* Throws if the evaluation throws.
* The result of the eval is not available to the caller.
*/
dojo.hostenv.loadUri = function(uri, cb){
if(dojo.hostenv.loadedUris[uri]){
return;
}
var contents = this.getText(uri, null, true);
if(contents == null){ return 0; }
var value = dj_eval(contents);
return 1;
}
// FIXME: probably need to add logging to this method
dojo.hostenv.loadUriAndCheck = function(uri, module, cb){
var ok = true;
try{
ok = this.loadUri(uri, cb);
}catch(e){
dojo.debug("failed loading ", uri, " with error: ", e);
}
return ((ok)&&(this.findModule(module, false))) ? true : false;
}
dojo.loaded = function(){ }
dojo.hostenv.loaded = function(){
this.post_load_ = true;
var mll = this.modulesLoadedListeners;
for(var x=0; x<mll.length; x++){
mll[x]();
}
dojo.loaded();
}
/*
Call styles:
dojo.addOnLoad(functionPointer)
dojo.addOnLoad(object, "functionName")
*/
dojo.addOnLoad = function(obj, fcnName) {
if(arguments.length == 1) {
dojo.hostenv.modulesLoadedListeners.push(obj);
} else if(arguments.length > 1) {
dojo.hostenv.modulesLoadedListeners.push(function() {
obj[fcnName]();
});
}
};
dojo.hostenv.modulesLoaded = function(){
if(this.post_load_){ return; }
if((this.loadUriStack.length==0)&&(this.getTextStack.length==0)){
if(this.inFlightCount > 0){
dojo.debug("files still in flight!");
return;
}
if(typeof setTimeout == "object"){
setTimeout("dojo.hostenv.loaded();", 0);
}else{
dojo.hostenv.loaded();
}
}
}
dojo.hostenv.moduleLoaded = function(modulename){
var modref = dojo.evalObjPath((modulename.split(".").slice(0, -1)).join('.'));
this.loaded_modules_[(new String(modulename)).toLowerCase()] = modref;
}
/**
* loadModule("A.B") first checks to see if symbol A.B is defined.
* If it is, it is simply returned (nothing to do).
*
* If it is not defined, it will look for "A/B_wev8.js" in the script root directory,
* followed by "A_wev8.js".
*
* It throws if it cannot find a file to load, or if the symbol A.B is not
* defined after loading.
*
* It returns the object A.B.
*
* This does nothing about importing symbols into the current package.
* It is presumed that the caller will take care of that. For example, to import
* all symbols:
*
* with (dojo.hostenv.loadModule("A.B")) {
* ...
* }
*
* And to import just the leaf symbol:
*
* var B = dojo.hostenv.loadModule("A.B");
* ...
*
* dj_load is an alias for dojo.hostenv.loadModule
*/
dojo.hostenv._global_omit_module_check = false;
dojo.hostenv.loadModule = function(modulename, exact_only, omit_module_check){
omit_module_check = this._global_omit_module_check || omit_module_check;
var module = this.findModule(modulename, false);
if(module){
return module;
}
// protect against infinite recursion from mutual dependencies
if(dj_undef(modulename, this.loading_modules_)){
this.addedToLoadingCount.push(modulename);
}
this.loading_modules_[modulename] = 1;
// convert periods to slashes
var relpath = modulename.replace(/\./g, '/') + '_wev8.js';
var syms = modulename.split(".");
var nsyms = modulename.split(".");
for (var i = syms.length - 1; i > 0; i--) {
var parentModule = syms.slice(0, i).join(".");
var parentModulePath = this.getModulePrefix(parentModule);
if (parentModulePath != parentModule) {
syms.splice(0, i, parentModulePath);
break;
}
}
var last = syms[syms.length - 1];
// figure out if we're looking for a full package, if so, we want to do
// things slightly diffrently
if(last=="*"){
modulename = (nsyms.slice(0, -1)).join('.');
while(syms.length){
syms.pop();
syms.push(this.pkgFileName);
relpath = syms.join("/") + '_wev8.js';
if(relpath.charAt(0)=="/"){
relpath = relpath.slice(1);
}
ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
if(ok){ break; }
syms.pop();
}
}else{
relpath = syms.join("/") + '_wev8.js';
modulename = nsyms.join('.');
var ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
if((!ok)&&(!exact_only)){
syms.pop();
while(syms.length){
relpath = syms.join('/') + '_wev8.js';
ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
if(ok){ break; }
syms.pop();
relpath = syms.join('/') + '/'+this.pkgFileName+'_wev8.js';
if(relpath.charAt(0)=="/"){
relpath = relpath.slice(1);
}
ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
if(ok){ break; }
}
}
if((!ok)&&(!omit_module_check)){
dojo.raise("Could not load '" + modulename + "'; last tried '" + relpath + "'");
}
}
// check that the symbol was defined
if(!omit_module_check){
// pass in false so we can give better error
module = this.findModule(modulename, false);
if(!module){
dojo.raise("symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
}
}
return module;
}
/**
* startPackage("A.B") follows the path, and at each level creates a new empty
* object or uses what already exists. It returns the result.
*/
dojo.hostenv.startPackage = function(packname){
var syms = packname.split(/\./);
if(syms[syms.length-1]=="*"){
syms.pop();
}
return dojo.evalObjPath(syms.join("."), true);
}
/**
* findModule("A.B") returns the object A.B if it exists, otherwise null.
* @param modulename A string like 'A.B'.
* @param must_exist Optional, defualt false. throw instead of returning null
* if the module does not currently exist.
*/
dojo.hostenv.findModule = function(modulename, must_exist) {
// check cache
/*
if(!dj_undef(modulename, this.modules_)){
return this.modules_[modulename];
}
*/
if(this.loaded_modules_[(new String(modulename)).toLowerCase()]){
return this.loaded_modules_[modulename];
}
// see if symbol is defined anyway
var module = dojo.evalObjPath(modulename);
if((typeof module !== 'undefined')&&(module)){
return module;
// return this.modules_[modulename] = module;
}
if(must_exist){
dojo.raise("no loaded module named '" + modulename + "'");
}
return null;
}