PageRenderTime 76ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/chytanka/trunk/Text2Audio/web/dojo/dojo.js

https://bitbucket.org/XmlAspect/chytanka
JavaScript | 7439 lines | 5521 code | 768 blank | 1150 comment | 1209 complexity | 555ab7f9262e6782b371f1c4380f582f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. if(typeof dojo == "undefined"){
  2. /**
  3. * @file bootstrap1.js
  4. *
  5. * summary: First file that is loaded that 'bootstraps' the entire dojo library suite.
  6. * note: Must run before hostenv_*.js file.
  7. *
  8. * @author Copyright 2004 Mark D. Anderson (mda@discerning.com)
  9. * TODOC: should the copyright be changed to Dojo Foundation?
  10. * @license Licensed under the Academic Free License 2.1 http://www.opensource.org/licenses/afl-2.1.php
  11. *
  12. * $Id: bootstrap1.js 4342 2006-06-11 23:03:30Z alex $
  13. */
  14. // TODOC: HOW TO DOC THE BELOW?
  15. // @global: djConfig
  16. // summary:
  17. // Application code can set the global 'djConfig' prior to loading
  18. // the library to override certain global settings for how dojo works.
  19. // description: The variables that can be set are as follows:
  20. // - isDebug: false
  21. // - allowQueryConfig: false
  22. // - baseScriptUri: ""
  23. // - baseRelativePath: ""
  24. // - libraryScriptUri: ""
  25. // - iePreventClobber: false
  26. // - ieClobberMinimal: true
  27. // - preventBackButtonFix: true
  28. // - searchIds: []
  29. // - parseWidgets: true
  30. // TODOC: HOW TO DOC THESE VARIABLES?
  31. // TODOC: IS THIS A COMPLETE LIST?
  32. // note:
  33. // 'djConfig' does not exist under 'dojo.*' so that it can be set before the
  34. // 'dojo' variable exists.
  35. // note:
  36. // Setting any of these variables *after* the library has loaded does nothing at all.
  37. // TODOC: is this still true? Release notes for 0.3 indicated they could be set after load.
  38. //
  39. //TODOC: HOW TO DOC THIS?
  40. // @global: dj_global
  41. // summary:
  42. // an alias for the top-level global object in the host environment
  43. // (e.g., the window object in a browser).
  44. // description:
  45. // Refer to 'dj_global' rather than referring to window to ensure your
  46. // code runs correctly in contexts other than web browsers (eg: Rhino on a server).
  47. var dj_global = this;
  48. function dj_undef(/*String*/ name, /*Object?*/ object){
  49. //summary: Returns true if 'name' is defined on 'object' (or globally if 'object' is null).
  50. //description: Note that 'defined' and 'exists' are not the same concept.
  51. if(object==null){ object = dj_global; }
  52. // exception if object is not an Object
  53. return (typeof object[name] == "undefined"); // Boolean
  54. }
  55. // make sure djConfig is defined
  56. if(dj_undef("djConfig")){
  57. var djConfig = {};
  58. }
  59. //TODOC: HOW TO DOC THIS?
  60. // dojo is the root variable of (almost all) our public symbols -- make sure it is defined.
  61. if(dj_undef("dojo")){
  62. var dojo = {};
  63. }
  64. //TODOC: HOW TO DOC THIS?
  65. dojo.version = {
  66. // summary: version number of this instance of dojo.
  67. major: 0, minor: 3, patch: 1, flag: "",
  68. revision: Number("$Rev: 4342 $".match(/[0-9]+/)[0]),
  69. toString: function(){
  70. with(dojo.version){
  71. return major + "." + minor + "." + patch + flag + " (" + revision + ")"; // String
  72. }
  73. }
  74. }
  75. dojo.evalProp = function(/*String*/ name, /*Object*/ object, /*Boolean?*/ create){
  76. // summary: Returns 'object[name]'. If not defined and 'create' is true, will return a new Object.
  77. // description:
  78. // Returns null if 'object[name]' is not defined and 'create' is not true.
  79. // Note: 'defined' and 'exists' are not the same concept.
  80. return (object && !dj_undef(name, object) ? object[name] : (create ? (object[name]={}) : undefined)); // mixed
  81. }
  82. dojo.parseObjPath = function(/*String*/ path, /*Object?*/ context, /*Boolean?*/ create){
  83. // summary: Parse string path to an object, and return corresponding object reference and property name.
  84. // description:
  85. // Returns an object with two properties, 'obj' and 'prop'.
  86. // 'obj[prop]' is the reference indicated by 'path'.
  87. // path: Path to an object, in the form "A.B.C".
  88. // context: Object to use as root of path. Defaults to 'dj_global'.
  89. // create: If true, Objects will be created at any point along the 'path' that is undefined.
  90. var object = (context != null ? context : dj_global);
  91. var names = path.split('.');
  92. var prop = names.pop();
  93. for (var i=0,l=names.length;i<l && object;i++){
  94. object = dojo.evalProp(names[i], object, create);
  95. }
  96. return {obj: object, prop: prop}; // Object: {obj: Object, prop: String}
  97. }
  98. dojo.evalObjPath = function(/*String*/ path, /*Boolean?*/ create){
  99. // summary: Return the value of object at 'path' in the global scope, without using 'eval()'.
  100. // path: Path to an object, in the form "A.B.C".
  101. // create: If true, Objects will be created at any point along the 'path' that is undefined.
  102. if(typeof path != "string"){
  103. return dj_global;
  104. }
  105. // fast path for no periods
  106. if(path.indexOf('.') == -1){
  107. return dojo.evalProp(path, dj_global, create); // mixed
  108. }
  109. //MOW: old 'with' syntax was confusing and would throw an error if parseObjPath returned null.
  110. var ref = dojo.parseObjPath(path, dj_global, create);
  111. if(ref){
  112. return dojo.evalProp(ref.prop, ref.obj, create); // mixed
  113. }
  114. return null;
  115. }
  116. // ****************************************************************
  117. // global public utils
  118. // TODOC: DO WE WANT TO NOTE THAT THESE ARE GLOBAL PUBLIC UTILS?
  119. // ****************************************************************
  120. dojo.errorToString = function(/*Error*/ exception){
  121. // summary: Return an exception's 'message', 'description' or text.
  122. // TODO: overriding Error.prototype.toString won't accomplish this?
  123. // ... since natively generated Error objects do not always reflect such things?
  124. if(!dj_undef("message", exception)){
  125. return exception.message; // String
  126. }else if(!dj_undef("description", exception)){
  127. return exception.description; // String
  128. }else{
  129. return exception; // Error
  130. }
  131. }
  132. dojo.raise = function(/*String*/ message, /*Error?*/ exception){
  133. // summary: Throw an error message, appending text of 'exception' if provided.
  134. // note: Also prints a message to the user using 'dojo.hostenv.println'.
  135. if(exception){
  136. message = message + ": "+dojo.errorToString(exception);
  137. }
  138. // print the message to the user if hostenv.println is defined
  139. try { dojo.hostenv.println("FATAL: "+message); } catch (e) {}
  140. throw Error(message);
  141. }
  142. //Stub functions so things don't break.
  143. //TODOC: HOW TO DOC THESE?
  144. dojo.debug = function(){}
  145. dojo.debugShallow = function(obj){}
  146. dojo.profile = { start: function(){}, end: function(){}, stop: function(){}, dump: function(){} };
  147. function dj_eval(/*String*/ scriptFragment){
  148. // summary: Perform an evaluation in the global scope. Use this rather than calling 'eval()' directly.
  149. // description: Placed in a separate function to minimize size of trapped evaluation context.
  150. // note:
  151. // - JSC eval() takes an optional second argument which can be 'unsafe'.
  152. // - Mozilla/SpiderMonkey eval() takes an optional second argument which is the
  153. // scope object for new symbols.
  154. return dj_global.eval ? dj_global.eval(scriptFragment) : eval(scriptFragment); // mixed
  155. }
  156. dojo.unimplemented = function(/*String*/ funcname, /*String?*/ extra){
  157. // summary: Throw an exception because some function is not implemented.
  158. // extra: Text to append to the exception message.
  159. var message = "'" + funcname + "' not implemented";
  160. if (extra != null) { message += " " + extra; }
  161. dojo.raise(message);
  162. }
  163. dojo.deprecated = function(/*String*/ behaviour, /*String?*/ extra, /*String?*/ removal){
  164. // summary: Log a debug message to indicate that a behavior has been deprecated.
  165. // extra: Text to append to the message.
  166. // removal: Text to indicate when in the future the behavior will be removed.
  167. var message = "DEPRECATED: " + behaviour;
  168. if(extra){ message += " " + extra; }
  169. if(removal){ message += " -- will be removed in version: " + removal; }
  170. dojo.debug(message);
  171. }
  172. dojo.inherits = function(/*Function*/ subclass, /*Function*/ superclass){
  173. // summary: Set up inheritance between two classes.
  174. if(typeof superclass != 'function'){
  175. dojo.raise("dojo.inherits: superclass argument ["+superclass+"] must be a function (subclass: [" + subclass + "']");
  176. }
  177. subclass.prototype = new superclass();
  178. subclass.prototype.constructor = subclass;
  179. subclass.superclass = superclass.prototype;
  180. // DEPRICATED: super is a reserved word, use 'superclass'
  181. subclass['super'] = superclass.prototype;
  182. }
  183. dojo.render = (function(){
  184. //TODOC: HOW TO DOC THIS?
  185. // summary: Details rendering support, OS and browser of the current environment.
  186. // TODOC: is this something many folks will interact with? If so, we should doc the structure created...
  187. function vscaffold(prefs, names){
  188. var tmp = {
  189. capable: false,
  190. support: {
  191. builtin: false,
  192. plugin: false
  193. },
  194. prefixes: prefs
  195. };
  196. for(var prop in names){
  197. tmp[prop] = false;
  198. }
  199. return tmp;
  200. }
  201. return {
  202. name: "",
  203. ver: dojo.version,
  204. os: { win: false, linux: false, osx: false },
  205. html: vscaffold(["html"], ["ie", "opera", "khtml", "safari", "moz"]),
  206. svg: vscaffold(["svg"], ["corel", "adobe", "batik"]),
  207. vml: vscaffold(["vml"], ["ie"]),
  208. swf: vscaffold(["Swf", "Flash", "Mm"], ["mm"]),
  209. swt: vscaffold(["Swt"], ["ibm"])
  210. };
  211. })();
  212. // ****************************************************************
  213. // dojo.hostenv methods that must be defined in hostenv_*.js
  214. // ****************************************************************
  215. /**
  216. * The interface definining the interaction with the EcmaScript host environment.
  217. */
  218. /*
  219. * None of these methods should ever be called directly by library users.
  220. * Instead public methods such as loadModule should be called instead.
  221. */
  222. dojo.hostenv = (function(){
  223. // TODOC: HOW TO DOC THIS?
  224. // summary: Provides encapsulation of behavior that changes across different 'host environments'
  225. // (different browsers, server via Rhino, etc).
  226. // description: None of these methods should ever be called directly by library users.
  227. // Use public methods such as 'loadModule' instead.
  228. // default configuration options
  229. var config = {
  230. isDebug: false,
  231. allowQueryConfig: false,
  232. baseScriptUri: "",
  233. baseRelativePath: "",
  234. libraryScriptUri: "",
  235. iePreventClobber: false,
  236. ieClobberMinimal: true,
  237. preventBackButtonFix: true,
  238. searchIds: [],
  239. parseWidgets: true
  240. };
  241. if (typeof djConfig == "undefined") { djConfig = config; }
  242. else {
  243. for (var option in config) {
  244. if (typeof djConfig[option] == "undefined") {
  245. djConfig[option] = config[option];
  246. }
  247. }
  248. }
  249. return {
  250. name_: '(unset)',
  251. version_: '(unset)',
  252. getName: function(){
  253. // sumary: Return the name of the host environment.
  254. return this.name_; // String
  255. },
  256. getVersion: function(){
  257. // summary: Return the version of the hostenv.
  258. return this.version_; // String
  259. },
  260. getText: function(/*String*/ uri){
  261. // summary: Read the plain/text contents at the specified 'uri'.
  262. // description:
  263. // If 'getText()' is not implemented, then it is necessary to override
  264. // 'loadUri()' with an implementation that doesn't rely on it.
  265. dojo.unimplemented('getText', "uri=" + uri);
  266. }
  267. };
  268. })();
  269. dojo.hostenv.getBaseScriptUri = function(){
  270. // summary: Return the base script uri that other scripts are found relative to.
  271. // TODOC: HUH? This comment means nothing to me. What other scripts? Is this the path to other dojo libraries?
  272. // MAYBE: Return the base uri to scripts in the dojo library. ???
  273. // return: Empty string or a path ending in '/'.
  274. if(djConfig.baseScriptUri.length){
  275. return djConfig.baseScriptUri;
  276. }
  277. // MOW: Why not:
  278. // uri = djConfig.libraryScriptUri || djConfig.baseRelativePath
  279. // ??? Why 'new String(...)'
  280. var uri = new String(djConfig.libraryScriptUri||djConfig.baseRelativePath);
  281. if (!uri) { dojo.raise("Nothing returned by getLibraryScriptUri(): " + uri); }
  282. // MOW: uri seems to not be actually used. Seems to be hard-coding to djConfig.baseRelativePath... ???
  283. var lastslash = uri.lastIndexOf('/'); // MOW ???
  284. djConfig.baseScriptUri = djConfig.baseRelativePath;
  285. return djConfig.baseScriptUri; // String
  286. }
  287. /*
  288. * loader.js - runs before the hostenv_*.js file. Contains all of the package loading methods.
  289. */
  290. //A semi-colon is at the start of the line because after doing a build, this function definition
  291. //get compressed onto the same line as the last line in bootstrap1.js. That list line is just a
  292. //curly bracket, and the browser complains about that syntax. The semicolon fixes it. Putting it
  293. //here instead of at the end of bootstrap1.js, since it is more of an issue for this file, (using
  294. //the closure), and bootstrap1.js could change in the future.
  295. ;(function(){
  296. //Additional properties for dojo.hostenv
  297. var _addHostEnv = {
  298. pkgFileName: "__package__",
  299. // for recursion protection
  300. loading_modules_: {},
  301. loaded_modules_: {},
  302. addedToLoadingCount: [],
  303. removedFromLoadingCount: [],
  304. inFlightCount: 0,
  305. // FIXME: it should be possible to pull module prefixes in from djConfig
  306. modulePrefixes_: {
  307. dojo: {name: "dojo", value: "src"}
  308. },
  309. setModulePrefix: function(module, prefix){
  310. this.modulePrefixes_[module] = {name: module, value: prefix};
  311. },
  312. getModulePrefix: function(module){
  313. var mp = this.modulePrefixes_;
  314. if((mp[module])&&(mp[module]["name"])){
  315. return mp[module].value;
  316. }
  317. return module;
  318. },
  319. getTextStack: [],
  320. loadUriStack: [],
  321. loadedUris: [],
  322. //WARNING: This variable is referenced by packages outside of bootstrap: FloatingPane.js and undo/browser.js
  323. post_load_: false,
  324. //Egad! Lots of test files push on this directly instead of using dojo.addOnLoad.
  325. modulesLoadedListeners: [],
  326. unloadListeners: [],
  327. loadNotifying: false
  328. };
  329. //Add all of these properties to dojo.hostenv
  330. for(var param in _addHostEnv){
  331. dojo.hostenv[param] = _addHostEnv[param];
  332. }
  333. })();
  334. /**
  335. * Loads and interprets the script located at relpath, which is relative to the
  336. * script root directory. If the script is found but its interpretation causes
  337. * a runtime exception, that exception is not caught by us, so the caller will
  338. * see it. We return a true value if and only if the script is found.
  339. *
  340. * For now, we do not have an implementation of a true search path. We
  341. * consider only the single base script uri, as returned by getBaseScriptUri().
  342. *
  343. * @param relpath A relative path to a script (no leading '/', and typically
  344. * ending in '.js').
  345. * @param module A module whose existance to check for after loading a path.
  346. * Can be used to determine success or failure of the load.
  347. * @param cb a function to pass the result of evaluating the script (optional)
  348. */
  349. dojo.hostenv.loadPath = function(relpath, module /*optional*/, cb /*optional*/){
  350. var uri;
  351. if((relpath.charAt(0) == '/')||(relpath.match(/^\w+:/))){
  352. // dojo.raise("relpath '" + relpath + "'; must be relative");
  353. uri = relpath;
  354. }else{
  355. uri = this.getBaseScriptUri() + relpath;
  356. }
  357. if(djConfig.cacheBust && dojo.render.html.capable){
  358. uri += "?" + String(djConfig.cacheBust).replace(/\W+/g,"");
  359. }
  360. try{
  361. return ((!module) ? this.loadUri(uri, cb) : this.loadUriAndCheck(uri, module, cb));
  362. }catch(e){
  363. dojo.debug(e);
  364. return false;
  365. }
  366. }
  367. /**
  368. * Reads the contents of the URI, and evaluates the contents.
  369. * Returns true if it succeeded. Returns false if the URI reading failed.
  370. * Throws if the evaluation throws.
  371. * The result of the eval is not available to the caller TODO: now it is; was this a deliberate restriction?
  372. *
  373. * @param uri a uri which points at the script to be loaded
  374. * @param cb a function to process the result of evaluating the script as an expression (optional)
  375. */
  376. dojo.hostenv.loadUri = function(uri, cb /*optional*/){
  377. if(this.loadedUris[uri]){
  378. return 1;
  379. }
  380. var contents = this.getText(uri, null, true);
  381. if(contents == null){ return 0; }
  382. this.loadedUris[uri] = true;
  383. if(cb){ contents = '('+contents+')'; }
  384. var value = dj_eval(contents);
  385. if(cb){
  386. cb(value);
  387. }
  388. return 1;
  389. }
  390. // FIXME: probably need to add logging to this method
  391. dojo.hostenv.loadUriAndCheck = function(uri, module, cb){
  392. var ok = true;
  393. try{
  394. ok = this.loadUri(uri, cb);
  395. }catch(e){
  396. dojo.debug("failed loading ", uri, " with error: ", e);
  397. }
  398. return ((ok)&&(this.findModule(module, false))) ? true : false;
  399. }
  400. dojo.loaded = function(){ }
  401. dojo.unloaded = function(){ }
  402. dojo.hostenv.loaded = function(){
  403. this.loadNotifying = true;
  404. this.post_load_ = true;
  405. var mll = this.modulesLoadedListeners;
  406. for(var x=0; x<mll.length; x++){
  407. mll[x]();
  408. }
  409. //Clear listeners so new ones can be added
  410. //For other xdomain package loads after the initial load.
  411. this.modulesLoadedListeners = [];
  412. this.loadNotifying = false;
  413. dojo.loaded();
  414. }
  415. dojo.hostenv.unloaded = function(){
  416. var mll = this.unloadListeners;
  417. while(mll.length){
  418. (mll.pop())();
  419. }
  420. dojo.unloaded();
  421. }
  422. /*
  423. Call styles:
  424. dojo.addOnLoad(functionPointer)
  425. dojo.addOnLoad(object, "functionName")
  426. */
  427. dojo.addOnLoad = function(obj, fcnName) {
  428. var dh = dojo.hostenv;
  429. if(arguments.length == 1) {
  430. dh.modulesLoadedListeners.push(obj);
  431. } else if(arguments.length > 1) {
  432. dh.modulesLoadedListeners.push(function() {
  433. obj[fcnName]();
  434. });
  435. }
  436. //Added for xdomain loading. dojo.addOnLoad is used to
  437. //indicate callbacks after doing some dojo.require() statements.
  438. //In the xdomain case, if all the requires are loaded (after initial
  439. //page load), then immediately call any listeners.
  440. if(dh.post_load_ && dh.inFlightCount == 0 && !dh.loadNotifying){
  441. dh.callLoaded();
  442. }
  443. }
  444. dojo.addOnUnload = function(obj, fcnName){
  445. var dh = dojo.hostenv;
  446. if(arguments.length == 1){
  447. dh.unloadListeners.push(obj);
  448. } else if(arguments.length > 1) {
  449. dh.unloadListeners.push(function() {
  450. obj[fcnName]();
  451. });
  452. }
  453. }
  454. dojo.hostenv.modulesLoaded = function(){
  455. if(this.post_load_){ return; }
  456. if((this.loadUriStack.length==0)&&(this.getTextStack.length==0)){
  457. if(this.inFlightCount > 0){
  458. dojo.debug("files still in flight!");
  459. return;
  460. }
  461. dojo.hostenv.callLoaded();
  462. }
  463. }
  464. dojo.hostenv.callLoaded = function(){
  465. if(typeof setTimeout == "object"){
  466. setTimeout("dojo.hostenv.loaded();", 0);
  467. }else{
  468. dojo.hostenv.loaded();
  469. }
  470. }
  471. dojo.hostenv.getModuleSymbols = function(modulename) {
  472. var syms = modulename.split(".");
  473. for(var i = syms.length - 1; i > 0; i--){
  474. var parentModule = syms.slice(0, i).join(".");
  475. var parentModulePath = this.getModulePrefix(parentModule);
  476. if(parentModulePath != parentModule){
  477. syms.splice(0, i, parentModulePath);
  478. break;
  479. }
  480. }
  481. return syms;
  482. }
  483. /**
  484. * loadModule("A.B") first checks to see if symbol A.B is defined.
  485. * If it is, it is simply returned (nothing to do).
  486. *
  487. * If it is not defined, it will look for "A/B.js" in the script root directory,
  488. * followed by "A.js".
  489. *
  490. * It throws if it cannot find a file to load, or if the symbol A.B is not
  491. * defined after loading.
  492. *
  493. * It returns the object A.B.
  494. *
  495. * This does nothing about importing symbols into the current package.
  496. * It is presumed that the caller will take care of that. For example, to import
  497. * all symbols:
  498. *
  499. * with (dojo.hostenv.loadModule("A.B")) {
  500. * ...
  501. * }
  502. *
  503. * And to import just the leaf symbol:
  504. *
  505. * var B = dojo.hostenv.loadModule("A.B");
  506. * ...
  507. *
  508. * dj_load is an alias for dojo.hostenv.loadModule
  509. */
  510. dojo.hostenv._global_omit_module_check = false;
  511. dojo.hostenv.loadModule = function(modulename, exact_only, omit_module_check){
  512. if(!modulename){ return; }
  513. omit_module_check = this._global_omit_module_check || omit_module_check;
  514. var module = this.findModule(modulename, false);
  515. if(module){
  516. return module;
  517. }
  518. // protect against infinite recursion from mutual dependencies
  519. if(dj_undef(modulename, this.loading_modules_)){
  520. this.addedToLoadingCount.push(modulename);
  521. }
  522. this.loading_modules_[modulename] = 1;
  523. // convert periods to slashes
  524. var relpath = modulename.replace(/\./g, '/') + '.js';
  525. var syms = this.getModuleSymbols(modulename);
  526. var startedRelative = ((syms[0].charAt(0) != '/')&&(!syms[0].match(/^\w+:/)));
  527. var last = syms[syms.length - 1];
  528. // figure out if we're looking for a full package, if so, we want to do
  529. // things slightly diffrently
  530. var nsyms = modulename.split(".");
  531. if(last=="*"){
  532. modulename = (nsyms.slice(0, -1)).join('.');
  533. while(syms.length){
  534. syms.pop();
  535. syms.push(this.pkgFileName);
  536. relpath = syms.join("/") + '.js';
  537. if(startedRelative && (relpath.charAt(0)=="/")){
  538. relpath = relpath.slice(1);
  539. }
  540. ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
  541. if(ok){ break; }
  542. syms.pop();
  543. }
  544. }else{
  545. relpath = syms.join("/") + '.js';
  546. modulename = nsyms.join('.');
  547. var ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
  548. if((!ok)&&(!exact_only)){
  549. syms.pop();
  550. while(syms.length){
  551. relpath = syms.join('/') + '.js';
  552. ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
  553. if(ok){ break; }
  554. syms.pop();
  555. relpath = syms.join('/') + '/'+this.pkgFileName+'.js';
  556. if(startedRelative && (relpath.charAt(0)=="/")){
  557. relpath = relpath.slice(1);
  558. }
  559. ok = this.loadPath(relpath, ((!omit_module_check) ? modulename : null));
  560. if(ok){ break; }
  561. }
  562. }
  563. if((!ok)&&(!omit_module_check)){
  564. dojo.raise("Could not load '" + modulename + "'; last tried '" + relpath + "'");
  565. }
  566. }
  567. // check that the symbol was defined
  568. //Don't bother if we're doing xdomain (asynchronous) loading.
  569. if(!omit_module_check && !this["isXDomain"]){
  570. // pass in false so we can give better error
  571. module = this.findModule(modulename, false);
  572. if(!module){
  573. dojo.raise("symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
  574. }
  575. }
  576. return module;
  577. }
  578. /**
  579. * startPackage("A.B") follows the path, and at each level creates a new empty
  580. * object or uses what already exists. It returns the result.
  581. */
  582. dojo.hostenv.startPackage = function(packname){
  583. var modref = dojo.evalObjPath((packname.split(".").slice(0, -1)).join('.'));
  584. this.loaded_modules_[(new String(packname)).toLowerCase()] = modref;
  585. var syms = packname.split(/\./);
  586. if(syms[syms.length-1]=="*"){
  587. syms.pop();
  588. }
  589. return dojo.evalObjPath(syms.join("."), true);
  590. }
  591. /**
  592. * findModule("A.B") returns the object A.B if it exists, otherwise null.
  593. * @param modulename A string like 'A.B'.
  594. * @param must_exist Optional, defualt false. throw instead of returning null
  595. * if the module does not currently exist.
  596. */
  597. dojo.hostenv.findModule = function(modulename, must_exist){
  598. // check cache
  599. /*
  600. if(!dj_undef(modulename, this.modules_)){
  601. return this.modules_[modulename];
  602. }
  603. */
  604. var lmn = (new String(modulename)).toLowerCase();
  605. if(this.loaded_modules_[lmn]){
  606. return this.loaded_modules_[lmn];
  607. }
  608. // see if symbol is defined anyway
  609. var module = dojo.evalObjPath(modulename);
  610. if((modulename)&&(typeof module != 'undefined')&&(module)){
  611. this.loaded_modules_[lmn] = module;
  612. return module;
  613. }
  614. if(must_exist){
  615. dojo.raise("no loaded module named '" + modulename + "'");
  616. }
  617. return null;
  618. }
  619. //Start of old bootstrap2:
  620. /*
  621. * This method taks a "map" of arrays which one can use to optionally load dojo
  622. * modules. The map is indexed by the possible dojo.hostenv.name_ values, with
  623. * two additional values: "default" and "common". The items in the "default"
  624. * array will be loaded if none of the other items have been choosen based on
  625. * the hostenv.name_ item. The items in the "common" array will _always_ be
  626. * loaded, regardless of which list is chosen. Here's how it's normally
  627. * called:
  628. *
  629. * dojo.kwCompoundRequire({
  630. * browser: [
  631. * ["foo.bar.baz", true, true], // an example that passes multiple args to loadModule()
  632. * "foo.sample.*",
  633. * "foo.test,
  634. * ],
  635. * default: [ "foo.sample.*" ],
  636. * common: [ "really.important.module.*" ]
  637. * });
  638. */
  639. dojo.kwCompoundRequire = function(modMap){
  640. var common = modMap["common"]||[];
  641. var result = (modMap[dojo.hostenv.name_]) ? common.concat(modMap[dojo.hostenv.name_]||[]) : common.concat(modMap["default"]||[]);
  642. for(var x=0; x<result.length; x++){
  643. var curr = result[x];
  644. if(curr.constructor == Array){
  645. dojo.hostenv.loadModule.apply(dojo.hostenv, curr);
  646. }else{
  647. dojo.hostenv.loadModule(curr);
  648. }
  649. }
  650. }
  651. dojo.require = function(){
  652. dojo.hostenv.loadModule.apply(dojo.hostenv, arguments);
  653. }
  654. dojo.requireIf = function(){
  655. if((arguments[0] === true)||(arguments[0]=="common")||(arguments[0] && dojo.render[arguments[0]].capable)){
  656. var args = [];
  657. for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); }
  658. dojo.require.apply(dojo, args);
  659. }
  660. }
  661. dojo.requireAfterIf = dojo.requireIf;
  662. dojo.provide = function(){
  663. return dojo.hostenv.startPackage.apply(dojo.hostenv, arguments);
  664. }
  665. dojo.setModulePrefix = function(module, prefix){
  666. return dojo.hostenv.setModulePrefix(module, prefix);
  667. }
  668. // determine if an object supports a given method
  669. // useful for longer api chains where you have to test each object in the chain
  670. dojo.exists = function(obj, name){
  671. var p = name.split(".");
  672. for(var i = 0; i < p.length; i++){
  673. if(!(obj[p[i]])) return false;
  674. obj = obj[p[i]];
  675. }
  676. return true;
  677. }
  678. };
  679. if(typeof window == 'undefined'){
  680. dojo.raise("no window object");
  681. }
  682. // attempt to figure out the path to dojo if it isn't set in the config
  683. (function() {
  684. // before we get any further with the config options, try to pick them out
  685. // of the URL. Most of this code is from NW
  686. if(djConfig.allowQueryConfig){
  687. var baseUrl = document.location.toString(); // FIXME: use location.query instead?
  688. var params = baseUrl.split("?", 2);
  689. if(params.length > 1){
  690. var paramStr = params[1];
  691. var pairs = paramStr.split("&");
  692. for(var x in pairs){
  693. var sp = pairs[x].split("=");
  694. // FIXME: is this eval dangerous?
  695. if((sp[0].length > 9)&&(sp[0].substr(0, 9) == "djConfig.")){
  696. var opt = sp[0].substr(9);
  697. try{
  698. djConfig[opt]=eval(sp[1]);
  699. }catch(e){
  700. djConfig[opt]=sp[1];
  701. }
  702. }
  703. }
  704. }
  705. }
  706. if(((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&(document && document.getElementsByTagName)){
  707. var scripts = document.getElementsByTagName("script");
  708. var rePkg = /(__package__|dojo|bootstrap1)\.js([\?\.]|$)/i;
  709. for(var i = 0; i < scripts.length; i++) {
  710. var src = scripts[i].getAttribute("src");
  711. if(!src) { continue; }
  712. var m = src.match(rePkg);
  713. if(m) {
  714. var root = src.substring(0, m.index);
  715. if(src.indexOf("bootstrap1") > -1) { root += "../"; }
  716. if(!this["djConfig"]) { djConfig = {}; }
  717. if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; }
  718. if(djConfig["baseRelativePath"] == "") { djConfig["baseRelativePath"] = root; }
  719. break;
  720. }
  721. }
  722. }
  723. // fill in the rendering support information in dojo.render.*
  724. var dr = dojo.render;
  725. var drh = dojo.render.html;
  726. var drs = dojo.render.svg;
  727. var dua = drh.UA = navigator.userAgent;
  728. var dav = drh.AV = navigator.appVersion;
  729. var t = true;
  730. var f = false;
  731. drh.capable = t;
  732. drh.support.builtin = t;
  733. dr.ver = parseFloat(drh.AV);
  734. dr.os.mac = dav.indexOf("Macintosh") >= 0;
  735. dr.os.win = dav.indexOf("Windows") >= 0;
  736. // could also be Solaris or something, but it's the same browser
  737. dr.os.linux = dav.indexOf("X11") >= 0;
  738. drh.opera = dua.indexOf("Opera") >= 0;
  739. drh.khtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0);
  740. drh.safari = dav.indexOf("Safari") >= 0;
  741. var geckoPos = dua.indexOf("Gecko");
  742. drh.mozilla = drh.moz = (geckoPos >= 0)&&(!drh.khtml);
  743. if (drh.mozilla) {
  744. // gecko version is YYYYMMDD
  745. drh.geckoVersion = dua.substring(geckoPos + 6, geckoPos + 14);
  746. }
  747. drh.ie = (document.all)&&(!drh.opera);
  748. drh.ie50 = drh.ie && dav.indexOf("MSIE 5.0")>=0;
  749. drh.ie55 = drh.ie && dav.indexOf("MSIE 5.5")>=0;
  750. drh.ie60 = drh.ie && dav.indexOf("MSIE 6.0")>=0;
  751. drh.ie70 = drh.ie && dav.indexOf("MSIE 7.0")>=0;
  752. // TODO: is the HTML LANG attribute relevant?
  753. dojo.locale = (drh.ie ? navigator.userLanguage : navigator.language).toLowerCase();
  754. dr.vml.capable=drh.ie;
  755. drs.capable = f;
  756. drs.support.plugin = f;
  757. drs.support.builtin = f;
  758. if (document.implementation
  759. && document.implementation.hasFeature
  760. && document.implementation.hasFeature("org.w3c.dom.svg", "1.0")
  761. ){
  762. drs.capable = t;
  763. drs.support.builtin = t;
  764. drs.support.plugin = f;
  765. }
  766. })();
  767. dojo.hostenv.startPackage("dojo.hostenv");
  768. dojo.render.name = dojo.hostenv.name_ = 'browser';
  769. dojo.hostenv.searchIds = [];
  770. // These are in order of decreasing likelihood; this will change in time.
  771. dojo.hostenv._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
  772. dojo.hostenv.getXmlhttpObject = function(){
  773. var http = null;
  774. var last_e = null;
  775. try{ http = new XMLHttpRequest(); }catch(e){}
  776. if(!http){
  777. for(var i=0; i<3; ++i){
  778. var progid = dojo.hostenv._XMLHTTP_PROGIDS[i];
  779. try{
  780. http = new ActiveXObject(progid);
  781. }catch(e){
  782. last_e = e;
  783. }
  784. if(http){
  785. dojo.hostenv._XMLHTTP_PROGIDS = [progid]; // so faster next time
  786. break;
  787. }
  788. }
  789. /*if(http && !http.toString) {
  790. http.toString = function() { "[object XMLHttpRequest]"; }
  791. }*/
  792. }
  793. if(!http){
  794. return dojo.raise("XMLHTTP not available", last_e);
  795. }
  796. return http;
  797. }
  798. /**
  799. * Read the contents of the specified uri and return those contents.
  800. *
  801. * @param uri A relative or absolute uri. If absolute, it still must be in the
  802. * same "domain" as we are.
  803. *
  804. * @param async_cb If not specified, load synchronously. If specified, load
  805. * asynchronously, and use async_cb as the progress handler which takes the
  806. * xmlhttp object as its argument. If async_cb, this function returns null.
  807. *
  808. * @param fail_ok Default false. If fail_ok and !async_cb and loading fails,
  809. * return null instead of throwing.
  810. */
  811. dojo.hostenv.getText = function(uri, async_cb, fail_ok){
  812. var http = this.getXmlhttpObject();
  813. if(async_cb){
  814. http.onreadystatechange = function(){
  815. if(4==http.readyState){
  816. if((!http["status"])||((200 <= http.status)&&(300 > http.status))){
  817. // dojo.debug("LOADED URI: "+uri);
  818. async_cb(http.responseText);
  819. }
  820. }
  821. }
  822. }
  823. http.open('GET', uri, async_cb ? true : false);
  824. try{
  825. http.send(null);
  826. if(async_cb){
  827. return null;
  828. }
  829. if((http["status"])&&((200 > http.status)||(300 <= http.status))){
  830. throw Error("Unable to load "+uri+" status:"+ http.status);
  831. }
  832. }catch(e){
  833. if((fail_ok)&&(!async_cb)){
  834. return null;
  835. }else{
  836. throw e;
  837. }
  838. }
  839. return http.responseText;
  840. }
  841. /*
  842. * It turns out that if we check *right now*, as this script file is being loaded,
  843. * then the last script element in the window DOM is ourselves.
  844. * That is because any subsequent script elements haven't shown up in the document
  845. * object yet.
  846. */
  847. /*
  848. function dj_last_script_src() {
  849. var scripts = window.document.getElementsByTagName('script');
  850. if(scripts.length < 1){
  851. dojo.raise("No script elements in window.document, so can't figure out my script src");
  852. }
  853. var script = scripts[scripts.length - 1];
  854. var src = script.src;
  855. if(!src){
  856. dojo.raise("Last script element (out of " + scripts.length + ") has no src");
  857. }
  858. return src;
  859. }
  860. if(!dojo.hostenv["library_script_uri_"]){
  861. dojo.hostenv.library_script_uri_ = dj_last_script_src();
  862. }
  863. */
  864. dojo.hostenv.defaultDebugContainerId = 'dojoDebug';
  865. dojo.hostenv._println_buffer = [];
  866. dojo.hostenv._println_safe = false;
  867. dojo.hostenv.println = function (line){
  868. if(!dojo.hostenv._println_safe){
  869. dojo.hostenv._println_buffer.push(line);
  870. }else{
  871. try {
  872. var console = document.getElementById(djConfig.debugContainerId ?
  873. djConfig.debugContainerId : dojo.hostenv.defaultDebugContainerId);
  874. if(!console) { console = document.getElementsByTagName("body")[0] || document.body; }
  875. var div = document.createElement("div");
  876. div.appendChild(document.createTextNode(line));
  877. console.appendChild(div);
  878. } catch (e) {
  879. try{
  880. // safari needs the output wrapped in an element for some reason
  881. document.write("<div>" + line + "</div>");
  882. }catch(e2){
  883. window.status = line;
  884. }
  885. }
  886. }
  887. }
  888. dojo.addOnLoad(function(){
  889. dojo.hostenv._println_safe = true;
  890. while(dojo.hostenv._println_buffer.length > 0){
  891. dojo.hostenv.println(dojo.hostenv._println_buffer.shift());
  892. }
  893. });
  894. function dj_addNodeEvtHdlr(node, evtName, fp, capture){
  895. var oldHandler = node["on"+evtName] || function(){};
  896. node["on"+evtName] = function(){
  897. fp.apply(node, arguments);
  898. oldHandler.apply(node, arguments);
  899. }
  900. return true;
  901. }
  902. /* Uncomment this to allow init after DOMLoad, not after window.onload
  903. // Mozilla exposes the event we could use
  904. if (dojo.render.html.mozilla) {
  905. document.addEventListener("DOMContentLoaded", dj_load_init, null);
  906. }
  907. // for Internet Explorer. readyState will not be achieved on init call, but dojo doesn't need it
  908. //Tighten up the comments below to allow init after DOMLoad, not after window.onload
  909. / * @cc_on @ * /
  910. / * @if (@_win32)
  911. document.write("<script defer>dj_load_init()<"+"/script>");
  912. / * @end @ * /
  913. */
  914. // default for other browsers
  915. // potential TODO: apply setTimeout approach for other browsers
  916. // that will cause flickering though ( document is loaded and THEN is processed)
  917. // maybe show/hide required in this case..
  918. // TODO: other browsers may support DOMContentLoaded/defer attribute. Add them to above.
  919. dj_addNodeEvtHdlr(window, "load", function(){
  920. // allow multiple calls, only first one will take effect
  921. if(arguments.callee.initialized){ return; }
  922. arguments.callee.initialized = true;
  923. var initFunc = function(){
  924. //perform initialization
  925. if(dojo.render.html.ie){
  926. dojo.hostenv.makeWidgets();
  927. }
  928. };
  929. if(dojo.hostenv.inFlightCount == 0){
  930. initFunc();
  931. dojo.hostenv.modulesLoaded();
  932. }else{
  933. dojo.addOnLoad(initFunc);
  934. }
  935. });
  936. dj_addNodeEvtHdlr(window, "unload", function(){
  937. dojo.hostenv.unloaded();
  938. });
  939. dojo.hostenv.makeWidgets = function(){
  940. // you can put searchIds in djConfig and dojo.hostenv at the moment
  941. // we should probably eventually move to one or the other
  942. var sids = [];
  943. if(djConfig.searchIds && djConfig.searchIds.length > 0) {
  944. sids = sids.concat(djConfig.searchIds);
  945. }
  946. if(dojo.hostenv.searchIds && dojo.hostenv.searchIds.length > 0) {
  947. sids = sids.concat(dojo.hostenv.searchIds);
  948. }
  949. if((djConfig.parseWidgets)||(sids.length > 0)){
  950. if(dojo.evalObjPath("dojo.widget.Parse")){
  951. // we must do this on a delay to avoid:
  952. // http://www.shaftek.org/blog/archives/000212.html
  953. // IE is such a tremendous peice of shit.
  954. var parser = new dojo.xml.Parse();
  955. if(sids.length > 0){
  956. for(var x=0; x<sids.length; x++){
  957. var tmpNode = document.getElementById(sids[x]);
  958. if(!tmpNode){ continue; }
  959. var frag = parser.parseElement(tmpNode, null, true);
  960. dojo.widget.getParser().createComponents(frag);
  961. }
  962. }else if(djConfig.parseWidgets){
  963. var frag = parser.parseElement(document.getElementsByTagName("body")[0] || document.body, null, true);
  964. dojo.widget.getParser().createComponents(frag);
  965. }
  966. }
  967. }
  968. }
  969. dojo.addOnLoad(function(){
  970. if(!dojo.render.html.ie) {
  971. dojo.hostenv.makeWidgets();
  972. }
  973. });
  974. try {
  975. if (dojo.render.html.ie) {
  976. document.write('<style>v\:*{ behavior:url(#default#VML); }</style>');
  977. document.write('<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>');
  978. }
  979. } catch (e) { }
  980. // stub, over-ridden by debugging code. This will at least keep us from
  981. // breaking when it's not included
  982. dojo.hostenv.writeIncludes = function(){}
  983. dojo.byId = function(id, doc){
  984. if(id && (typeof id == "string" || id instanceof String)){
  985. if(!doc){ doc = document; }
  986. return doc.getElementById(id);
  987. }
  988. return id; // assume it's a node
  989. }
  990. //Semicolon is for when this file is integrated with a custom build on one line
  991. //with some other file's contents. Sometimes that makes things not get defined
  992. //properly, particularly with the using the closure below to do all the work.
  993. ;(function(){
  994. //Don't do this work if dojo.js has already done it.
  995. if(typeof dj_usingBootstrap != "undefined"){
  996. return;
  997. }
  998. var isRhino = false;
  999. var isSpidermonkey = false;
  1000. var isDashboard = false;
  1001. if((typeof this["load"] == "function")&&((typeof this["Packages"] == "function")||(typeof this["Packages"] == "object"))){
  1002. isRhino = true;
  1003. }else if(typeof this["load"] == "function"){
  1004. isSpidermonkey = true;
  1005. }else if(window.widget){
  1006. isDashboard = true;
  1007. }
  1008. var tmps = [];
  1009. if((this["djConfig"])&&((djConfig["isDebug"])||(djConfig["debugAtAllCosts"]))){
  1010. tmps.push("debug.js");
  1011. }
  1012. if((this["djConfig"])&&(djConfig["debugAtAllCosts"])&&(!isRhino)&&(!isDashboard)){
  1013. tmps.push("browser_debug.js");
  1014. }
  1015. //Support compatibility packages. Right now this only allows setting one
  1016. //compatibility package. Might need to revisit later down the line to support
  1017. //more than one.
  1018. if((this["djConfig"])&&(djConfig["compat"])){
  1019. tmps.push("compat/" + djConfig["compat"] + ".js");
  1020. }
  1021. var loaderRoot = djConfig["baseScriptUri"];
  1022. if((this["djConfig"])&&(djConfig["baseLoaderUri"])){
  1023. loaderRoot = djConfig["baseLoaderUri"];
  1024. }
  1025. for(var x=0; x < tmps.length; x++){
  1026. var spath = loaderRoot+"src/"+tmps[x];
  1027. if(isRhino||isSpidermonkey){
  1028. load(spath);
  1029. } else {
  1030. try {
  1031. document.write("<scr"+"ipt type='text/javascript' src='"+spath+"'></scr"+"ipt>");
  1032. } catch (e) {
  1033. var script = document.createElement("script");
  1034. script.src = spath;
  1035. document.getElementsByTagName("head")[0].appendChild(script);
  1036. }
  1037. }
  1038. }
  1039. })();
  1040. // Localization routines
  1041. /**
  1042. * The locale to look for string bundles if none are defined for your locale. Translations for all strings
  1043. * should be provided in this locale.
  1044. */
  1045. //TODO: this really belongs in translation metadata, not in code
  1046. dojo.fallback_locale = 'en';
  1047. /**
  1048. * Returns canonical form of locale, as used by Dojo. All variants are case-insensitive and are separated by '-'
  1049. * as specified in RFC 3066
  1050. */
  1051. dojo.normalizeLocale = function(locale) {
  1052. return locale ? locale.toLowerCase() : dojo.locale;
  1053. };
  1054. /**
  1055. * requireLocalization() is for loading translated bundles provided within a package in the namespace.
  1056. * Contents are typically strings, but may be any name/value pair, represented in JSON format.
  1057. * A bundle is structured in a program as follows:
  1058. *
  1059. * <package>/
  1060. * nls/
  1061. * de/
  1062. * mybundle.js
  1063. * de-at/
  1064. * mybundle.js
  1065. * en/
  1066. * mybundle.js
  1067. * en-us/
  1068. * mybundle.js
  1069. * en-gb/
  1070. * mybundle.js
  1071. * es/
  1072. * mybundle.js
  1073. * ...etc
  1074. *
  1075. * where package is part of the namespace as used by dojo.require(). Each directory is named for a
  1076. * locale as specified by RFC 3066, (http://www.ietf.org/rfc/rfc3066.txt), normalized in lowercase.
  1077. *
  1078. * For a given locale, string bundles will be loaded for that locale and all general locales above it, as well
  1079. * as a system-specified fallback. For example, "de_at" will also load "de" and "en". Lookups will traverse
  1080. * the locales in this order. A build step can preload the bundles to avoid data redundancy and extra network hits.
  1081. *
  1082. * @param modulename package in which the bundle is found
  1083. * @param bundlename bundle name, typically the filename without the '.js' suffix
  1084. * @param locale the locale to load (optional) By default, the browser's user locale as defined
  1085. * in dojo.locale
  1086. */
  1087. dojo.requireLocalization = function(modulename, bundlename, locale /*optional*/){
  1088. dojo.debug("EXPERIMENTAL: dojo.requireLocalization"); //dojo.experimental
  1089. var syms = dojo.hostenv.getModuleSymbols(modulename);
  1090. var modpath = syms.concat("nls").join("/");
  1091. locale = dojo.normalizeLocale(locale);
  1092. var elements = locale.split('-');
  1093. var searchlist = [];
  1094. for(var i = elements.length; i > 0; i--){
  1095. searchlist.push(elements.slice(0, i).join('-'));
  1096. }
  1097. if(searchlist[searchlist.length-1] != dojo.fallback_locale){
  1098. searchlist.push(dojo.fallback_locale);
  1099. }
  1100. var bundlepackage = [modulename, "_nls", bundlename].join(".");
  1101. var bundle = dojo.hostenv.startPackage(bundlepackage);
  1102. dojo.hostenv.loaded_modules_[bundlepackage] = bundle;
  1103. var inherit = false;
  1104. for(var i = searchlist.length - 1; i >= 0; i--){
  1105. var loc = searchlist[i];
  1106. var pkg = [bundlepackage, loc].join(".");
  1107. var loaded = false;
  1108. if(!dojo.hostenv.findModule(pkg)){
  1109. // Mark loaded whether it's found or not, so that further load attempts will not be made
  1110. dojo.hostenv.loaded_modules_[pkg] = null;
  1111. var filespec = [modpath, loc, bundlename].join("/") + '.js';
  1112. loaded = dojo.hostenv.loadPath(filespec, null, function(hash) {
  1113. bundle[loc] = hash;
  1114. if(inherit){
  1115. // Use mixins approach to copy string references from inherit bundle, but skip overrides.
  1116. for(var x in inherit){
  1117. if(!bundle[loc][x]){
  1118. bundle[loc][x] = inherit[x];
  1119. }
  1120. }
  1121. }
  1122. /*
  1123. // Use prototype to point to other bundle, then copy in result from loadPath
  1124. bundle[loc] = new function(){};
  1125. if(inherit){ bundle[loc].prototype = inherit; }
  1126. for(var i in hash){ bundle[loc][i] = hash[i]; }
  1127. */
  1128. });
  1129. }else{
  1130. loaded = true;
  1131. }
  1132. if(loaded && bundle[loc]){
  1133. inherit = bundle[loc];
  1134. }
  1135. }
  1136. };
  1137. dojo.provide("dojo.string.common");
  1138. dojo.require("dojo.string");
  1139. /**
  1140. * Trim whitespace from 'str'. If 'wh' > 0,
  1141. * only trim from start, if 'wh' < 0, only trim
  1142. * from end, otherwise trim both ends
  1143. */
  1144. dojo.string.trim = function(str, wh){
  1145. if(!str.replace){ return str; }
  1146. if(!str.length){ return str; }
  1147. var re = (wh > 0) ? (/^\s+/) : (wh < 0) ? (/\s+$/) : (/^\s+|\s+$/g);
  1148. return str.replace(re, "");
  1149. }
  1150. /**
  1151. * Trim whitespace at the beginning of 'str'
  1152. */
  1153. dojo.string.trimStart = function(str) {
  1154. return dojo.string.trim(str, 1);
  1155. }
  1156. /**
  1157. * Trim whitespace at the end of 'str'
  1158. */
  1159. dojo.string.trimEnd = function(str) {
  1160. return dojo.string.trim(str, -1);
  1161. }
  1162. /**
  1163. * Return 'str' repeated 'count' times, optionally
  1164. * placing 'separator' between each rep
  1165. */
  1166. dojo.string.repeat = function(str, count, separator) {
  1167. var out = "";
  1168. for(var i = 0; i < count; i++) {
  1169. out += str;
  1170. if(separator && i < count - 1) {
  1171. out += separator;
  1172. }
  1173. }
  1174. return out;
  1175. }
  1176. /**
  1177. * Pad 'str' to guarantee that it is at least 'len' length
  1178. * with the character 'c' at either the start (dir=1) or
  1179. * end (dir=-1) of the string
  1180. */
  1181. dojo.string.pad = function(str, len/*=2*/, c/*='0'*/, dir/*=1*/) {
  1182. var out = String(str);
  1183. if(!c) {
  1184. c = '0';
  1185. }
  1186. if(!dir) {
  1187. dir = 1;
  1188. }
  1189. while(out.length < len) {
  1190. if(dir > 0) {
  1191. out = c + out;
  1192. } else {
  1193. out += c;
  1194. }
  1195. }
  1196. return out;
  1197. }
  1198. /** same as dojo.string.pad(str, len, c, 1) */
  1199. dojo.string.padLeft = function(str, len, c) {
  1200. return dojo.string.pad(str, len, c, 1);
  1201. }
  1202. /** same as dojo.string.pad(str, len, c, -1) */
  1203. dojo.string.padRight = function(str, len, c) {
  1204. return dojo.string.pad(str, len, c, -1);
  1205. }
  1206. dojo.provide("dojo.string");
  1207. dojo.require("dojo.string.common");
  1208. dojo.provide("dojo.lang.common");
  1209. dojo.require("dojo.lang");
  1210. /*
  1211. * Adds the given properties/methods to the specified object
  1212. */
  1213. dojo.lang._mixin = function(obj, props){
  1214. var tobj = {};
  1215. for(var x in props){
  1216. // the "tobj" condition avoid copying properties in "props"
  1217. // inherited from Object.prototype. For example, if obj has a custom
  1218. // toString() method, don't overwrite it with the toString() method
  1219. // that props inherited from Object.protoype
  1220. if(typeof tobj[x] == "undefined" || tobj[x] != props[x]) {
  1221. obj[x] = props[x];
  1222. }
  1223. }
  1224. // IE doesn't recognize custom toStrings in for..in
  1225. if(dojo.render.html.ie && dojo.lang.isFunction(props["toString"]) && props["toString"] != obj["toString"]) {
  1226. obj.toString = props.toString;
  1227. }
  1228. return obj;
  1229. }
  1230. /*
  1231. * Adds the properties/methods of argument Objects to obj
  1232. */
  1233. dojo.lang.mixin = function(obj, props /*, props, ..., props */){
  1234. for(var i=1, l=arguments.length; i<l; i++){
  1235. dojo.lang._mixin(obj, arguments[i]);
  1236. }
  1237. return obj;
  1238. }
  1239. /*
  1240. * Adds the properties/methods of argument Objects to ctor's prototype
  1241. */
  1242. dojo.lang.extend = function(ctor /*function*/, props /*, props, ..., props */){
  1243. for(var i=1, l=arguments.length; i<l; i++){
  1244. dojo.lang._mixin(ctor.prototype, arguments[i]);
  1245. }
  1246. return ctor;
  1247. }
  1248. /**
  1249. * See if val is in arr. Call signatures:
  1250. * find(array, value, identity) // recommended
  1251. * find(value, array, identity)
  1252. **/
  1253. dojo.lang.find = function( /*Array*/ arr,
  1254. /*Object*/ val,
  1255. /*boolean*/ identity,
  1256. /*boolean*/ findLast){
  1257. // support both (arr, val) and (val, arr)
  1258. if(!dojo.lang.isArrayLike(arr) && dojo.lang.isArrayLike(val)) {
  1259. var a = arr;
  1260. arr = val;
  1261. val = a;
  1262. }
  1263. var isString = dojo.lang.isString(arr);
  1264. if(isString) { arr = arr.split(""); }
  1265. if(findLast) {
  1266. var step = -1;
  1267. var i = arr.length - 1;
  1268. var end = -1;
  1269. } else {
  1270. var step = 1;
  1271. var i = 0;
  1272. var end = arr.length;
  1273. }
  1274. if(identity){
  1275. while(i != end) {
  1276. if(arr[i] === val){ return i; }
  1277. i += step;
  1278. }
  1279. }else{
  1280. while(i != end) {
  1281. if(arr[i] == val){ return i; }
  1282. i += step;
  1283. }
  1284. }
  1285. return -1;
  1286. }
  1287. dojo.lang.indexOf = dojo.lang.find;
  1288. dojo.lang.findLast = function(/*Array*/ arr, /*Object*/ val, /*boolean*/ identity){
  1289. return dojo.lang.find(arr, val, identity, true);
  1290. }
  1291. dojo.lang.lastIndexOf = dojo.lang.findLast;
  1292. dojo.lang.inArray = function(arr /*Array*/, val /*Object*/){
  1293. return dojo.lang.find(arr, val) > -1; // return: boolean
  1294. }
  1295. /**
  1296. * Partial implmentation of is* functions from
  1297. * http://www.crockford.com/javascript/recommend.html
  1298. * NOTE: some of these may not be the best thing to use in all situations
  1299. * as they aren't part of core JS and therefore can't work in every case.
  1300. * See WARNING messages inline for tips.
  1301. *
  1302. * The following is* functions are fairly "safe"
  1303. */
  1304. dojo.lang.isObject = function(wh){
  1305. if(typeof wh == "undefined"){ return false; }
  1306. return (typeof wh == "object" || wh === null || dojo.lang.isArray(wh) || dojo.lang.isFunction(wh));
  1307. }
  1308. dojo.lang.isArray = function(wh){
  1309. return (wh instanceof Array || typeof wh == "array");
  1310. }
  1311. dojo.lang.isArrayLike = function(wh){
  1312. if(dojo.lang.isString(wh)){ return false; }
  1313. if(dojo.lang.isFunction(wh)){ return false; } // keeps out built-in ctors (Number, String, ...) which have length properties
  1314. if(dojo.lang.isArray(wh)){ return true; }
  1315. if(typeof wh != "undefined" && wh
  1316. && dojo.lang.isNumber(wh.length) && isFinite(wh.length)){ return true; }
  1317. return false;
  1318. }
  1319. dojo.lang.isFunction = function(wh){
  1320. if(!wh){ return false; }
  1321. return (wh instanceof Function || typeof wh == "function");
  1322. }
  1323. dojo.lang.isString = function(wh){
  1324. return (wh instanceof String || typeof wh == "string");
  1325. }
  1326. dojo.lang.isAlien = function(wh){
  1327. if(!wh){ return false; }
  1328. return !dojo.lang.isFunction() && /\{\s*\[native code\]\s*\}/.test(String(wh));
  1329. }
  1330. dojo.lang.isBoolean = function(wh){
  1331. return (wh instanceof Boolean || typeof wh == "boolean");
  1332. }
  1333. /**
  1334. * The following is***() functions are somewhat "unsafe". Fortunately,
  1335. * there are workarounds the the language provides and are mentioned
  1336. * in the WARNING messages.
  1337. *
  1338. * WARNING: In most cases, isNaN(wh) is sufficient to determine whether or not
  1339. * something is a number or can be used as such. For example, a number or string
  1340. * can be used interchangably when accessing array items (arr["1"] is the same as
  1341. * arr[1]) and isNaN will return false for both values ("1" and 1). Should you
  1342. * use isNumber("1"), that will return false, which is generally not too useful.
  1343. * Also, isNumber(NaN) returns true, again, this isn't generally useful, but there
  1344. * are corner cases (like when you want to make sure that two things are really
  1345. * the same type of thing). That is really where isNumber "shines".
  1346. *
  1347. * RECOMMENDATION: Use isNaN(wh) when possible
  1348. */
  1349. dojo.lang.isNumber = function(wh){
  1350. return (wh instanceof Number || typeof wh == "number");
  1351. }
  1352. /**
  1353. * WARNING: In some cases, isUndefined will not behave as you
  1354. * might expect. If you do isUndefined(foo) and there is no earlier
  1355. * reference to foo, an error will be thrown before isUndefined is
  1356. * called. It behaves correctly if you scope yor object first, i.e.
  1357. * isUndefined(foo.bar) where foo is an object and bar isn't a
  1358. * property of the object.
  1359. *
  1360. * RECOMMENDATION: Use `typeof foo == "undefined"` when possible
  1361. *
  1362. * FIXME: Should isUndefined go away since it is error prone?
  1363. */
  1364. dojo.lang.isUndefined = function(wh){
  1365. return ((wh == undefined)&&(typeof wh == "undefined"));
  1366. }
  1367. // end Crockford functions
  1368. dojo.provide("dojo.lang.extras");
  1369. dojo.require("dojo.lang.common");
  1370. /**
  1371. * Sets a timeout in milliseconds to execute a function in a given context
  1372. * with optional arguments.
  1373. *
  1374. * setTimeout (Object context, function func, number delay[, arg1[, ...]]);
  1375. * setTimeout (function func, number delay[, arg1[, ...]]);
  1376. */
  1377. dojo.lang.setTimeout = function(func, delay){
  1378. var context = window, argsStart = 2;
  1379. if(!dojo.lang.isFunction(func)){
  1380. context = func;
  1381. func = delay;
  1382. delay = arguments[2];
  1383. argsStart++;
  1384. }
  1385. if(dojo.lang.isString(func)){
  1386. func = context[func];
  1387. }
  1388. var args = [];
  1389. for (var i = argsStart; i < arguments.length; i++) {
  1390. args.push(arguments[i]);
  1391. }
  1392. return setTimeout(function () { func.apply(context, args); }, delay);
  1393. }
  1394. dojo.lang.getNameInObj = function(ns, item){
  1395. if(!ns){ ns = dj_global; }
  1396. for(var x in ns){
  1397. if(ns[x] === item){
  1398. return new String(x);
  1399. }
  1400. }
  1401. return null;
  1402. }
  1403. dojo.lang.shallowCopy = function(obj) {
  1404. var ret = {}, key;
  1405. for(key in obj) {
  1406. if(dojo.lang.isUndefined(ret[key])) {
  1407. ret[key] = obj[key];
  1408. }
  1409. }
  1410. return ret;
  1411. }
  1412. /**
  1413. * Return the first argument that isn't undefined
  1414. */
  1415. dojo.lang.firstValued = function(/* ... */) {
  1416. for(var i = 0; i < arguments.length; i++) {
  1417. if(typeof arguments[i] != "undefined") {
  1418. return arguments[i];
  1419. }
  1420. }
  1421. return undefined;
  1422. }
  1423. /**
  1424. * Get a value from a reference specified as a string descriptor,
  1425. * (e.g. "A.B") in the given context.
  1426. *
  1427. * getObjPathValue(String objpath [, Object context, Boolean create])
  1428. *
  1429. * If context is not specified, dj_global is used
  1430. * If create is true, undefined objects in the path are created.
  1431. */
  1432. dojo.lang.getObjPathValue = function(objpath, context, create){
  1433. with(dojo.parseObjPath(objpath, context, create)){
  1434. return dojo.evalProp(prop, obj, create);
  1435. }
  1436. }
  1437. /**
  1438. * Set a value on a reference specified as a string descriptor.
  1439. * (e.g. "A.B") in the given context.
  1440. *
  1441. * setObjPathValue(String objpath, value [, Object context, Boolean create])
  1442. *
  1443. * If context is not specified, dj_global is used
  1444. * If create is true, undefined objects in the path are created.
  1445. */
  1446. dojo.lang.setObjPathValue = function(objpath, value, context, create){
  1447. if(arguments.length < 4){
  1448. create = true;
  1449. }
  1450. with(dojo.parseObjPath(objpath, context, create)){
  1451. if(obj && (create || (prop in obj))){
  1452. obj[prop] = value;
  1453. }
  1454. }
  1455. }
  1456. dojo.provide("dojo.io.IO");
  1457. dojo.requir

Large files files are truncated, but you can click here to view the full file