Changeset 6982
- Timestamp:
- 01/04/07 15:49:58 (2 years ago)
- Location:
- trunk/src
- Files:
-
- 2 modified
-
bootstrap1.js (modified) (12 diffs)
-
loader.js (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bootstrap1.js
r6959 r6982 36 36 // 'dojo' variable exists. 37 37 // note: 38 // Setting any of these variables *after* the library has loaded does nothing at all. 39 // TODOC: is this still true? Release notes for 0.3 indicated they could be set after load. 40 // 38 // Setting any of these variables *after* the library has loaded does 39 // nothing at all. 41 40 42 41 … … 110 109 } 111 110 112 dojo.evalProp = function(/*String*/ name, /*Object*/ object, /*Boolean?*/ create){ 113 // summary: Returns 'object[name]'. If not defined and 'create' is true, will return a new Object. 111 dojo.getObject = function(/*String*/name, /*Object*/obj, /*Boolean*/create, /*Boolean*/returnWrapper){ 112 // summary: 113 // gets an object from a dot-separated string, such as "A.B.C" 114 // description: 115 // useful for longer api chains where you have to test each object in 116 // the chain 117 // name: 118 // Path to an object, in the form "A.B.C". 119 // obj: 120 // Optional. Object to use as root of path. Defaults to 121 // 'dojo.global()'. Null may be passed. 122 // create: 123 // Optional. If true, Objects will be created at any point along the 124 // 'path' that is undefined. 125 // returnWrapper: 126 // Optional. Returns an object with two properties, 'obj' and 'prop'. 127 // 'obj[prop]' is the reference indicated by 'name'. 128 var tobj, tprop; 129 if(typeof name != "string"){ 130 // clearly an error 131 // FIXME: why is this here? 132 return undefined; // Undefined 133 } 134 tobj = obj; 135 if(!tobj){ tobj = dojo.global(); } 136 var parts=name.split("."), i=0, lobj; 137 do{ 138 lobj = tobj; 139 tobj = tobj[parts[i++]]; 140 }while(i<parts.length && tobj); 141 tprop = tobj; 142 tobj = lobj; 143 return (returnWrapper) ? { obj: tobj, prop: tprop } : tprop; // Object 144 } 145 146 dojo.exists = function(/*String*/name, /*Object*/obj){ 147 // summary: 148 // determine if an object supports a given method 149 // description: 150 // useful for longer api chains where you have to test each object in 151 // the chain 152 // name: 153 // Path to an object, in the form "A.B.C". 154 // obj: 155 // Optional. Object to use as root of path. Defaults to 156 // 'dojo.global()'. Null may be passed. 157 if(typeof obj == "string"){ 158 // back-compat, should be removed at some point 159 dojo.deprecated("dojo.exists(obj, name)", "use dojo.exists(name, obj, /*optional*/create)", "0.6"); 160 // swap them 161 var tmp = name; 162 name = obj; 163 obj = tmp; 164 } 165 return (!!dojo.getObject(name, obj)); // Boolean 166 } 167 168 dojo.evalProp = function(/*String*/name, /*Object*/object, /*Boolean?*/create){ 169 // summary: 170 // DEPRECATED. Returns 'object[name]'. If not defined and 'create' is 171 // true, will return a new Object. 114 172 // description: 115 173 // Returns null if 'object[name]' is not defined and 'create' is not true. 116 174 // Note: 'defined' and 'exists' are not the same concept. 117 if((!object)||(!name)){ return undefined; }// undefined 118 if(!dj_undef(name, object)){ return object[name]; }// mixed 119 return (create ? (object[name]={}) : undefined); // mixed 175 dojo.deprecated("dojo.evalProp", "just use hash syntax. Sheesh.", "0.6"); 176 return object[name] || (create ? (object[name]={}) : undefined); // mixed 120 177 } 121 178 122 179 dojo.parseObjPath = function(/*String*/ path, /*Object?*/ context, /*Boolean?*/ create){ 123 // summary: Parse string path to an object, and return corresponding object reference and property name. 180 // summary: 181 // DEPRECATED. Parse string path to an object, and return 182 // corresponding object reference and property name. 124 183 // description: 125 184 // Returns an object with two properties, 'obj' and 'prop'. … … 127 186 // path: Path to an object, in the form "A.B.C". 128 187 // context: Object to use as root of path. Defaults to 'dojo.global()'. 129 // create: If true, Objects will be created at any point along the 'path' that is undefined. 130 var object = (context || dojo.global()); 131 var names = path.split('.'); 132 var prop = names.pop(); 133 for(var i=0,l=names.length;i<l && object;i++){ 134 object = dojo.evalProp(names[i], object, create); 135 } 136 return {obj: object, prop: prop}; // Object: {obj: Object, prop: String} 188 // create: 189 // If true, Objects will be created at any point along the 'path' that 190 // is undefined. 191 dojo.deprecated("dojo.parseObjPath", "use dojo.getObject(path, context, create, true)", "0.6"); 192 return dojo.getObject(path, context, create, true); // Object: {obj: Object, prop: String} 137 193 } 138 194 139 195 dojo.evalObjPath = function(/*String*/ path, /*Boolean?*/ create){ 140 // summary: Return the value of object at 'path' in the global scope, without using 'eval()'. 196 // summary: 197 // DEPRECATED. Return the value of object at 'path' in the global 198 // scope, without using 'eval()'. 141 199 // path: Path to an object, in the form "A.B.C". 142 // create: If true, Objects will be created at any point along the 'path' that is undefined. 143 if(typeof path != "string"){ 144 return dojo.global(); 145 } 146 // fast path for no periods 147 if(path.indexOf('.') == -1){ 148 return dojo.evalProp(path, dojo.global(), create); // mixed 149 } 150 151 //MOW: old 'with' syntax was confusing and would throw an error if parseObjPath returned null. 152 var ref = dojo.parseObjPath(path, dojo.global(), create); 153 if(ref){ 154 return dojo.evalProp(ref.prop, ref.obj, create); // mixed 155 } 156 return null; 200 // create: 201 // If true, Objects will be created at any point along the 'path' that 202 // is undefined. 203 dojo.deprecated("dojo.evalObjPath", "use dojo.getObject(path, null, create)", "0.6"); 204 return dojo.getObject(path, null, create); // Object 157 205 } 158 206 … … 162 210 // TODO: overriding Error.prototype.toString won't accomplish this? 163 211 // ... since natively generated Error objects do not always reflect such things? 212 /* 164 213 if(!dj_undef("message", exception)){ 165 214 return exception.message; // String … … 169 218 return exception; // Error 170 219 } 220 */ 221 return (exception["message"]||exception["description"]||exception); 171 222 } 172 223 173 224 dojo.raise = function(/*String*/ message, /*Error?*/ exception){ 174 // summary: Common point for raising exceptions in Dojo to enable logging. 175 // Throws an error message with text of 'exception' if provided, or 176 // rethrows exception object. 225 // summary: 226 // Common point for raising exceptions in Dojo to enable logging. 227 // Throws an error message with text of 'exception' if provided, or 228 // rethrows exception object. 177 229 178 230 if(exception){ … … 204 256 205 257 function dj_eval(/*String*/ scriptFragment){ 206 // summary: Perform an evaluation in the global scope. Use this rather than calling 'eval()' directly. 207 // description: Placed in a separate function to minimize size of trapped evaluation context. 258 // summary: 259 // Perform an evaluation in the global scope. Use this rather than 260 // calling 'eval()' directly. 261 // description: 262 // Placed in a separate function to minimize size of trapped 263 // evaluation context. 208 264 // note: 209 265 // - JSC eval() takes an optional second argument which can be 'unsafe'. … … 222 278 223 279 dojo.deprecated = function(/*String*/ behaviour, /*String?*/ extra, /*String?*/ removal){ 224 // summary: Log a debug message to indicate that a behavior has been deprecated. 280 // summary: 281 // Log a debug message to indicate that a behavior has been 282 // deprecated. 225 283 // extra: Text to append to the message. 226 // removal: Text to indicate when in the future the behavior will be removed. 284 // removal: 285 // Text to indicate when in the future the behavior will be removed. 227 286 var message = "DEPRECATED: " + behaviour; 228 287 if(extra){ message += " " + extra; } … … 232 291 233 292 dojo.render = (function(){ 234 //TODOC: HOW TO DOC THIS? 235 // summary: Details rendering support, OS and browser of the current environment. 236 // TODOC: is this something many folks will interact with? If so, we should doc the structure created... 293 // summary: 294 // Builds the dojo.render object which details rendering support, OS 295 // and browser of the current environment. 296 // description: 297 // commonly used properties of dojo.render (in HTML environments) 298 // include: 299 // 300 // dojo.render.html.ie 301 // dojo.render.html.opera 302 // dojo.render.html.khtml 303 // dojo.render.html.safari 304 // dojo.render.html.moz 305 // dojo.render.html.mozilla 306 // 307 // additional objects are provided to detail support for other types 308 // of media and environments. For instance, the following determines 309 // if there's native SVG support in a browser: 310 // 311 // if(dojo.render.svg.capable && dojo.render.svg.builtin){ 312 // ... 313 // } 314 // 315 // Other properties of note: 316 // 317 // dojo.render.os.win 318 // dojo.render.os.osx 319 // dojo.render.os.linux 320 // dojo.render.html.UA (navigator.userAgent) 321 // dojo.render.html.AV (navigator.appVersion) 322 // dojo.render.html.ie50 (MSIE 5.0) 323 // dojo.render.html.ie55 (MSIE 5.5) 324 // dojo.render.html.ie60 (MSIE 6.0) 325 // dojo.render.html.ie70 (MSIE 7.0) 326 // 327 // All reasonable measures are taken to ensure that the values in 328 // dojo.render represent the real environment and not, say, a browser 329 // "masquerading" as a different browser version. Only supported 330 // environments and browsers will likely have entires in dojo.render. 237 331 function vscaffold(prefs, names){ 238 332 var tmp = { … … 276 370 dojo.hostenv = (function(){ 277 371 // TODOC: HOW TO DOC THIS? 278 // summary: Provides encapsulation of behavior that changes across different 'host environments' 279 // (different browsers, server via Rhino, etc). 280 // description: None of these methods should ever be called directly by library users. 281 // Use public methods such as 'loadModule' instead. 372 // summary: 373 // Provides encapsulation of behavior that changes across different 374 // 'host environments' (different browsers, server via Rhino, etc). 375 // description: 376 // None of these methods should ever be called directly by library 377 // users. Use public methods such as 'loadModule' instead. 282 378 283 379 // default configuration options … … 323 419 324 420 getText: function(/*String*/ uri){ 325 // summary: Read the plain/text contents at the specified 'uri'. 326 // description: 327 // If 'getText()' is not implemented, then it is necessary to override 328 // 'loadUri()' with an implementation that doesn't rely on it. 329 421 // summary: 422 // Read the plain/text contents at the specified 'uri'. 423 // description: 424 // If 'getText()' is not implemented, then it is necessary to 425 // override 'loadUri()' with an implementation that doesn't 426 // rely on it. 330 427 dojo.unimplemented('getText', "uri=" + uri); 331 428 } … … 335 432 336 433 dojo.hostenv.getBaseScriptUri = function(){ 337 // summary: Return the base script uri that other scripts are found relative to.338 // TODOC: HUH? This comment means nothing to me. What other scripts? Is this the path to other dojo libraries?434 // summary: 435 // Return the base script uri that other scripts are found relative to. 339 436 // MAYBE: Return the base uri to scripts in the dojo library. ??? 340 437 // return: Empty string or a path ending in '/'. 438 439 440 // TODOC: 441 // HUH? This comment means nothing to me. What other scripts? Is 442 // this the path to other dojo libraries? 341 443 if(djConfig.baseScriptUri.length){ 342 444 return djConfig.baseScriptUri; … … 350 452 dojo.raise("Nothing returned by getLibraryScriptUri(): " + uri); 351 453 } 352 353 // MOW: uri seems to not be actually used. Seems to be hard-coding to djConfig.baseRelativePath... ??? 354 var lastslash = uri.lastIndexOf('/'); // MOW ??? 454 // MOW: 455 // uri seems to not be actually used. Seems to be hard-coding to 456 // djConfig.baseRelativePath... ??? 457 355 458 djConfig.baseScriptUri = djConfig.baseRelativePath; 356 459 return djConfig.baseScriptUri; // String 357 460 } 461 // vim:ai:ts=4:noet:textwidth=80 -
trunk/src/loader.js
r6847 r6982 49 49 loadedUris: [], 50 50 51 //WARNING: This variable is referenced by packages outside of bootstrap: FloatingPane.js and undo/browser.js 51 //WARNING: 52 // This variable is referenced by packages outside of bootstrap: 53 // FloatingPane.js and undo/browser.js 52 54 post_load_: false, 53 55 … … 65 67 66 68 dojo.hostenv.loadPath = function(/*String*/relpath, /*String?*/module, /*Function?*/cb){ 67 // summary: 68 // Load a Javascript module given a relative path 69 // 70 // description: 71 // Loads and interprets the script located at relpath, which is relative to the 72 // script root directory. If the script is found but its interpretation causes 73 // a runtime exception, that exception is not caught by us, so the caller will 74 // see it. We return a true value if and only if the script is found. 75 // 76 // For now, we do not have an implementation of a true search path. We 77 // consider only the single base script uri, as returned by getBaseScriptUri(). 78 // 79 // relpath: A relative path to a script (no leading '/', and typically 80 // ending in '.js'). 81 // module: A module whose existance to check for after loading a path. 82 // Can be used to determine success or failure of the load. 83 // cb: a callback function to pass the result of evaluating the script 69 // summary: 70 // Load a Javascript module given a relative path 71 // 72 // description: 73 // Loads and interprets the script located at relpath, which is 74 // relative to the script root directory. If the script is found but 75 // its interpretation causes a runtime exception, that exception is 76 // not caught by us, so the caller will see it. We return a true 77 // value if and only if the script is found. 78 // 79 // For now, we do not have an implementation of a true search path. 80 // We consider only the single base script uri, as returned by 81 // getBaseScriptUri(). 82 // 83 // relpath: 84 // A relative path to a script (no leading '/', and typically ending 85 // in '.js'). 86 // module: 87 // A module whose existance to check for after loading a path. Can be 88 // used to determine success or failure of the load. 89 // cb: 90 // a callback function to pass the result of evaluating the script 84 91 85 92 var uri; … … 102 109 103 110 dojo.hostenv.loadUri = function(/*String (URL)*/uri, /*Function?*/cb){ 104 // summary: 105 // Loads JavaScript from a URI 106 // 107 // description: 108 // Reads the contents of the URI, and evaluates the contents. This is used to load modules as well 109 // as resource bundles. Returns true if it succeeded. Returns false if the URI reading failed. 110 // Throws if the evaluation throws. 111 // 112 // uri: a uri which points at the script to be loaded 113 // cb: a callback function to process the result of evaluating the script as an expression, typically 114 // used by the resource bundle loader to load JSON-style resources 111 // summary: 112 // Loads JavaScript from a URI 113 // description: 114 // Reads the contents of the URI, and evaluates the contents. This is 115 // used to load modules as well as resource bundles. Returns true if 116 // it succeeded. Returns false if the URI reading failed. Throws if 117 // the evaluation throws. 118 // uri: a uri which points at the script to be loaded 119 // cb: 120 // a callback function to process the result of evaluating the script 121 // as an expression, typically used by the resource bundle loader to 122 // load JSON-style resources 115 123 116 124 if(this.loadedUris[uri]){ … … 196 204 197 205 dojo.addOnUnload = function(/*Object?*/obj, /*String|Function?*/functionName){ 198 // summary: registers a function to be triggered when the page unloads 199 // 200 // usage: 201 // dojo.addOnLoad(functionPointer) 202 // dojo.addOnLoad(object, "functionName") 206 // summary: registers a function to be triggered when the page unloads 207 // usage: 208 // dojo.addOnLoad(functionPointer) 209 // dojo.addOnLoad(object, "functionName") 203 210 var dh = dojo.hostenv; 204 211 if(arguments.length == 1){ … … 231 238 232 239 dojo.hostenv.getModuleSymbols = function(/*String*/modulename){ 233 // summary: 234 // Converts a module name in dotted JS notation to an array representing the path in the source tree 240 // summary: 241 // Converts a module name in dotted JS notation to an array 242 // representing the path in the source tree 235 243 var syms = modulename.split("."); 236 244 for(var i = syms.length; i>0; i--){ … … 251 259 252 260 dojo.hostenv._global_omit_module_check = false; 253 dojo.hostenv.loadModule = function(/*String*/moduleName, /*Boolean?*/exactOnly, /*Boolean?*/omitModuleCheck){ 254 // summary: 255 // loads a Javascript module from the appropriate URI 256 // 257 // description: 258 // loadModule("A.B") first checks to see if symbol A.B is defined. 259 // If it is, it is simply returned (nothing to do). 260 // 261 // If it is not defined, it will look for "A/B.js" in the script root directory, 262 // followed by "A.js". 263 // 264 // It throws if it cannot find a file to load, or if the symbol A.B is not 265 // defined after loading. 266 // 267 // It returns the object A.B. 268 // 269 // This does nothing about importing symbols into the current package. 270 // It is presumed that the caller will take care of that. For example, to import 271 // all symbols: 272 // 273 // with (dojo.hostenv.loadModule("A.B")) { 274 // ... 275 // } 276 // 277 // And to import just the leaf symbol: 278 // 279 // var B = dojo.hostenv.loadModule("A.B"); 280 // ... 281 // 282 // dj_load is an alias for dojo.hostenv.loadModule 261 262 dojo.hostenv.loadModule = function( /*String*/moduleName, 263 /*Boolean?*/exactOnly, 264 /*Boolean?*/omitModuleCheck){ 265 // summary: 266 // loads a Javascript module from the appropriate URI 267 // description: 268 // loadModule("A.B") first checks to see if symbol A.B is defined. If 269 // it is, it is simply returned (nothing to do). 270 // 271 // If it is not defined, it will look for "A/B.js" in the script root 272 // directory, followed by "A.js". 273 // 274 // It throws if it cannot find a file to load, or if the symbol A.B is 275 // not defined after loading. 276 // 277 // It returns the object A.B. 278 // 279 // This does nothing about importing symbols into the current package. 280 // It is presumed that the caller will take care of that. For example, 281 // to import all symbols: 282 // 283 // with (dojo.hostenv.loadModule("A.B")) { 284 // ... 285 // } 286 // 287 // And to import just the leaf symbol: 288 // 289 // var B = dojo.hostenv.loadModule("A.B"); 290 // ... 291 // 292 // dj_load is an alias for dojo.hostenv.loadModule 283 293 284 294 if(!moduleName){ return; } … … 368 378 369 379 dojo.hostenv.startPackage = function(/*String*/packageName){ 370 // summary:371 //Creates a JavaScript package372 // 373 // description: 374 // startPackage("A.B") follows the path, and at each level creates a new empty 375 // object or uses what already exists. It returns theresult.376 // 377 // packageName:the package to be created as a String in dot notation380 // summary: 381 // Creates a JavaScript package 382 // description: 383 // startPackage("A.B") follows the path, and at each level creates a 384 // new empty object or uses what already exists. It returns the 385 // result. 386 // packageName: 387 // the package to be created as a String in dot notation 378 388 379 389 //Make sure we have a string. … … 394 404 395 405 dojo.hostenv.findModule = function(/*String*/moduleName, /*Boolean?*/mustExist){ 396 // summary: 397 // Returns the Object representing the module, if it exists, otherwise null. 398 // 399 // moduleName A fully qualified module including package name, like 'A.B'. 400 // mustExist Optional, default false. throw instead of returning null 401 // if the module does not currently exist. 406 // summary: 407 // Returns the Object representing the module, if it exists, otherwise 408 // null. 409 // moduleName: 410 // A fully qualified module including package name, like 'A.B'. 411 // mustExist: 412 // Optional, default false. throw instead of returning null if the 413 // module does not currently exist. 402 414 403 415 var lmn = String(moduleName); … … 416 428 417 429 dojo.kwCompoundRequire = function(/*Object containing Arrays*/modMap){ 418 // description: 419 // This method taks a "map" of arrays which one can use to optionally load dojo 420 // modules. The map is indexed by the possible dojo.hostenv.name_ values, with 421 // two additional values: "default" and "common". The items in the "default" 422 // array will be loaded if none of the other items have been choosen based on 423 // the hostenv.name_ item. The items in the "common" array will _always_ be 424 // loaded, regardless of which list is chosen. Here's how it's normally 425 // called: 426 // 427 // dojo.kwCompoundRequire({ 428 // browser: [ 429 // ["foo.bar.baz", true, true], // an example that passes multiple args to loadModule() 430 // "foo.sample.*", 431 // "foo.test, 432 // ], 433 // default: [ "foo.sample.*" ], 434 // common: [ "really.important.module.*" ] 435 // }); 430 // description: 431 // This method taks a "map" of arrays which one can use to optionally 432 // load dojo modules. The map is indexed by the possible 433 // dojo.hostenv.name_ values, with two additional values: "default" 434 // and "common". The items in the "default" array will be loaded if 435 // none of the other items have been choosen based on the 436 // hostenv.name_ item. The items in the "common" array will _always_ 437 // be loaded, regardless of which list is chosen. Here's how it's 438 // normally called: 439 // 440 // dojo.kwCompoundRequire({ 441 // // an example that passes multiple args to loadModule() 442 // browser: [ 443 // ["foo.bar.baz", true, true], 444 // "foo.sample.*", 445 // "foo.test, 446 // ], 447 // default: [ "foo.sample.*" ], 448 // common: [ "really.important.module.*" ] 449 // }); 436 450 437 451 var common = modMap["common"]||[]; … … 449 463 450 464 dojo.require = function(/*String*/ resourceName){ 451 // summary 452 // Ensure that the given resource (ie, javascript 453 // source file) has been loaded. 454 // description 455 // dojo.require() is similar to C's #include command or java's "import" command. 456 // You call dojo.require() to pull in the resources (ie, javascript source files) 457 // that define the functions you are using. 465 // summary: 466 // Ensure that the given resource (ie, javascript source file) has 467 // been loaded. 468 // description: 469 // dojo.require() is similar to C's #include command or java's 470 // "import" command. You call dojo.require() to pull in the resources 471 // (ie, javascript source files) that define the functions you are 472 // using. 458 473 // 459 // Note that in the case of a build, many resources have already been included 460 // into dojo.js (ie, many of the javascript source files have been compressed and 461 // concatened into dojo.js), so many dojo.require() calls will simply return 462 // without downloading anything. 474 // Note that in the case of a build, many resources have already been 475 // included into dojo.js (ie, many of the javascript source files have 476 // been compressed and concatened into dojo.js), so many