PageRenderTime 113ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 2ms

/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
  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.require("dojo.string");
  1458. dojo.require("dojo.lang.extras");
  1459. /******************************************************************************
  1460. * Notes about dojo.io design:
  1461. *
  1462. * The dojo.io.* package has the unenviable task of making a lot of different
  1463. * types of I/O feel natural, despite a universal lack of good (or even
  1464. * reasonable!) I/O capability in the host environment. So lets pin this down
  1465. * a little bit further.
  1466. *
  1467. * Rhino:
  1468. * perhaps the best situation anywhere. Access to Java classes allows you
  1469. * to do anything one might want in terms of I/O, both synchronously and
  1470. * async. Can open TCP sockets and perform low-latency client/server
  1471. * interactions. HTTP transport is available through Java HTTP client and
  1472. * server classes. Wish it were always this easy.
  1473. *
  1474. * xpcshell:
  1475. * XPCOM for I/O. A cluster-fuck to be sure.
  1476. *
  1477. * spidermonkey:
  1478. * S.O.L.
  1479. *
  1480. * Browsers:
  1481. * Browsers generally do not provide any useable filesystem access. We are
  1482. * therefore limited to HTTP for moving information to and from Dojo
  1483. * instances living in a browser.
  1484. *
  1485. * XMLHTTP:
  1486. * Sync or async, allows reading of arbitrary text files (including
  1487. * JS, which can then be eval()'d), writing requires server
  1488. * cooperation and is limited to HTTP mechanisms (POST and GET).
  1489. *
  1490. * <iframe> hacks:
  1491. * iframe document hacks allow browsers to communicate asynchronously
  1492. * with a server via HTTP POST and GET operations. With significant
  1493. * effort and server cooperation, low-latency data transit between
  1494. * client and server can be acheived via iframe mechanisms (repubsub).
  1495. *
  1496. * SVG:
  1497. * Adobe's SVG viewer implements helpful primitives for XML-based
  1498. * requests, but receipt of arbitrary text data seems unlikely w/o
  1499. * <![CDATA[]]> sections.
  1500. *
  1501. *
  1502. * A discussion between Dylan, Mark, Tom, and Alex helped to lay down a lot
  1503. * the IO API interface. A transcript of it can be found at:
  1504. * http://dojotoolkit.org/viewcvs/viewcvs.py/documents/irc/irc_io_api_log.txt?rev=307&view=auto
  1505. *
  1506. * Also referenced in the design of the API was the DOM 3 L&S spec:
  1507. * http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html
  1508. ******************************************************************************/
  1509. // a map of the available transport options. Transports should add themselves
  1510. // by calling add(name)
  1511. dojo.io.transports = [];
  1512. dojo.io.hdlrFuncNames = [ "load", "error", "timeout" ]; // we're omitting a progress() event for now
  1513. dojo.io.Request = function(url, mimetype, transport, changeUrl){
  1514. if((arguments.length == 1)&&(arguments[0].constructor == Object)){
  1515. this.fromKwArgs(arguments[0]);
  1516. }else{
  1517. this.url = url;
  1518. if(mimetype){ this.mimetype = mimetype; }
  1519. if(transport){ this.transport = transport; }
  1520. if(arguments.length >= 4){ this.changeUrl = changeUrl; }
  1521. }
  1522. }
  1523. dojo.lang.extend(dojo.io.Request, {
  1524. /** The URL to hit */
  1525. url: "",
  1526. /** The mime type used to interrpret the response body */
  1527. mimetype: "text/plain",
  1528. /** The HTTP method to use */
  1529. method: "GET",
  1530. /** An Object containing key-value pairs to be included with the request */
  1531. content: undefined, // Object
  1532. /** The transport medium to use */
  1533. transport: undefined, // String
  1534. /** If defined the URL of the page is physically changed */
  1535. changeUrl: undefined, // String
  1536. /** A form node to use in the request */
  1537. formNode: undefined, // HTMLFormElement
  1538. /** Whether the request should be made synchronously */
  1539. sync: false,
  1540. bindSuccess: false,
  1541. /** Cache/look for the request in the cache before attempting to request?
  1542. * NOTE: this isn't a browser cache, this is internal and would only cache in-page
  1543. */
  1544. useCache: false,
  1545. /** Prevent the browser from caching this by adding a query string argument to the URL */
  1546. preventCache: false,
  1547. // events stuff
  1548. load: function(type, data, evt){ },
  1549. error: function(type, error){ },
  1550. timeout: function(type){ },
  1551. handle: function(){ },
  1552. //FIXME: change BrowserIO.js to use timeouts? IframeIO?
  1553. // The number of seconds to wait until firing a timeout callback.
  1554. // If it is zero, that means, don't do a timeout check.
  1555. timeoutSeconds: 0,
  1556. // the abort method needs to be filled in by the transport that accepts the
  1557. // bind() request
  1558. abort: function(){ },
  1559. // backButton: function(){ },
  1560. // forwardButton: function(){ },
  1561. fromKwArgs: function(kwArgs){
  1562. // normalize args
  1563. if(kwArgs["url"]){ kwArgs.url = kwArgs.url.toString(); }
  1564. if(kwArgs["formNode"]) { kwArgs.formNode = dojo.byId(kwArgs.formNode); }
  1565. if(!kwArgs["method"] && kwArgs["formNode"] && kwArgs["formNode"].method) {
  1566. kwArgs.method = kwArgs["formNode"].method;
  1567. }
  1568. // backwards compatibility
  1569. if(!kwArgs["handle"] && kwArgs["handler"]){ kwArgs.handle = kwArgs.handler; }
  1570. if(!kwArgs["load"] && kwArgs["loaded"]){ kwArgs.load = kwArgs.loaded; }
  1571. if(!kwArgs["changeUrl"] && kwArgs["changeURL"]) { kwArgs.changeUrl = kwArgs.changeURL; }
  1572. // encoding fun!
  1573. kwArgs.encoding = dojo.lang.firstValued(kwArgs["encoding"], djConfig["bindEncoding"], "");
  1574. kwArgs.sendTransport = dojo.lang.firstValued(kwArgs["sendTransport"], djConfig["ioSendTransport"], false);
  1575. var isFunction = dojo.lang.isFunction;
  1576. for(var x=0; x<dojo.io.hdlrFuncNames.length; x++){
  1577. var fn = dojo.io.hdlrFuncNames[x];
  1578. if(isFunction(kwArgs[fn])){ continue; }
  1579. if(isFunction(kwArgs["handle"])){
  1580. kwArgs[fn] = kwArgs.handle;
  1581. }
  1582. // handler is aliased above, shouldn't need this check
  1583. /* else if(dojo.lang.isObject(kwArgs.handler)){
  1584. if(isFunction(kwArgs.handler[fn])){
  1585. kwArgs[fn] = kwArgs.handler[fn]||kwArgs.handler["handle"]||function(){};
  1586. }
  1587. }*/
  1588. }
  1589. dojo.lang.mixin(this, kwArgs);
  1590. }
  1591. });
  1592. dojo.io.Error = function(msg, type, num){
  1593. this.message = msg;
  1594. this.type = type || "unknown"; // must be one of "io", "parse", "unknown"
  1595. this.number = num || 0; // per-substrate error number, not normalized
  1596. }
  1597. dojo.io.transports.addTransport = function(name){
  1598. this.push(name);
  1599. // FIXME: do we need to handle things that aren't direct children of the
  1600. // dojo.io namespace? (say, dojo.io.foo.fooTransport?)
  1601. this[name] = dojo.io[name];
  1602. }
  1603. // binding interface, the various implementations register their capabilities
  1604. // and the bind() method dispatches
  1605. dojo.io.bind = function(request){
  1606. // if the request asks for a particular implementation, use it
  1607. if(!(request instanceof dojo.io.Request)){
  1608. try{
  1609. request = new dojo.io.Request(request);
  1610. }catch(e){ dojo.debug(e); }
  1611. }
  1612. var tsName = "";
  1613. if(request["transport"]){
  1614. tsName = request["transport"];
  1615. // FIXME: it would be good to call the error handler, although we'd
  1616. // need to use setTimeout or similar to accomplish this and we can't
  1617. // garuntee that this facility is available.
  1618. if(!this[tsName]){ return request; }
  1619. }else{
  1620. // otherwise we do our best to auto-detect what available transports
  1621. // will handle
  1622. for(var x=0; x<dojo.io.transports.length; x++){
  1623. var tmp = dojo.io.transports[x];
  1624. if((this[tmp])&&(this[tmp].canHandle(request))){
  1625. tsName = tmp;
  1626. }
  1627. }
  1628. if(tsName == ""){ return request; }
  1629. }
  1630. this[tsName].bind(request);
  1631. request.bindSuccess = true;
  1632. return request;
  1633. }
  1634. dojo.io.queueBind = function(request){
  1635. if(!(request instanceof dojo.io.Request)){
  1636. try{
  1637. request = new dojo.io.Request(request);
  1638. }catch(e){ dojo.debug(e); }
  1639. }
  1640. // make sure we get called if/when we get a response
  1641. var oldLoad = request.load;
  1642. request.load = function(){
  1643. dojo.io._queueBindInFlight = false;
  1644. var ret = oldLoad.apply(this, arguments);
  1645. dojo.io._dispatchNextQueueBind();
  1646. return ret;
  1647. }
  1648. var oldErr = request.error;
  1649. request.error = function(){
  1650. dojo.io._queueBindInFlight = false;
  1651. var ret = oldErr.apply(this, arguments);
  1652. dojo.io._dispatchNextQueueBind();
  1653. return ret;
  1654. }
  1655. dojo.io._bindQueue.push(request);
  1656. dojo.io._dispatchNextQueueBind();
  1657. return request;
  1658. }
  1659. dojo.io._dispatchNextQueueBind = function(){
  1660. if(!dojo.io._queueBindInFlight){
  1661. dojo.io._queueBindInFlight = true;
  1662. if(dojo.io._bindQueue.length > 0){
  1663. dojo.io.bind(dojo.io._bindQueue.shift());
  1664. }else{
  1665. dojo.io._queueBindInFlight = false;
  1666. }
  1667. }
  1668. }
  1669. dojo.io._bindQueue = [];
  1670. dojo.io._queueBindInFlight = false;
  1671. dojo.io.argsFromMap = function(map, encoding, last){
  1672. var enc = /utf/i.test(encoding||"") ? encodeURIComponent : dojo.string.encodeAscii;
  1673. var mapped = [];
  1674. var control = new Object();
  1675. for(var name in map){
  1676. var domap = function(elt){
  1677. var val = enc(name)+"="+enc(elt);
  1678. mapped[(last == name) ? "push" : "unshift"](val);
  1679. }
  1680. if(!control[name]){
  1681. var value = map[name];
  1682. // FIXME: should be isArrayLike?
  1683. if (dojo.lang.isArray(value)){
  1684. dojo.lang.forEach(value, domap);
  1685. }else{
  1686. domap(value);
  1687. }
  1688. }
  1689. }
  1690. return mapped.join("&");
  1691. }
  1692. dojo.io.setIFrameSrc = function(iframe, src, replace){
  1693. try{
  1694. var r = dojo.render.html;
  1695. // dojo.debug(iframe);
  1696. if(!replace){
  1697. if(r.safari){
  1698. iframe.location = src;
  1699. }else{
  1700. frames[iframe.name].location = src;
  1701. }
  1702. }else{
  1703. // Fun with DOM 0 incompatibilities!
  1704. var idoc;
  1705. if(r.ie){
  1706. idoc = iframe.contentWindow.document;
  1707. }else if(r.safari){
  1708. idoc = iframe.document;
  1709. }else{ // if(r.moz){
  1710. idoc = iframe.contentWindow;
  1711. }
  1712. //For Safari (at least 2.0.3) and Opera, if the iframe
  1713. //has just been created but it doesn't have content
  1714. //yet, then iframe.document may be null. In that case,
  1715. //use iframe.location and return.
  1716. if(!idoc){
  1717. iframe.location = src;
  1718. return;
  1719. }else{
  1720. idoc.location.replace(src);
  1721. }
  1722. }
  1723. }catch(e){
  1724. dojo.debug(e);
  1725. dojo.debug("setIFrameSrc: "+e);
  1726. }
  1727. }
  1728. /*
  1729. dojo.io.sampleTranport = new function(){
  1730. this.canHandle = function(kwArgs){
  1731. // canHandle just tells dojo.io.bind() if this is a good transport to
  1732. // use for the particular type of request.
  1733. if(
  1734. (
  1735. (kwArgs["mimetype"] == "text/plain") ||
  1736. (kwArgs["mimetype"] == "text/html") ||
  1737. (kwArgs["mimetype"] == "text/javascript")
  1738. )&&(
  1739. (kwArgs["method"] == "get") ||
  1740. ( (kwArgs["method"] == "post") && (!kwArgs["formNode"]) )
  1741. )
  1742. ){
  1743. return true;
  1744. }
  1745. return false;
  1746. }
  1747. this.bind = function(kwArgs){
  1748. var hdlrObj = {};
  1749. // set up a handler object
  1750. for(var x=0; x<dojo.io.hdlrFuncNames.length; x++){
  1751. var fn = dojo.io.hdlrFuncNames[x];
  1752. if(typeof kwArgs.handler == "object"){
  1753. if(typeof kwArgs.handler[fn] == "function"){
  1754. hdlrObj[fn] = kwArgs.handler[fn]||kwArgs.handler["handle"];
  1755. }
  1756. }else if(typeof kwArgs[fn] == "function"){
  1757. hdlrObj[fn] = kwArgs[fn];
  1758. }else{
  1759. hdlrObj[fn] = kwArgs["handle"]||function(){};
  1760. }
  1761. }
  1762. // build a handler function that calls back to the handler obj
  1763. var hdlrFunc = function(evt){
  1764. if(evt.type == "onload"){
  1765. hdlrObj.load("load", evt.data, evt);
  1766. }else if(evt.type == "onerr"){
  1767. var errObj = new dojo.io.Error("sampleTransport Error: "+evt.msg);
  1768. hdlrObj.error("error", errObj);
  1769. }
  1770. }
  1771. // the sample transport would attach the hdlrFunc() when sending the
  1772. // request down the pipe at this point
  1773. var tgtURL = kwArgs.url+"?"+dojo.io.argsFromMap(kwArgs.content);
  1774. // sampleTransport.sendRequest(tgtURL, hdlrFunc);
  1775. }
  1776. dojo.io.transports.addTransport("sampleTranport");
  1777. }
  1778. */
  1779. dojo.provide("dojo.lang.array");
  1780. dojo.require("dojo.lang.common");
  1781. // FIXME: Is this worthless since you can do: if(name in obj)
  1782. // is this the right place for this?
  1783. dojo.lang.has = function(obj, name){
  1784. try{
  1785. return (typeof obj[name] != "undefined");
  1786. }catch(e){ return false; }
  1787. }
  1788. dojo.lang.isEmpty = function(obj) {
  1789. if(dojo.lang.isObject(obj)) {
  1790. var tmp = {};
  1791. var count = 0;
  1792. for(var x in obj){
  1793. if(obj[x] && (!tmp[x])){
  1794. count++;
  1795. break;
  1796. }
  1797. }
  1798. return (count == 0);
  1799. } else if(dojo.lang.isArrayLike(obj) || dojo.lang.isString(obj)) {
  1800. return obj.length == 0;
  1801. }
  1802. }
  1803. dojo.lang.map = function(arr, obj, unary_func){
  1804. var isString = dojo.lang.isString(arr);
  1805. if(isString){
  1806. arr = arr.split("");
  1807. }
  1808. if(dojo.lang.isFunction(obj)&&(!unary_func)){
  1809. unary_func = obj;
  1810. obj = dj_global;
  1811. }else if(dojo.lang.isFunction(obj) && unary_func){
  1812. // ff 1.5 compat
  1813. var tmpObj = obj;
  1814. obj = unary_func;
  1815. unary_func = tmpObj;
  1816. }
  1817. if(Array.map){
  1818. var outArr = Array.map(arr, unary_func, obj);
  1819. }else{
  1820. var outArr = [];
  1821. for(var i=0;i<arr.length;++i){
  1822. outArr.push(unary_func.call(obj, arr[i]));
  1823. }
  1824. }
  1825. if(isString) {
  1826. return outArr.join("");
  1827. } else {
  1828. return outArr;
  1829. }
  1830. }
  1831. // http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach
  1832. dojo.lang.forEach = function(anArray /* Array */, callback /* Function */, thisObject /* Object */){
  1833. if(dojo.lang.isString(anArray)){
  1834. anArray = anArray.split("");
  1835. }
  1836. if(Array.forEach){
  1837. Array.forEach(anArray, callback, thisObject);
  1838. }else{
  1839. // FIXME: there are several ways of handilng thisObject. Is dj_global always the default context?
  1840. if(!thisObject){
  1841. thisObject=dj_global;
  1842. }
  1843. for(var i=0,l=anArray.length; i<l; i++){
  1844. callback.call(thisObject, anArray[i], i, anArray);
  1845. }
  1846. }
  1847. }
  1848. dojo.lang._everyOrSome = function(every, arr, callback, thisObject){
  1849. if(dojo.lang.isString(arr)){
  1850. arr = arr.split("");
  1851. }
  1852. if(Array.every){
  1853. return Array[ (every) ? "every" : "some" ](arr, callback, thisObject);
  1854. }else{
  1855. if(!thisObject){
  1856. thisObject = dj_global;
  1857. }
  1858. for(var i=0,l=arr.length; i<l; i++){
  1859. var result = callback.call(thisObject, arr[i], i, arr);
  1860. if((every)&&(!result)){
  1861. return false;
  1862. }else if((!every)&&(result)){
  1863. return true;
  1864. }
  1865. }
  1866. return (every) ? true : false;
  1867. }
  1868. }
  1869. dojo.lang.every = function(arr, callback, thisObject){
  1870. return this._everyOrSome(true, arr, callback, thisObject);
  1871. }
  1872. dojo.lang.some = function(arr, callback, thisObject){
  1873. return this._everyOrSome(false, arr, callback, thisObject);
  1874. }
  1875. dojo.lang.filter = function(arr, callback, thisObject) {
  1876. var isString = dojo.lang.isString(arr);
  1877. if(isString) { arr = arr.split(""); }
  1878. if(Array.filter) {
  1879. var outArr = Array.filter(arr, callback, thisObject);
  1880. } else {
  1881. if(!thisObject) {
  1882. if(arguments.length >= 3) { dojo.raise("thisObject doesn't exist!"); }
  1883. thisObject = dj_global;
  1884. }
  1885. var outArr = [];
  1886. for(var i = 0; i < arr.length; i++) {
  1887. if(callback.call(thisObject, arr[i], i, arr)) {
  1888. outArr.push(arr[i]);
  1889. }
  1890. }
  1891. }
  1892. if(isString) {
  1893. return outArr.join("");
  1894. } else {
  1895. return outArr;
  1896. }
  1897. }
  1898. /**
  1899. * Creates a 1-D array out of all the arguments passed,
  1900. * unravelling any array-like objects in the process
  1901. *
  1902. * Ex:
  1903. * unnest(1, 2, 3) ==> [1, 2, 3]
  1904. * unnest(1, [2, [3], [[[4]]]]) ==> [1, 2, 3, 4]
  1905. */
  1906. dojo.lang.unnest = function(/* ... */) {
  1907. var out = [];
  1908. for(var i = 0; i < arguments.length; i++) {
  1909. if(dojo.lang.isArrayLike(arguments[i])) {
  1910. var add = dojo.lang.unnest.apply(this, arguments[i]);
  1911. out = out.concat(add);
  1912. } else {
  1913. out.push(arguments[i]);
  1914. }
  1915. }
  1916. return out;
  1917. }
  1918. /**
  1919. * Converts an array-like object (i.e. arguments, DOMCollection)
  1920. * to an array
  1921. **/
  1922. dojo.lang.toArray = function(arrayLike, startOffset) {
  1923. var array = [];
  1924. for(var i = startOffset||0; i < arrayLike.length; i++) {
  1925. array.push(arrayLike[i]);
  1926. }
  1927. return array;
  1928. }
  1929. dojo.provide("dojo.lang.func");
  1930. dojo.require("dojo.lang.common");
  1931. /**
  1932. * Runs a function in a given scope (thisObject), can
  1933. * also be used to preserve scope.
  1934. *
  1935. * hitch(foo, "bar"); // runs foo.bar() in the scope of foo
  1936. * hitch(foo, myFunction); // runs myFunction in the scope of foo
  1937. */
  1938. dojo.lang.hitch = function(thisObject, method) {
  1939. if(dojo.lang.isString(method)) {
  1940. var fcn = thisObject[method];
  1941. } else {
  1942. var fcn = method;
  1943. }
  1944. return function() {
  1945. return fcn.apply(thisObject, arguments);
  1946. }
  1947. }
  1948. dojo.lang.anonCtr = 0;
  1949. dojo.lang.anon = {};
  1950. dojo.lang.nameAnonFunc = function(anonFuncPtr, namespaceObj, searchForNames){
  1951. var nso = (namespaceObj || dojo.lang.anon);
  1952. if( (searchForNames) ||
  1953. ((dj_global["djConfig"])&&(djConfig["slowAnonFuncLookups"] == true)) ){
  1954. for(var x in nso){
  1955. if(nso[x] === anonFuncPtr){
  1956. return x;
  1957. }
  1958. }
  1959. }
  1960. var ret = "__"+dojo.lang.anonCtr++;
  1961. while(typeof nso[ret] != "undefined"){
  1962. ret = "__"+dojo.lang.anonCtr++;
  1963. }
  1964. nso[ret] = anonFuncPtr;
  1965. return ret;
  1966. }
  1967. dojo.lang.forward = function(funcName){
  1968. // Returns a function that forwards a method call to this.func(...)
  1969. return function(){
  1970. return this[funcName].apply(this, arguments);
  1971. };
  1972. }
  1973. dojo.lang.curry = function(ns, func /* args ... */){
  1974. var outerArgs = [];
  1975. ns = ns||dj_global;
  1976. if(dojo.lang.isString(func)){
  1977. func = ns[func];
  1978. }
  1979. for(var x=2; x<arguments.length; x++){
  1980. outerArgs.push(arguments[x]);
  1981. }
  1982. // since the event system replaces the original function with a new
  1983. // join-point runner with an arity of 0, we check to see if it's left us
  1984. // any clues about the original arity in lieu of the function's actual
  1985. // length property
  1986. var ecount = (func["__preJoinArity"]||func.length) - outerArgs.length;
  1987. // borrowed from svend tofte
  1988. function gather(nextArgs, innerArgs, expected){
  1989. var texpected = expected;
  1990. var totalArgs = innerArgs.slice(0); // copy
  1991. for(var x=0; x<nextArgs.length; x++){
  1992. totalArgs.push(nextArgs[x]);
  1993. }
  1994. // check the list of provided nextArgs to see if it, plus the
  1995. // number of innerArgs already supplied, meets the total
  1996. // expected.
  1997. expected = expected-nextArgs.length;
  1998. if(expected<=0){
  1999. var res = func.apply(ns, totalArgs);
  2000. expected = texpected;
  2001. return res;
  2002. }else{
  2003. return function(){
  2004. return gather(arguments,// check to see if we've been run
  2005. // with enough args
  2006. totalArgs, // a copy
  2007. expected); // how many more do we need to run?;
  2008. }
  2009. }
  2010. }
  2011. return gather([], outerArgs, ecount);
  2012. }
  2013. dojo.lang.curryArguments = function(ns, func, args, offset){
  2014. var targs = [];
  2015. var x = offset||0;
  2016. for(x=offset; x<args.length; x++){
  2017. targs.push(args[x]); // ensure that it's an arr
  2018. }
  2019. return dojo.lang.curry.apply(dojo.lang, [ns, func].concat(targs));
  2020. }
  2021. dojo.lang.tryThese = function(){
  2022. for(var x=0; x<arguments.length; x++){
  2023. try{
  2024. if(typeof arguments[x] == "function"){
  2025. var ret = (arguments[x]());
  2026. if(ret){
  2027. return ret;
  2028. }
  2029. }
  2030. }catch(e){
  2031. dojo.debug(e);
  2032. }
  2033. }
  2034. }
  2035. dojo.lang.delayThese = function(farr, cb, delay, onend){
  2036. /**
  2037. * alternate: (array funcArray, function callback, function onend)
  2038. * alternate: (array funcArray, function callback)
  2039. * alternate: (array funcArray)
  2040. */
  2041. if(!farr.length){
  2042. if(typeof onend == "function"){
  2043. onend();
  2044. }
  2045. return;
  2046. }
  2047. if((typeof delay == "undefined")&&(typeof cb == "number")){
  2048. delay = cb;
  2049. cb = function(){};
  2050. }else if(!cb){
  2051. cb = function(){};
  2052. if(!delay){ delay = 0; }
  2053. }
  2054. setTimeout(function(){
  2055. (farr.shift())();
  2056. cb();
  2057. dojo.lang.delayThese(farr, cb, delay, onend);
  2058. }, delay);
  2059. }
  2060. dojo.provide("dojo.string.extras");
  2061. dojo.require("dojo.string.common");
  2062. dojo.require("dojo.lang");
  2063. /**
  2064. * Performs parameterized substitutions on a string. For example,
  2065. * dojo.string.substituteParams("File '%{0}' is not found in directory '%{1}'.","foo.html","/temp");
  2066. * returns
  2067. * "File 'foo.html' is not found in directory '/temp'."
  2068. *
  2069. * @param template the original string template with %{values} to be replaced
  2070. * @param hash name/value pairs (type object) to provide substitutions. Alternatively, substitutions may be
  2071. * included as arguments 1..n to this function, corresponding to template parameters 0..n-1
  2072. * @return the completed string. Throws an exception if any parameter is unmatched
  2073. */
  2074. //TODO: use ${} substitution syntax instead, like widgets do?
  2075. dojo.string.substituteParams = function(template /*string */, hash /* object - optional or ... */) {
  2076. var map = (typeof hash == 'object') ? hash : dojo.lang.toArray(arguments, 1);
  2077. return template.replace(/\%\{(\w+)\}/g, function(match, key){
  2078. return map[key] || dojo.raise("Substitution not found: " + key);
  2079. });
  2080. };
  2081. /**
  2082. * Parameterized string function
  2083. * str - formatted string with %{values} to be replaces
  2084. * pairs - object of name: "value" value pairs
  2085. * killExtra - remove all remaining %{values} after pairs are inserted
  2086. */
  2087. dojo.string.paramString = function(str, pairs, killExtra) {
  2088. dojo.deprecated("dojo.string.paramString",
  2089. "use dojo.string.substituteParams instead", "0.4");
  2090. for(var name in pairs) {
  2091. var re = new RegExp("\\%\\{" + name + "\\}", "g");
  2092. str = str.replace(re, pairs[name]);
  2093. }
  2094. if(killExtra) { str = str.replace(/%\{([^\}\s]+)\}/g, ""); }
  2095. return str;
  2096. }
  2097. /** Uppercases the first letter of each word */
  2098. dojo.string.capitalize = function (str) {
  2099. if (!dojo.lang.isString(str)) { return ""; }
  2100. if (arguments.length == 0) { str = this; }
  2101. var words = str.split(' ');
  2102. for(var i=0; i<words.length; i++){
  2103. words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1);
  2104. }
  2105. return words.join(" ");
  2106. }
  2107. /**
  2108. * Return true if the entire string is whitespace characters
  2109. */
  2110. dojo.string.isBlank = function (str) {
  2111. if(!dojo.lang.isString(str)) { return true; }
  2112. return (dojo.string.trim(str).length == 0);
  2113. }
  2114. dojo.string.encodeAscii = function(str) {
  2115. if(!dojo.lang.isString(str)) { return str; }
  2116. var ret = "";
  2117. var value = escape(str);
  2118. var match, re = /%u([0-9A-F]{4})/i;
  2119. while((match = value.match(re))) {
  2120. var num = Number("0x"+match[1]);
  2121. var newVal = escape("&#" + num + ";");
  2122. ret += value.substring(0, match.index) + newVal;
  2123. value = value.substring(match.index+match[0].length);
  2124. }
  2125. ret += value.replace(/\+/g, "%2B");
  2126. return ret;
  2127. }
  2128. dojo.string.escape = function(type, str) {
  2129. var args = dojo.lang.toArray(arguments, 1);
  2130. switch(type.toLowerCase()) {
  2131. case "xml":
  2132. case "html":
  2133. case "xhtml":
  2134. return dojo.string.escapeXml.apply(this, args);
  2135. case "sql":
  2136. return dojo.string.escapeSql.apply(this, args);
  2137. case "regexp":
  2138. case "regex":
  2139. return dojo.string.escapeRegExp.apply(this, args);
  2140. case "javascript":
  2141. case "jscript":
  2142. case "js":
  2143. return dojo.string.escapeJavaScript.apply(this, args);
  2144. case "ascii":
  2145. // so it's encode, but it seems useful
  2146. return dojo.string.encodeAscii.apply(this, args);
  2147. default:
  2148. return str;
  2149. }
  2150. }
  2151. dojo.string.escapeXml = function(str, noSingleQuotes) {
  2152. str = str.replace(/&/gm, "&amp;").replace(/</gm, "&lt;")
  2153. .replace(/>/gm, "&gt;").replace(/"/gm, "&quot;");
  2154. if(!noSingleQuotes) { str = str.replace(/'/gm, "&#39;"); }
  2155. return str;
  2156. }
  2157. dojo.string.escapeSql = function(str) {
  2158. return str.replace(/'/gm, "''");
  2159. }
  2160. dojo.string.escapeRegExp = function(str) {
  2161. return str.replace(/\\/gm, "\\\\").replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1");
  2162. }
  2163. dojo.string.escapeJavaScript = function(str) {
  2164. return str.replace(/(["'\f\b\n\t\r])/gm, "\\$1");
  2165. }
  2166. dojo.string.escapeString = function(str){
  2167. return ('"' + str.replace(/(["\\])/g, '\\$1') + '"'
  2168. ).replace(/[\f]/g, "\\f"
  2169. ).replace(/[\b]/g, "\\b"
  2170. ).replace(/[\n]/g, "\\n"
  2171. ).replace(/[\t]/g, "\\t"
  2172. ).replace(/[\r]/g, "\\r");
  2173. }
  2174. // TODO: make an HTML version
  2175. dojo.string.summary = function(str, len) {
  2176. if(!len || str.length <= len) {
  2177. return str;
  2178. } else {
  2179. return str.substring(0, len).replace(/\.+$/, "") + "...";
  2180. }
  2181. }
  2182. /**
  2183. * Returns true if 'str' ends with 'end'
  2184. */
  2185. dojo.string.endsWith = function(str, end, ignoreCase) {
  2186. if(ignoreCase) {
  2187. str = str.toLowerCase();
  2188. end = end.toLowerCase();
  2189. }
  2190. if((str.length - end.length) < 0){
  2191. return false;
  2192. }
  2193. return str.lastIndexOf(end) == str.length - end.length;
  2194. }
  2195. /**
  2196. * Returns true if 'str' ends with any of the arguments[2 -> n]
  2197. */
  2198. dojo.string.endsWithAny = function(str /* , ... */) {
  2199. for(var i = 1; i < arguments.length; i++) {
  2200. if(dojo.string.endsWith(str, arguments[i])) {
  2201. return true;
  2202. }
  2203. }
  2204. return false;
  2205. }
  2206. /**
  2207. * Returns true if 'str' starts with 'start'
  2208. */
  2209. dojo.string.startsWith = function(str, start, ignoreCase) {
  2210. if(ignoreCase) {
  2211. str = str.toLowerCase();
  2212. start = start.toLowerCase();
  2213. }
  2214. return str.indexOf(start) == 0;
  2215. }
  2216. /**
  2217. * Returns true if 'str' starts with any of the arguments[2 -> n]
  2218. */
  2219. dojo.string.startsWithAny = function(str /* , ... */) {
  2220. for(var i = 1; i < arguments.length; i++) {
  2221. if(dojo.string.startsWith(str, arguments[i])) {
  2222. return true;
  2223. }
  2224. }
  2225. return false;
  2226. }
  2227. /**
  2228. * Returns true if 'str' contains any of the arguments 2 -> n
  2229. */
  2230. dojo.string.has = function(str /* , ... */) {
  2231. for(var i = 1; i < arguments.length; i++) {
  2232. if(str.indexOf(arguments[i]) > -1){
  2233. return true;
  2234. }
  2235. }
  2236. return false;
  2237. }
  2238. dojo.string.normalizeNewlines = function (text,newlineChar) {
  2239. if (newlineChar == "\n") {
  2240. text = text.replace(/\r\n/g, "\n");
  2241. text = text.replace(/\r/g, "\n");
  2242. } else if (newlineChar == "\r") {
  2243. text = text.replace(/\r\n/g, "\r");
  2244. text = text.replace(/\n/g, "\r");
  2245. } else {
  2246. text = text.replace(/([^\r])\n/g, "$1\r\n");
  2247. text = text.replace(/\r([^\n])/g, "\r\n$1");
  2248. }
  2249. return text;
  2250. }
  2251. dojo.string.splitEscaped = function (str,charac) {
  2252. var components = [];
  2253. for (var i = 0, prevcomma = 0; i < str.length; i++) {
  2254. if (str.charAt(i) == '\\') { i++; continue; }
  2255. if (str.charAt(i) == charac) {
  2256. components.push(str.substring(prevcomma, i));
  2257. prevcomma = i + 1;
  2258. }
  2259. }
  2260. components.push(str.substr(prevcomma));
  2261. return components;
  2262. }
  2263. dojo.provide("dojo.dom");
  2264. dojo.require("dojo.lang.array");
  2265. dojo.dom.ELEMENT_NODE = 1;
  2266. dojo.dom.ATTRIBUTE_NODE = 2;
  2267. dojo.dom.TEXT_NODE = 3;
  2268. dojo.dom.CDATA_SECTION_NODE = 4;
  2269. dojo.dom.ENTITY_REFERENCE_NODE = 5;
  2270. dojo.dom.ENTITY_NODE = 6;
  2271. dojo.dom.PROCESSING_INSTRUCTION_NODE = 7;
  2272. dojo.dom.COMMENT_NODE = 8;
  2273. dojo.dom.DOCUMENT_NODE = 9;
  2274. dojo.dom.DOCUMENT_TYPE_NODE = 10;
  2275. dojo.dom.DOCUMENT_FRAGMENT_NODE = 11;
  2276. dojo.dom.NOTATION_NODE = 12;
  2277. dojo.dom.dojoml = "http://www.dojotoolkit.org/2004/dojoml";
  2278. /**
  2279. * comprehensive list of XML namespaces
  2280. **/
  2281. dojo.dom.xmlns = {
  2282. svg : "http://www.w3.org/2000/svg",
  2283. smil : "http://www.w3.org/2001/SMIL20/",
  2284. mml : "http://www.w3.org/1998/Math/MathML",
  2285. cml : "http://www.xml-cml.org",
  2286. xlink : "http://www.w3.org/1999/xlink",
  2287. xhtml : "http://www.w3.org/1999/xhtml",
  2288. xul : "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  2289. xbl : "http://www.mozilla.org/xbl",
  2290. fo : "http://www.w3.org/1999/XSL/Format",
  2291. xsl : "http://www.w3.org/1999/XSL/Transform",
  2292. xslt : "http://www.w3.org/1999/XSL/Transform",
  2293. xi : "http://www.w3.org/2001/XInclude",
  2294. xforms : "http://www.w3.org/2002/01/xforms",
  2295. saxon : "http://icl.com/saxon",
  2296. xalan : "http://xml.apache.org/xslt",
  2297. xsd : "http://www.w3.org/2001/XMLSchema",
  2298. dt: "http://www.w3.org/2001/XMLSchema-datatypes",
  2299. xsi : "http://www.w3.org/2001/XMLSchema-instance",
  2300. rdf : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  2301. rdfs : "http://www.w3.org/2000/01/rdf-schema#",
  2302. dc : "http://purl.org/dc/elements/1.1/",
  2303. dcq: "http://purl.org/dc/qualifiers/1.0",
  2304. "soap-env" : "http://schemas.xmlsoap.org/soap/envelope/",
  2305. wsdl : "http://schemas.xmlsoap.org/wsdl/",
  2306. AdobeExtensions : "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
  2307. };
  2308. dojo.dom.isNode = function(wh){
  2309. if(typeof Element == "object") {
  2310. try {
  2311. return wh instanceof Element;
  2312. } catch(E) {}
  2313. } else {
  2314. // best-guess
  2315. return wh && !isNaN(wh.nodeType);
  2316. }
  2317. }
  2318. dojo.dom.getTagName = function(node){
  2319. dojo.deprecated("dojo.dom.getTagName", "use node.tagName instead", "0.4");
  2320. var tagName = node.tagName;
  2321. if(tagName.substr(0,5).toLowerCase()!="dojo:"){
  2322. if(tagName.substr(0,4).toLowerCase()=="dojo"){
  2323. // FIXME: this assuumes tag names are always lower case
  2324. return "dojo:" + tagName.substring(4).toLowerCase();
  2325. }
  2326. // allow lower-casing
  2327. var djt = node.getAttribute("dojoType")||node.getAttribute("dojotype");
  2328. if(djt){
  2329. return "dojo:"+djt.toLowerCase();
  2330. }
  2331. if((node.getAttributeNS)&&(node.getAttributeNS(this.dojoml,"type"))){
  2332. return "dojo:" + node.getAttributeNS(this.dojoml,"type").toLowerCase();
  2333. }
  2334. try{
  2335. // FIXME: IE really really doesn't like this, so we squelch
  2336. // errors for it
  2337. djt = node.getAttribute("dojo:type");
  2338. }catch(e){ /* FIXME: log? */ }
  2339. if(djt){
  2340. return "dojo:"+djt.toLowerCase();
  2341. }
  2342. if((!dj_global["djConfig"])||(!djConfig["ignoreClassNames"])){
  2343. // FIXME: should we make this optionally enabled via djConfig?
  2344. var classes = node.className||node.getAttribute("class");
  2345. // FIXME: following line, without check for existence of classes.indexOf
  2346. // breaks firefox 1.5's svg widgets
  2347. if((classes)&&(classes.indexOf)&&(classes.indexOf("dojo-") != -1)){
  2348. var aclasses = classes.split(" ");
  2349. for(var x=0; x<aclasses.length; x++){
  2350. if((aclasses[x].length>5)&&(aclasses[x].indexOf("dojo-")>=0)){
  2351. return "dojo:"+aclasses[x].substr(5).toLowerCase();
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. return tagName.toLowerCase();
  2358. }
  2359. dojo.dom.getUniqueId = function(){
  2360. do {
  2361. var id = "dj_unique_" + (++arguments.callee._idIncrement);
  2362. }while(document.getElementById(id));
  2363. return id;
  2364. }
  2365. dojo.dom.getUniqueId._idIncrement = 0;
  2366. dojo.dom.firstElement = dojo.dom.getFirstChildElement = function(parentNode, tagName){
  2367. var node = parentNode.firstChild;
  2368. while(node && node.nodeType != dojo.dom.ELEMENT_NODE){
  2369. node = node.nextSibling;
  2370. }
  2371. if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
  2372. node = dojo.dom.nextElement(node, tagName);
  2373. }
  2374. return node;
  2375. }
  2376. dojo.dom.lastElement = dojo.dom.getLastChildElement = function(parentNode, tagName){
  2377. var node = parentNode.lastChild;
  2378. while(node && node.nodeType != dojo.dom.ELEMENT_NODE) {
  2379. node = node.previousSibling;
  2380. }
  2381. if(tagName && node && node.tagName && node.tagName.toLowerCase() != tagName.toLowerCase()) {
  2382. node = dojo.dom.prevElement(node, tagName);
  2383. }
  2384. return node;
  2385. }
  2386. dojo.dom.nextElement = dojo.dom.getNextSiblingElement = function(node, tagName){
  2387. if(!node) { return null; }
  2388. do {
  2389. node = node.nextSibling;
  2390. } while(node && node.nodeType != dojo.dom.ELEMENT_NODE);
  2391. if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
  2392. return dojo.dom.nextElement(node, tagName);
  2393. }
  2394. return node;
  2395. }
  2396. dojo.dom.prevElement = dojo.dom.getPreviousSiblingElement = function(node, tagName){
  2397. if(!node) { return null; }
  2398. if(tagName) { tagName = tagName.toLowerCase(); }
  2399. do {
  2400. node = node.previousSibling;
  2401. } while(node && node.nodeType != dojo.dom.ELEMENT_NODE);
  2402. if(node && tagName && tagName.toLowerCase() != node.tagName.toLowerCase()) {
  2403. return dojo.dom.prevElement(node, tagName);
  2404. }
  2405. return node;
  2406. }
  2407. // TODO: hmph
  2408. /*this.forEachChildTag = function(node, unaryFunc) {
  2409. var child = this.getFirstChildTag(node);
  2410. while(child) {
  2411. if(unaryFunc(child) == "break") { break; }
  2412. child = this.getNextSiblingTag(child);
  2413. }
  2414. }*/
  2415. dojo.dom.moveChildren = function(srcNode, destNode, trim){
  2416. var count = 0;
  2417. if(trim) {
  2418. while(srcNode.hasChildNodes() &&
  2419. srcNode.firstChild.nodeType == dojo.dom.TEXT_NODE) {
  2420. srcNode.removeChild(srcNode.firstChild);
  2421. }
  2422. while(srcNode.hasChildNodes() &&
  2423. srcNode.lastChild.nodeType == dojo.dom.TEXT_NODE) {
  2424. srcNode.removeChild(srcNode.lastChild);
  2425. }
  2426. }
  2427. while(srcNode.hasChildNodes()){
  2428. destNode.appendChild(srcNode.firstChild);
  2429. count++;
  2430. }
  2431. return count;
  2432. }
  2433. dojo.dom.copyChildren = function(srcNode, destNode, trim){
  2434. var clonedNode = srcNode.cloneNode(true);
  2435. return this.moveChildren(clonedNode, destNode, trim);
  2436. }
  2437. dojo.dom.removeChildren = function(node){
  2438. var count = node.childNodes.length;
  2439. while(node.hasChildNodes()){ node.removeChild(node.firstChild); }
  2440. return count;
  2441. }
  2442. dojo.dom.replaceChildren = function(node, newChild){
  2443. // FIXME: what if newChild is an array-like object?
  2444. dojo.dom.removeChildren(node);
  2445. node.appendChild(newChild);
  2446. }
  2447. dojo.dom.removeNode = function(node){
  2448. if(node && node.parentNode){
  2449. // return a ref to the removed child
  2450. return node.parentNode.removeChild(node);
  2451. }
  2452. }
  2453. dojo.dom.getAncestors = function(node, filterFunction, returnFirstHit) {
  2454. var ancestors = [];
  2455. var isFunction = dojo.lang.isFunction(filterFunction);
  2456. while(node) {
  2457. if (!isFunction || filterFunction(node)) {
  2458. ancestors.push(node);
  2459. }
  2460. if (returnFirstHit && ancestors.length > 0) { return ancestors[0]; }
  2461. node = node.parentNode;
  2462. }
  2463. if (returnFirstHit) { return null; }
  2464. return ancestors;
  2465. }
  2466. dojo.dom.getAncestorsByTag = function(node, tag, returnFirstHit) {
  2467. tag = tag.toLowerCase();
  2468. return dojo.dom.getAncestors(node, function(el){
  2469. return ((el.tagName)&&(el.tagName.toLowerCase() == tag));
  2470. }, returnFirstHit);
  2471. }
  2472. dojo.dom.getFirstAncestorByTag = function(node, tag) {
  2473. return dojo.dom.getAncestorsByTag(node, tag, true);
  2474. }
  2475. dojo.dom.isDescendantOf = function(node, ancestor, guaranteeDescendant){
  2476. // guaranteeDescendant allows us to be a "true" isDescendantOf function
  2477. if(guaranteeDescendant && node) { node = node.parentNode; }
  2478. while(node) {
  2479. if(node == ancestor){ return true; }
  2480. node = node.parentNode;
  2481. }
  2482. return false;
  2483. }
  2484. dojo.dom.innerXML = function(node){
  2485. if(node.innerXML){
  2486. return node.innerXML;
  2487. }else if (node.xml){
  2488. return node.xml;
  2489. }else if(typeof XMLSerializer != "undefined"){
  2490. return (new XMLSerializer()).serializeToString(node);
  2491. }
  2492. }
  2493. dojo.dom.createDocument = function(){
  2494. var doc = null;
  2495. if(!dj_undef("ActiveXObject")){
  2496. var prefixes = [ "MSXML2", "Microsoft", "MSXML", "MSXML3" ];
  2497. for(var i = 0; i<prefixes.length; i++){
  2498. try{
  2499. doc = new ActiveXObject(prefixes[i]+".XMLDOM");
  2500. }catch(e){ /* squelch */ };
  2501. if(doc){ break; }
  2502. }
  2503. }else if((document.implementation)&&
  2504. (document.implementation.createDocument)){
  2505. doc = document.implementation.createDocument("", "", null);
  2506. }
  2507. return doc;
  2508. }
  2509. dojo.dom.createDocumentFromText = function(str, mimetype){
  2510. if(!mimetype){ mimetype = "text/xml"; }
  2511. if(!dj_undef("DOMParser")){
  2512. var parser = new DOMParser();
  2513. return parser.parseFromString(str, mimetype);
  2514. }else if(!dj_undef("ActiveXObject")){
  2515. var domDoc = dojo.dom.createDocument();
  2516. if(domDoc){
  2517. domDoc.async = false;
  2518. domDoc.loadXML(str);
  2519. return domDoc;
  2520. }else{
  2521. dojo.debug("toXml didn't work?");
  2522. }
  2523. /*
  2524. }else if((dojo.render.html.capable)&&(dojo.render.html.safari)){
  2525. // FIXME: this doesn't appear to work!
  2526. // from: http://web-graphics.com/mtarchive/001606.php
  2527. // var xml = '<?xml version="1.0"?>'+str;
  2528. var mtype = "text/xml";
  2529. var xml = '<?xml version="1.0"?>'+str;
  2530. var url = "data:"+mtype+";charset=utf-8,"+encodeURIComponent(xml);
  2531. var req = new XMLHttpRequest();
  2532. req.open("GET", url, false);
  2533. req.overrideMimeType(mtype);
  2534. req.send(null);
  2535. return req.responseXML;
  2536. */
  2537. }else if(document.createElement){
  2538. // FIXME: this may change all tags to uppercase!
  2539. var tmp = document.createElement("xml");
  2540. tmp.innerHTML = str;
  2541. if(document.implementation && document.implementation.createDocument) {
  2542. var xmlDoc = document.implementation.createDocument("foo", "", null);
  2543. for(var i = 0; i < tmp.childNodes.length; i++) {
  2544. xmlDoc.importNode(tmp.childNodes.item(i), true);
  2545. }
  2546. return xmlDoc;
  2547. }
  2548. // FIXME: probably not a good idea to have to return an HTML fragment
  2549. // FIXME: the tmp.doc.firstChild is as tested from IE, so it may not
  2550. // work that way across the board
  2551. return ((tmp.document)&&
  2552. (tmp.document.firstChild ? tmp.document.firstChild : tmp));
  2553. }
  2554. return null;
  2555. }
  2556. dojo.dom.prependChild = function(node, parent) {
  2557. if(parent.firstChild) {
  2558. parent.insertBefore(node, parent.firstChild);
  2559. } else {
  2560. parent.appendChild(node);
  2561. }
  2562. return true;
  2563. }
  2564. dojo.dom.insertBefore = function(node, ref, force){
  2565. if (force != true &&
  2566. (node === ref || node.nextSibling === ref)){ return false; }
  2567. var parent = ref.parentNode;
  2568. parent.insertBefore(node, ref);
  2569. return true;
  2570. }
  2571. dojo.dom.insertAfter = function(node, ref, force){
  2572. var pn = ref.parentNode;
  2573. if(ref == pn.lastChild){
  2574. if((force != true)&&(node === ref)){
  2575. return false;
  2576. }
  2577. pn.appendChild(node);
  2578. }else{
  2579. return this.insertBefore(node, ref.nextSibling, force);
  2580. }
  2581. return true;
  2582. }
  2583. dojo.dom.insertAtPosition = function(node, ref, position){
  2584. if((!node)||(!ref)||(!position)){ return false; }
  2585. switch(position.toLowerCase()){
  2586. case "before":
  2587. return dojo.dom.insertBefore(node, ref);
  2588. case "after":
  2589. return dojo.dom.insertAfter(node, ref);
  2590. case "first":
  2591. if(ref.firstChild){
  2592. return dojo.dom.insertBefore(node, ref.firstChild);
  2593. }else{
  2594. ref.appendChild(node);
  2595. return true;
  2596. }
  2597. break;
  2598. default: // aka: last
  2599. ref.appendChild(node);
  2600. return true;
  2601. }
  2602. }
  2603. dojo.dom.insertAtIndex = function(node, containingNode, insertionIndex){
  2604. var siblingNodes = containingNode.childNodes;
  2605. // if there aren't any kids yet, just add it to the beginning
  2606. if (!siblingNodes.length){
  2607. containingNode.appendChild(node);
  2608. return true;
  2609. }
  2610. // otherwise we need to walk the childNodes
  2611. // and find our spot
  2612. var after = null;
  2613. for(var i=0; i<siblingNodes.length; i++){
  2614. var sibling_index = siblingNodes.item(i)["getAttribute"] ? parseInt(siblingNodes.item(i).getAttribute("dojoinsertionindex")) : -1;
  2615. if (sibling_index < insertionIndex){
  2616. after = siblingNodes.item(i);
  2617. }
  2618. }
  2619. if (after){
  2620. // add it after the node in {after}
  2621. return dojo.dom.insertAfter(node, after);
  2622. }else{
  2623. // add it to the start
  2624. return dojo.dom.insertBefore(node, siblingNodes.item(0));
  2625. }
  2626. }
  2627. /**
  2628. * implementation of the DOM Level 3 attribute.
  2629. *
  2630. * @param node The node to scan for text
  2631. * @param text Optional, set the text to this value.
  2632. */
  2633. dojo.dom.textContent = function(node, text){
  2634. if (text) {
  2635. dojo.dom.replaceChildren(node, document.createTextNode(text));
  2636. return text;
  2637. } else {
  2638. var _result = "";
  2639. if (node == null) { return _result; }
  2640. for (var i = 0; i < node.childNodes.length; i++) {
  2641. switch (node.childNodes[i].nodeType) {
  2642. case 1: // ELEMENT_NODE
  2643. case 5: // ENTITY_REFERENCE_NODE
  2644. _result += dojo.dom.textContent(node.childNodes[i]);
  2645. break;
  2646. case 3: // TEXT_NODE
  2647. case 2: // ATTRIBUTE_NODE
  2648. case 4: // CDATA_SECTION_NODE
  2649. _result += node.childNodes[i].nodeValue;
  2650. break;
  2651. default:
  2652. break;
  2653. }
  2654. }
  2655. return _result;
  2656. }
  2657. }
  2658. dojo.dom.collectionToArray = function(collection){
  2659. dojo.deprecated("dojo.dom.collectionToArray", "use dojo.lang.toArray instead", "0.4");
  2660. return dojo.lang.toArray(collection);
  2661. }
  2662. dojo.dom.hasParent = function (node) {
  2663. return node && node.parentNode && dojo.dom.isNode(node.parentNode);
  2664. }
  2665. /**
  2666. * Determines if node has any of the provided tag names and
  2667. * returns the tag name that matches, empty string otherwise.
  2668. *
  2669. * Examples:
  2670. *
  2671. * myFooNode = <foo />
  2672. * isTag(myFooNode, "foo"); // returns "foo"
  2673. * isTag(myFooNode, "bar"); // returns ""
  2674. * isTag(myFooNode, "FOO"); // returns ""
  2675. * isTag(myFooNode, "hey", "foo", "bar"); // returns "foo"
  2676. **/
  2677. dojo.dom.isTag = function(node /* ... */) {
  2678. if(node && node.tagName) {
  2679. var arr = dojo.lang.toArray(arguments, 1);
  2680. return arr[ dojo.lang.find(node.tagName, arr) ] || "";
  2681. }
  2682. return "";
  2683. }
  2684. dojo.provide("dojo.undo.browser");
  2685. dojo.require("dojo.io");
  2686. try{
  2687. if((!djConfig["preventBackButtonFix"])&&(!dojo.hostenv.post_load_)){
  2688. document.write("<iframe style='border: 0px; width: 1px; height: 1px; position: absolute; bottom: 0px; right: 0px; visibility: visible;' name='djhistory' id='djhistory' src='"+(dojo.hostenv.getBaseScriptUri()+'iframe_history.html')+"'></iframe>");
  2689. }
  2690. }catch(e){/* squelch */}
  2691. if(dojo.render.html.opera){
  2692. dojo.debug("Opera is not supported with dojo.undo.browser, so back/forward detection will not work.");
  2693. }
  2694. /* NOTES:
  2695. * Safari 1.2:
  2696. * back button "works" fine, however it's not possible to actually
  2697. * DETECT that you've moved backwards by inspecting window.location.
  2698. * Unless there is some other means of locating.
  2699. * FIXME: perhaps we can poll on history.length?
  2700. * Safari 2.0.3+ (and probably 1.3.2+):
  2701. * works fine, except when changeUrl is used. When changeUrl is used,
  2702. * Safari jumps all the way back to whatever page was shown before
  2703. * the page that uses dojo.undo.browser support.
  2704. * IE 5.5 SP2:
  2705. * back button behavior is macro. It does not move back to the
  2706. * previous hash value, but to the last full page load. This suggests
  2707. * that the iframe is the correct way to capture the back button in
  2708. * these cases.
  2709. * Don't test this page using local disk for MSIE. MSIE will not create
  2710. * a history list for iframe_history.html if served from a file: URL.
  2711. * The XML served back from the XHR tests will also not be properly
  2712. * created if served from local disk. Serve the test pages from a web
  2713. * server to test in that browser.
  2714. * IE 6.0:
  2715. * same behavior as IE 5.5 SP2
  2716. * Firefox 1.0:
  2717. * the back button will return us to the previous hash on the same
  2718. * page, thereby not requiring an iframe hack, although we do then
  2719. * need to run a timer to detect inter-page movement.
  2720. */
  2721. dojo.undo.browser = {
  2722. initialHref: window.location.href,
  2723. initialHash: window.location.hash,
  2724. moveForward: false,
  2725. historyStack: [],
  2726. forwardStack: [],
  2727. historyIframe: null,
  2728. bookmarkAnchor: null,
  2729. locationTimer: null,
  2730. /**
  2731. * setInitialState sets the state object and back callback for the very first page that is loaded.
  2732. * It is recommended that you call this method as part of an event listener that is registered via
  2733. * dojo.addOnLoad().
  2734. */
  2735. setInitialState: function(args){
  2736. this.initialState = {"url": this.initialHref, "kwArgs": args, "urlHash": this.initialHash};
  2737. },
  2738. //FIXME: Would like to support arbitrary back/forward jumps. Have to rework iframeLoaded among other things.
  2739. //FIXME: is there a slight race condition in moz using change URL with the timer check and when
  2740. // the hash gets set? I think I have seen a back/forward call in quick succession, but not consistent.
  2741. /**
  2742. * addToHistory takes one argument, and it is an object that defines the following functions:
  2743. * - To support getting back button notifications, the object argument should implement a
  2744. * function called either "back", "backButton", or "handle". The string "back" will be
  2745. * passed as the first and only argument to this callback.
  2746. * - To support getting forward button notifications, the object argument should implement a
  2747. * function called either "forward", "forwardButton", or "handle". The string "forward" will be
  2748. * passed as the first and only argument to this callback.
  2749. * - If you want the browser location string to change, define "changeUrl" on the object. If the
  2750. * value of "changeUrl" is true, then a unique number will be appended to the URL as a fragment
  2751. * identifier (http://some.domain.com/path#uniquenumber). If it is any other value that does
  2752. * not evaluate to false, that value will be used as the fragment identifier. For example,
  2753. * if changeUrl: 'page1', then the URL will look like: http://some.domain.com/path#page1
  2754. *
  2755. * Full example:
  2756. *
  2757. * dojo.undo.browser.addToHistory({
  2758. * back: function() { alert('back pressed'); },
  2759. * forward: function() { alert('forward pressed'); },
  2760. * changeUrl: true
  2761. * });
  2762. */
  2763. addToHistory: function(args){
  2764. var hash = null;
  2765. if(!this.historyIframe){
  2766. this.historyIframe = window.frames["djhistory"];
  2767. }
  2768. if(!this.bookmarkAnchor){
  2769. this.bookmarkAnchor = document.createElement("a");
  2770. (document.body||document.getElementsByTagName("body")[0]).appendChild(this.bookmarkAnchor);
  2771. this.bookmarkAnchor.style.display = "none";
  2772. }
  2773. if((!args["changeUrl"])||(dojo.render.html.ie)){
  2774. var url = dojo.hostenv.getBaseScriptUri()+"iframe_history.html?"+(new Date()).getTime();
  2775. this.moveForward = true;
  2776. dojo.io.setIFrameSrc(this.historyIframe, url, false);
  2777. }
  2778. if(args["changeUrl"]){
  2779. this.changingUrl = true;
  2780. hash = "#"+ ((args["changeUrl"]!==true) ? args["changeUrl"] : (new Date()).getTime());
  2781. setTimeout("window.location.href = '"+hash+"'; dojo.undo.browser.changingUrl = false;", 1);
  2782. this.bookmarkAnchor.href = hash;
  2783. if(dojo.render.html.ie){
  2784. var oldCB = args["back"]||args["backButton"]||args["handle"];
  2785. //The function takes handleName as a parameter, in case the
  2786. //callback we are overriding was "handle". In that case,
  2787. //we will need to pass the handle name to handle.
  2788. var tcb = function(handleName){
  2789. if(window.location.hash != ""){
  2790. setTimeout("window.location.href = '"+hash+"';", 1);
  2791. }
  2792. //Use apply to set "this" to args, and to try to avoid memory leaks.
  2793. oldCB.apply(this, [handleName]);
  2794. }
  2795. //Set interceptor function in the right place.
  2796. if(args["back"]){
  2797. args.back = tcb;
  2798. }else if(args["backButton"]){
  2799. args.backButton = tcb;
  2800. }else if(args["handle"]){
  2801. args.handle = tcb;
  2802. }
  2803. //If addToHistory is called, then that means we prune the
  2804. //forward stack -- the user went back, then wanted to
  2805. //start a new forward path.
  2806. this.forwardStack = [];
  2807. var oldFW = args["forward"]||args["forwardButton"]||args["handle"];
  2808. //The function takes handleName as a parameter, in case the
  2809. //callback we are overriding was "handle". In that case,
  2810. //we will need to pass the handle name to handle.
  2811. var tfw = function(handleName){
  2812. if(window.location.hash != ""){
  2813. window.location.href = hash;
  2814. }
  2815. if(oldFW){ // we might not actually have one
  2816. //Use apply to set "this" to args, and to try to avoid memory leaks.
  2817. oldFW.apply(this, [handleName]);
  2818. }
  2819. }
  2820. //Set interceptor function in the right place.
  2821. if(args["forward"]){
  2822. args.forward = tfw;
  2823. }else if(args["forwardButton"]){
  2824. args.forwardButton = tfw;
  2825. }else if(args["handle"]){
  2826. args.handle = tfw;
  2827. }
  2828. }else if(dojo.render.html.moz){
  2829. // start the timer
  2830. if(!this.locationTimer){
  2831. this.locationTimer = setInterval("dojo.undo.browser.checkLocation();", 200);
  2832. }
  2833. }
  2834. }
  2835. this.historyStack.push({"url": url, "kwArgs": args, "urlHash": hash});
  2836. },
  2837. checkLocation: function(){
  2838. if (!this.changingUrl){
  2839. var hsl = this.historyStack.length;
  2840. if((window.location.hash == this.initialHash||window.location.href == this.initialHref)&&(hsl == 1)){
  2841. // FIXME: could this ever be a forward button?
  2842. // we can't clear it because we still need to check for forwards. Ugg.
  2843. // clearInterval(this.locationTimer);
  2844. this.handleBackButton();
  2845. return;
  2846. }
  2847. // first check to see if we could have gone forward. We always halt on
  2848. // a no-hash item.
  2849. if(this.forwardStack.length > 0){
  2850. if(this.forwardStack[this.forwardStack.length-1].urlHash == window.location.hash){
  2851. this.handleForwardButton();
  2852. return;
  2853. }
  2854. }
  2855. // ok, that didn't work, try someplace back in the history stack
  2856. if((hsl >= 2)&&(this.historyStack[hsl-2])){
  2857. if(this.historyStack[hsl-2].urlHash==window.location.hash){
  2858. this.handleBackButton();
  2859. return;
  2860. }
  2861. }
  2862. }
  2863. },
  2864. iframeLoaded: function(evt, ifrLoc){
  2865. if(!dojo.render.html.opera){
  2866. var query = this._getUrlQuery(ifrLoc.href);
  2867. if(query == null){
  2868. // alert("iframeLoaded");
  2869. // we hit the end of the history, so we should go back
  2870. if(this.historyStack.length == 1){
  2871. this.handleBackButton();
  2872. }
  2873. return;
  2874. }
  2875. if(this.moveForward){
  2876. // we were expecting it, so it's not either a forward or backward movement
  2877. this.moveForward = false;
  2878. return;
  2879. }
  2880. //Check the back stack first, since it is more likely.
  2881. //Note that only one step back or forward is supported.
  2882. if(this.historyStack.length >= 2 && query == this._getUrlQuery(this.historyStack[this.historyStack.length-2].url)){
  2883. this.handleBackButton();
  2884. }
  2885. else if(this.forwardStack.length > 0 && query == this._getUrlQuery(this.forwardStack[this.forwardStack.length-1].url)){
  2886. this.handleForwardButton();
  2887. }
  2888. }
  2889. },
  2890. handleBackButton: function(){
  2891. //The "current" page is always at the top of the history stack.
  2892. var current = this.historyStack.pop();
  2893. if(!current){ return; }
  2894. var last = this.historyStack[this.historyStack.length-1];
  2895. if(!last && this.historyStack.length == 0){
  2896. last = this.initialState;
  2897. }
  2898. if (last){
  2899. if(last.kwArgs["back"]){
  2900. last.kwArgs["back"]();
  2901. }else if(last.kwArgs["backButton"]){
  2902. last.kwArgs["backButton"]();
  2903. }else if(last.kwArgs["handle"]){
  2904. last.kwArgs.handle("back");
  2905. }
  2906. }
  2907. this.forwardStack.push(current);
  2908. },
  2909. handleForwardButton: function(){
  2910. var last = this.forwardStack.pop();
  2911. if(!last){ return; }
  2912. if(last.kwArgs["forward"]){
  2913. last.kwArgs.forward();
  2914. }else if(last.kwArgs["forwardButton"]){
  2915. last.kwArgs.forwardButton();
  2916. }else if(last.kwArgs["handle"]){
  2917. last.kwArgs.handle("forward");
  2918. }
  2919. this.historyStack.push(last);
  2920. },
  2921. _getUrlQuery: function(url){
  2922. var segments = url.split("?");
  2923. if (segments.length < 2){
  2924. return null;
  2925. }
  2926. else{
  2927. return segments[1];
  2928. }
  2929. }
  2930. }
  2931. dojo.provide("dojo.io.BrowserIO");
  2932. dojo.require("dojo.io");
  2933. dojo.require("dojo.lang.array");
  2934. dojo.require("dojo.lang.func");
  2935. dojo.require("dojo.string.extras");
  2936. dojo.require("dojo.dom");
  2937. dojo.require("dojo.undo.browser");
  2938. dojo.io.checkChildrenForFile = function(node){
  2939. var hasFile = false;
  2940. var inputs = node.getElementsByTagName("input");
  2941. dojo.lang.forEach(inputs, function(input){
  2942. if(hasFile){ return; }
  2943. if(input.getAttribute("type")=="file"){
  2944. hasFile = true;
  2945. }
  2946. });
  2947. return hasFile;
  2948. }
  2949. dojo.io.formHasFile = function(formNode){
  2950. return dojo.io.checkChildrenForFile(formNode);
  2951. }
  2952. dojo.io.updateNode = function(node, urlOrArgs){
  2953. node = dojo.byId(node);
  2954. var args = urlOrArgs;
  2955. if(dojo.lang.isString(urlOrArgs)){
  2956. args = { url: urlOrArgs };
  2957. }
  2958. args.mimetype = "text/html";
  2959. args.load = function(t, d, e){
  2960. while(node.firstChild){
  2961. if(dojo["event"]){
  2962. try{
  2963. dojo.event.browser.clean(node.firstChild);
  2964. }catch(e){}
  2965. }
  2966. node.removeChild(node.firstChild);
  2967. }
  2968. node.innerHTML = d;
  2969. };
  2970. dojo.io.bind(args);
  2971. }
  2972. dojo.io.formFilter = function(node) {
  2973. var type = (node.type||"").toLowerCase();
  2974. return !node.disabled && node.name
  2975. && !dojo.lang.inArray(type, ["file", "submit", "image", "reset", "button"]);
  2976. }
  2977. // TODO: Move to htmlUtils
  2978. dojo.io.encodeForm = function(formNode, encoding, formFilter){
  2979. if((!formNode)||(!formNode.tagName)||(!formNode.tagName.toLowerCase() == "form")){
  2980. dojo.raise("Attempted to encode a non-form element.");
  2981. }
  2982. if(!formFilter) { formFilter = dojo.io.formFilter; }
  2983. var enc = /utf/i.test(encoding||"") ? encodeURIComponent : dojo.string.encodeAscii;
  2984. var values = [];
  2985. for(var i = 0; i < formNode.elements.length; i++){
  2986. var elm = formNode.elements[i];
  2987. if(!elm || elm.tagName.toLowerCase() == "fieldset" || !formFilter(elm)) { continue; }
  2988. var name = enc(elm.name);
  2989. var type = elm.type.toLowerCase();
  2990. if(type == "select-multiple"){
  2991. for(var j = 0; j < elm.options.length; j++){
  2992. if(elm.options[j].selected) {
  2993. values.push(name + "=" + enc(elm.options[j].value));
  2994. }
  2995. }
  2996. }else if(dojo.lang.inArray(type, ["radio", "checkbox"])){
  2997. if(elm.checked){
  2998. values.push(name + "=" + enc(elm.value));
  2999. }
  3000. }else{
  3001. values.push(name + "=" + enc(elm.value));
  3002. }
  3003. }
  3004. // now collect input type="image", which doesn't show up in the elements array
  3005. var inputs = formNode.getElementsByTagName("input");
  3006. for(var i = 0; i < inputs.length; i++) {
  3007. var input = inputs[i];
  3008. if(input.type.toLowerCase() == "image" && input.form == formNode
  3009. && formFilter(input)) {
  3010. var name = enc(input.name);
  3011. values.push(name + "=" + enc(input.value));
  3012. values.push(name + ".x=0");
  3013. values.push(name + ".y=0");
  3014. }
  3015. }
  3016. return values.join("&") + "&";
  3017. }
  3018. dojo.io.FormBind = function(args) {
  3019. this.bindArgs = {};
  3020. if(args && args.formNode) {
  3021. this.init(args);
  3022. } else if(args) {
  3023. this.init({formNode: args});
  3024. }
  3025. }
  3026. dojo.lang.extend(dojo.io.FormBind, {
  3027. form: null,
  3028. bindArgs: null,
  3029. clickedButton: null,
  3030. init: function(args) {
  3031. var form = dojo.byId(args.formNode);
  3032. if(!form || !form.tagName || form.tagName.toLowerCase() != "form") {
  3033. throw new Error("FormBind: Couldn't apply, invalid form");
  3034. } else if(this.form == form) {
  3035. return;
  3036. } else if(this.form) {
  3037. throw new Error("FormBind: Already applied to a form");
  3038. }
  3039. dojo.lang.mixin(this.bindArgs, args);
  3040. this.form = form;
  3041. this.connect(form, "onsubmit", "submit");
  3042. for(var i = 0; i < form.elements.length; i++) {
  3043. var node = form.elements[i];
  3044. if(node && node.type && dojo.lang.inArray(node.type.toLowerCase(), ["submit", "button"])) {
  3045. this.connect(node, "onclick", "click");
  3046. }
  3047. }
  3048. var inputs = form.getElementsByTagName("input");
  3049. for(var i = 0; i < inputs.length; i++) {
  3050. var input = inputs[i];
  3051. if(input.type.toLowerCase() == "image" && input.form == form) {
  3052. this.connect(input, "onclick", "click");
  3053. }
  3054. }
  3055. },
  3056. onSubmit: function(form) {
  3057. return true;
  3058. },
  3059. submit: function(e) {
  3060. e.preventDefault();
  3061. if(this.onSubmit(this.form)) {
  3062. dojo.io.bind(dojo.lang.mixin(this.bindArgs, {
  3063. formFilter: dojo.lang.hitch(this, "formFilter")
  3064. }));
  3065. }
  3066. },
  3067. click: function(e) {
  3068. var node = e.currentTarget;
  3069. if(node.disabled) { return; }
  3070. this.clickedButton = node;
  3071. },
  3072. formFilter: function(node) {
  3073. var type = (node.type||"").toLowerCase();
  3074. var accept = false;
  3075. if(node.disabled || !node.name) {
  3076. accept = false;
  3077. } else if(dojo.lang.inArray(type, ["submit", "button", "image"])) {
  3078. if(!this.clickedButton) { this.clickedButton = node; }
  3079. accept = node == this.clickedButton;
  3080. } else {
  3081. accept = !dojo.lang.inArray(type, ["file", "submit", "reset", "button"]);
  3082. }
  3083. return accept;
  3084. },
  3085. // in case you don't have dojo.event.* pulled in
  3086. connect: function(srcObj, srcFcn, targetFcn) {
  3087. if(dojo.evalObjPath("dojo.event.connect")) {
  3088. dojo.event.connect(srcObj, srcFcn, this, targetFcn);
  3089. } else {
  3090. var fcn = dojo.lang.hitch(this, targetFcn);
  3091. srcObj[srcFcn] = function(e) {
  3092. if(!e) { e = window.event; }
  3093. if(!e.currentTarget) { e.currentTarget = e.srcElement; }
  3094. if(!e.preventDefault) { e.preventDefault = function() { window.event.returnValue = false; } }
  3095. fcn(e);
  3096. }
  3097. }
  3098. }
  3099. });
  3100. dojo.io.XMLHTTPTransport = new function(){
  3101. var _this = this;
  3102. var _cache = {}; // FIXME: make this public? do we even need to?
  3103. this.useCache = false; // if this is true, we'll cache unless kwArgs.useCache = false
  3104. this.preventCache = false; // if this is true, we'll always force GET requests to cache
  3105. // FIXME: Should this even be a function? or do we just hard code it in the next 2 functions?
  3106. function getCacheKey(url, query, method) {
  3107. return url + "|" + query + "|" + method.toLowerCase();
  3108. }
  3109. function addToCache(url, query, method, http) {
  3110. _cache[getCacheKey(url, query, method)] = http;
  3111. }
  3112. function getFromCache(url, query, method) {
  3113. return _cache[getCacheKey(url, query, method)];
  3114. }
  3115. this.clearCache = function() {
  3116. _cache = {};
  3117. }
  3118. // moved successful load stuff here
  3119. function doLoad(kwArgs, http, url, query, useCache) {
  3120. if( ((http.status>=200)&&(http.status<300))|| // allow any 2XX response code
  3121. (http.status==304)|| // get it out of the cache
  3122. (location.protocol=="file:" && (http.status==0 || http.status==undefined))||
  3123. (location.protocol=="chrome:" && (http.status==0 || http.status==undefined))
  3124. ){
  3125. var ret;
  3126. if(kwArgs.method.toLowerCase() == "head"){
  3127. var headers = http.getAllResponseHeaders();
  3128. ret = {};
  3129. ret.toString = function(){ return headers; }
  3130. var values = headers.split(/[\r\n]+/g);
  3131. for(var i = 0; i < values.length; i++) {
  3132. var pair = values[i].match(/^([^:]+)\s*:\s*(.+)$/i);
  3133. if(pair) {
  3134. ret[pair[1]] = pair[2];
  3135. }
  3136. }
  3137. }else if(kwArgs.mimetype == "text/javascript"){
  3138. try{
  3139. ret = dj_eval(http.responseText);
  3140. }catch(e){
  3141. dojo.debug(e);
  3142. dojo.debug(http.responseText);
  3143. ret = null;
  3144. }
  3145. }else if(kwArgs.mimetype == "text/json"){
  3146. try{
  3147. ret = dj_eval("("+http.responseText+")");
  3148. }catch(e){
  3149. dojo.debug(e);
  3150. dojo.debug(http.responseText);
  3151. ret = false;
  3152. }
  3153. }else if((kwArgs.mimetype == "application/xml")||
  3154. (kwArgs.mimetype == "text/xml")){
  3155. ret = http.responseXML;
  3156. if(!ret || typeof ret == "string" || !http.getResponseHeader("Content-Type")) {
  3157. ret = dojo.dom.createDocumentFromText(http.responseText);
  3158. }
  3159. }else{
  3160. ret = http.responseText;
  3161. }
  3162. if(useCache){ // only cache successful responses
  3163. addToCache(url, query, kwArgs.method, http);
  3164. }
  3165. kwArgs[(typeof kwArgs.load == "function") ? "load" : "handle"]("load", ret, http, kwArgs);
  3166. }else{
  3167. var errObj = new dojo.io.Error("XMLHttpTransport Error: "+http.status+" "+http.statusText);
  3168. kwArgs[(typeof kwArgs.error == "function") ? "error" : "handle"]("error", errObj, http, kwArgs);
  3169. }
  3170. }
  3171. // set headers (note: Content-Type will get overriden if kwArgs.contentType is set)
  3172. function setHeaders(http, kwArgs){
  3173. if(kwArgs["headers"]) {
  3174. for(var header in kwArgs["headers"]) {
  3175. if(header.toLowerCase() == "content-type" && !kwArgs["contentType"]) {
  3176. kwArgs["contentType"] = kwArgs["headers"][header];
  3177. } else {
  3178. http.setRequestHeader(header, kwArgs["headers"][header]);
  3179. }
  3180. }
  3181. }
  3182. }
  3183. this.inFlight = [];
  3184. this.inFlightTimer = null;
  3185. this.startWatchingInFlight = function(){
  3186. if(!this.inFlightTimer){
  3187. this.inFlightTimer = setInterval("dojo.io.XMLHTTPTransport.watchInFlight();", 10);
  3188. }
  3189. }
  3190. this.watchInFlight = function(){
  3191. var now = null;
  3192. for(var x=this.inFlight.length-1; x>=0; x--){
  3193. var tif = this.inFlight[x];
  3194. if(!tif){ this.inFlight.splice(x, 1); continue; }
  3195. if(4==tif.http.readyState){
  3196. // remove it so we can clean refs
  3197. this.inFlight.splice(x, 1);
  3198. doLoad(tif.req, tif.http, tif.url, tif.query, tif.useCache);
  3199. }else if (tif.startTime){
  3200. //See if this is a timeout case.
  3201. if(!now){
  3202. now = (new Date()).getTime();
  3203. }
  3204. if(tif.startTime + (tif.req.timeoutSeconds * 1000) < now){
  3205. //Stop the request.
  3206. if(typeof tif.http.abort == "function"){
  3207. tif.http.abort();
  3208. }
  3209. // remove it so we can clean refs
  3210. this.inFlight.splice(x, 1);
  3211. tif.req[(typeof tif.req.timeout == "function") ? "timeout" : "handle"]("timeout", null, tif.http, tif.req);
  3212. }
  3213. }
  3214. }
  3215. if(this.inFlight.length == 0){
  3216. clearInterval(this.inFlightTimer);
  3217. this.inFlightTimer = null;
  3218. }
  3219. }
  3220. var hasXmlHttp = dojo.hostenv.getXmlhttpObject() ? true : false;
  3221. this.canHandle = function(kwArgs){
  3222. // canHandle just tells dojo.io.bind() if this is a good transport to
  3223. // use for the particular type of request.
  3224. // FIXME: we need to determine when form values need to be
  3225. // multi-part mime encoded and avoid using this transport for those
  3226. // requests.
  3227. return hasXmlHttp
  3228. && dojo.lang.inArray((kwArgs["mimetype"].toLowerCase()||""), ["text/plain", "text/html", "application/xml", "text/xml", "text/javascript", "text/json"])
  3229. && !( kwArgs["formNode"] && dojo.io.formHasFile(kwArgs["formNode"]) );
  3230. }
  3231. this.multipartBoundary = "45309FFF-BD65-4d50-99C9-36986896A96F"; // unique guid as a boundary value for multipart posts
  3232. this.bind = function(kwArgs){
  3233. if(!kwArgs["url"]){
  3234. // are we performing a history action?
  3235. if( !kwArgs["formNode"]
  3236. && (kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"] || kwArgs["watchForURL"])
  3237. && (!djConfig.preventBackButtonFix)) {
  3238. dojo.deprecated("Using dojo.io.XMLHTTPTransport.bind() to add to browser history without doing an IO request",
  3239. "Use dojo.undo.browser.addToHistory() instead.", "0.4");
  3240. dojo.undo.browser.addToHistory(kwArgs);
  3241. return true;
  3242. }
  3243. }
  3244. // build this first for cache purposes
  3245. var url = kwArgs.url;
  3246. var query = "";
  3247. if(kwArgs["formNode"]){
  3248. var ta = kwArgs.formNode.getAttribute("action");
  3249. if((ta)&&(!kwArgs["url"])){ url = ta; }
  3250. var tp = kwArgs.formNode.getAttribute("method");
  3251. if((tp)&&(!kwArgs["method"])){ kwArgs.method = tp; }
  3252. query += dojo.io.encodeForm(kwArgs.formNode, kwArgs.encoding, kwArgs["formFilter"]);
  3253. }
  3254. if(url.indexOf("#") > -1) {
  3255. dojo.debug("Warning: dojo.io.bind: stripping hash values from url:", url);
  3256. url = url.split("#")[0];
  3257. }
  3258. if(kwArgs["file"]){
  3259. // force post for file transfer
  3260. kwArgs.method = "post";
  3261. }
  3262. if(!kwArgs["method"]){
  3263. kwArgs.method = "get";
  3264. }
  3265. // guess the multipart value
  3266. if(kwArgs.method.toLowerCase() == "get"){
  3267. // GET cannot use multipart
  3268. kwArgs.multipart = false;
  3269. }else{
  3270. if(kwArgs["file"]){
  3271. // enforce multipart when sending files
  3272. kwArgs.multipart = true;
  3273. }else if(!kwArgs["multipart"]){
  3274. // default
  3275. kwArgs.multipart = false;
  3276. }
  3277. }
  3278. if(kwArgs["backButton"] || kwArgs["back"] || kwArgs["changeUrl"]){
  3279. dojo.undo.browser.addToHistory(kwArgs);
  3280. }
  3281. var content = kwArgs["content"] || {};
  3282. if(kwArgs.sendTransport) {
  3283. content["dojo.transport"] = "xmlhttp";
  3284. }
  3285. do { // break-block
  3286. if(kwArgs.postContent){
  3287. query = kwArgs.postContent;
  3288. break;
  3289. }
  3290. if(content) {
  3291. query += dojo.io.argsFromMap(content, kwArgs.encoding);
  3292. }
  3293. if(kwArgs.method.toLowerCase() == "get" || !kwArgs.multipart){
  3294. break;
  3295. }
  3296. var t = [];
  3297. if(query.length){
  3298. var q = query.split("&");
  3299. for(var i = 0; i < q.length; ++i){
  3300. if(q[i].length){
  3301. var p = q[i].split("=");
  3302. t.push( "--" + this.multipartBoundary,
  3303. "Content-Disposition: form-data; name=\"" + p[0] + "\"",
  3304. "",
  3305. p[1]);
  3306. }
  3307. }
  3308. }
  3309. if(kwArgs.file){
  3310. if(dojo.lang.isArray(kwArgs.file)){
  3311. for(var i = 0; i < kwArgs.file.length; ++i){
  3312. var o = kwArgs.file[i];
  3313. t.push( "--" + this.multipartBoundary,
  3314. "Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",
  3315. "Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),
  3316. "",
  3317. o.content);
  3318. }
  3319. }else{
  3320. var o = kwArgs.file;
  3321. t.push( "--" + this.multipartBoundary,
  3322. "Content-Disposition: form-data; name=\"" + o.name + "\"; filename=\"" + ("fileName" in o ? o.fileName : o.name) + "\"",
  3323. "Content-Type: " + ("contentType" in o ? o.contentType : "application/octet-stream"),
  3324. "",
  3325. o.content);
  3326. }
  3327. }
  3328. if(t.length){
  3329. t.push("--"+this.multipartBoundary+"--", "");
  3330. query = t.join("\r\n");
  3331. }
  3332. }while(false);
  3333. // kwArgs.Connection = "close";
  3334. var async = kwArgs["sync"] ? false : true;
  3335. var preventCache = kwArgs["preventCache"] ||
  3336. (this.preventCache == true && kwArgs["preventCache"] != false);
  3337. var useCache = kwArgs["useCache"] == true ||
  3338. (this.useCache == true && kwArgs["useCache"] != false );
  3339. // preventCache is browser-level (add query string junk), useCache
  3340. // is for the local cache. If we say preventCache, then don't attempt
  3341. // to look in the cache, but if useCache is true, we still want to cache
  3342. // the response
  3343. if(!preventCache && useCache){
  3344. var cachedHttp = getFromCache(url, query, kwArgs.method);
  3345. if(cachedHttp){
  3346. doLoad(kwArgs, cachedHttp, url, query, false);
  3347. return;
  3348. }
  3349. }
  3350. // much of this is from getText, but reproduced here because we need
  3351. // more flexibility
  3352. var http = dojo.hostenv.getXmlhttpObject(kwArgs);
  3353. var received = false;
  3354. // build a handler function that calls back to the handler obj
  3355. if(async){
  3356. var startTime =
  3357. // FIXME: setting up this callback handler leaks on IE!!!
  3358. this.inFlight.push({
  3359. "req": kwArgs,
  3360. "http": http,
  3361. "url": url,
  3362. "query": query,
  3363. "useCache": useCache,
  3364. "startTime": kwArgs.timeoutSeconds ? (new Date()).getTime() : 0
  3365. });
  3366. this.startWatchingInFlight();
  3367. }
  3368. if(kwArgs.method.toLowerCase() == "post"){
  3369. // FIXME: need to hack in more flexible Content-Type setting here!
  3370. http.open("POST", url, async);
  3371. setHeaders(http, kwArgs);
  3372. http.setRequestHeader("Content-Type", kwArgs.multipart ? ("multipart/form-data; boundary=" + this.multipartBoundary) :
  3373. (kwArgs.contentType || "application/x-www-form-urlencoded"));
  3374. try{
  3375. http.send(query);
  3376. }catch(e){
  3377. if(typeof http.abort == "function"){
  3378. http.abort();
  3379. }
  3380. doLoad(kwArgs, {status: 404}, url, query, useCache);
  3381. }
  3382. }else{
  3383. var tmpUrl = url;
  3384. if(query != "") {
  3385. tmpUrl += (tmpUrl.indexOf("?") > -1 ? "&" : "?") + query;
  3386. }
  3387. if(preventCache) {
  3388. tmpUrl += (dojo.string.endsWithAny(tmpUrl, "?", "&")
  3389. ? "" : (tmpUrl.indexOf("?") > -1 ? "&" : "?")) + "dojo.preventCache=" + new Date().valueOf();
  3390. }
  3391. http.open(kwArgs.method.toUpperCase(), tmpUrl, async);
  3392. setHeaders(http, kwArgs);
  3393. try {
  3394. http.send(null);
  3395. }catch(e) {
  3396. if(typeof http.abort == "function"){
  3397. http.abort();
  3398. }
  3399. doLoad(kwArgs, {status: 404}, url, query, useCache);
  3400. }
  3401. }
  3402. if( !async ) {
  3403. doLoad(kwArgs, http, url, query, useCache);
  3404. }
  3405. kwArgs.abort = function(){
  3406. return http.abort();
  3407. }
  3408. return;
  3409. }
  3410. dojo.io.transports.addTransport("XMLHTTPTransport");
  3411. }
  3412. dojo.provide("dojo.event");
  3413. dojo.require("dojo.lang.array");
  3414. dojo.require("dojo.lang.extras");
  3415. dojo.require("dojo.lang.func");
  3416. dojo.event = new function(){
  3417. this.canTimeout = dojo.lang.isFunction(dj_global["setTimeout"])||dojo.lang.isAlien(dj_global["setTimeout"]);
  3418. // FIXME: where should we put this method (not here!)?
  3419. function interpolateArgs(args, searchForNames){
  3420. var dl = dojo.lang;
  3421. var ao = {
  3422. srcObj: dj_global,
  3423. srcFunc: null,
  3424. adviceObj: dj_global,
  3425. adviceFunc: null,
  3426. aroundObj: null,
  3427. aroundFunc: null,
  3428. adviceType: (args.length>2) ? args[0] : "after",
  3429. precedence: "last",
  3430. once: false,
  3431. delay: null,
  3432. rate: 0,
  3433. adviceMsg: false
  3434. };
  3435. switch(args.length){
  3436. case 0: return;
  3437. case 1: return;
  3438. case 2:
  3439. ao.srcFunc = args[0];
  3440. ao.adviceFunc = args[1];
  3441. break;
  3442. case 3:
  3443. if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isString(args[2]))){
  3444. ao.adviceType = "after";
  3445. ao.srcObj = args[0];
  3446. ao.srcFunc = args[1];
  3447. ao.adviceFunc = args[2];
  3448. }else if((dl.isString(args[1]))&&(dl.isString(args[2]))){
  3449. ao.srcFunc = args[1];
  3450. ao.adviceFunc = args[2];
  3451. }else if((dl.isObject(args[0]))&&(dl.isString(args[1]))&&(dl.isFunction(args[2]))){
  3452. ao.adviceType = "after";
  3453. ao.srcObj = args[0];
  3454. ao.srcFunc = args[1];
  3455. var tmpName = dl.nameAnonFunc(args[2], ao.adviceObj, searchForNames);
  3456. ao.adviceFunc = tmpName;
  3457. }else if((dl.isFunction(args[0]))&&(dl.isObject(args[1]))&&(dl.isString(args[2]))){
  3458. ao.adviceType = "after";
  3459. ao.srcObj = dj_global;
  3460. var tmpName = dl.nameAnonFunc(args[0], ao.srcObj, searchForNames);
  3461. ao.srcFunc = tmpName;
  3462. ao.adviceObj = args[1];
  3463. ao.adviceFunc = args[2];
  3464. }
  3465. break;
  3466. case 4:
  3467. if((dl.isObject(args[0]))&&(dl.isObject(args[2]))){
  3468. // we can assume that we've got an old-style "connect" from
  3469. // the sigslot school of event attachment. We therefore
  3470. // assume after-advice.
  3471. ao.adviceType = "after";
  3472. ao.srcObj = args[0];
  3473. ao.srcFunc = args[1];
  3474. ao.adviceObj = args[2];
  3475. ao.adviceFunc = args[3];
  3476. }else if((dl.isString(args[0]))&&(dl.isString(args[1]))&&(dl.isObject(args[2]))){
  3477. ao.adviceType = args[0];
  3478. ao.srcObj = dj_global;
  3479. ao.srcFunc = args[1];
  3480. ao.adviceObj = args[2];
  3481. ao.adviceFunc = args[3];
  3482. }else if((dl.isString(args[0]))&&(dl.isFunction(args[1]))&&(dl.isObject(args[2]))){
  3483. ao.adviceType = args[0];
  3484. ao.srcObj = dj_global;
  3485. var tmpName = dl.nameAnonFunc(args[1], dj_global, searchForNames);
  3486. ao.srcFunc = tmpName;
  3487. ao.adviceObj = args[2];
  3488. ao.adviceFunc = args[3];
  3489. }else if((dl.isString(args[0]))&&(dl.isObject(args[1]))&&(dl.isString(args[2]))&&(dl.isFunction(args[3]))){
  3490. ao.srcObj = args[1];
  3491. ao.srcFunc = args[2];
  3492. var tmpName = dl.nameAnonFunc(args[3], dj_global, searchForNames);
  3493. ao.adviceObj = dj_global;
  3494. ao.adviceFunc = tmpName;
  3495. }else if(dl.isObject(args[1])){
  3496. ao.srcObj = args[1];
  3497. ao.srcFunc = args[2];
  3498. ao.adviceObj = dj_global;
  3499. ao.adviceFunc = args[3];
  3500. }else if(dl.isObject(args[2])){
  3501. ao.srcObj = dj_global;
  3502. ao.srcFunc = args[1];
  3503. ao.adviceObj = args[2];
  3504. ao.adviceFunc = args[3];
  3505. }else{
  3506. ao.srcObj = ao.adviceObj = ao.aroundObj = dj_global;
  3507. ao.srcFunc = args[1];
  3508. ao.adviceFunc = args[2];
  3509. ao.aroundFunc = args[3];
  3510. }
  3511. break;
  3512. case 6:
  3513. ao.srcObj = args[1];
  3514. ao.srcFunc = args[2];
  3515. ao.adviceObj = args[3]
  3516. ao.adviceFunc = args[4];
  3517. ao.aroundFunc = args[5];
  3518. ao.aroundObj = dj_global;
  3519. break;
  3520. default:
  3521. ao.srcObj = args[1];
  3522. ao.srcFunc = args[2];
  3523. ao.adviceObj = args[3]
  3524. ao.adviceFunc = args[4];
  3525. ao.aroundObj = args[5];
  3526. ao.aroundFunc = args[6];
  3527. ao.once = args[7];
  3528. ao.delay = args[8];
  3529. ao.rate = args[9];
  3530. ao.adviceMsg = args[10];
  3531. break;
  3532. }
  3533. if(dl.isFunction(ao.aroundFunc)){
  3534. var tmpName = dl.nameAnonFunc(ao.aroundFunc, ao.aroundObj, searchForNames);
  3535. ao.aroundFunc = tmpName;
  3536. }
  3537. if(dl.isFunction(ao.srcFunc)){
  3538. ao.srcFunc = dl.getNameInObj(ao.srcObj, ao.srcFunc);
  3539. }
  3540. if(dl.isFunction(ao.adviceFunc)){
  3541. ao.adviceFunc = dl.getNameInObj(ao.adviceObj, ao.adviceFunc);
  3542. }
  3543. if((ao.aroundObj)&&(dl.isFunction(ao.aroundFunc))){
  3544. ao.aroundFunc = dl.getNameInObj(ao.aroundObj, ao.aroundFunc);
  3545. }
  3546. if(!ao.srcObj){
  3547. dojo.raise("bad srcObj for srcFunc: "+ao.srcFunc);
  3548. }
  3549. if(!ao.adviceObj){
  3550. dojo.raise("bad adviceObj for adviceFunc: "+ao.adviceFunc);
  3551. }
  3552. return ao;
  3553. }
  3554. this.connect = function(){
  3555. if(arguments.length == 1){
  3556. var ao = arguments[0];
  3557. }else{
  3558. var ao = interpolateArgs(arguments, true);
  3559. }
  3560. if(dojo.lang.isArray(ao.srcObj) && ao.srcObj!=""){
  3561. var tmpAO = {};
  3562. for(var x in ao){
  3563. tmpAO[x] = ao[x];
  3564. }
  3565. var mjps = [];
  3566. dojo.lang.forEach(ao.srcObj, function(src){
  3567. if((dojo.render.html.capable)&&(dojo.lang.isString(src))){
  3568. src = dojo.byId(src);
  3569. // dojo.debug(src);
  3570. }
  3571. tmpAO.srcObj = src;
  3572. // dojo.debug(tmpAO.srcObj, tmpAO.srcFunc);
  3573. // dojo.debug(tmpAO.adviceObj, tmpAO.adviceFunc);
  3574. mjps.push(dojo.event.connect.call(dojo.event, tmpAO));
  3575. });
  3576. return mjps;
  3577. }
  3578. // FIXME: just doing a "getForMethod()" seems to be enough to put this into infinite recursion!!
  3579. var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
  3580. if(ao.adviceFunc){
  3581. var mjp2 = dojo.event.MethodJoinPoint.getForMethod(ao.adviceObj, ao.adviceFunc);
  3582. }
  3583. mjp.kwAddAdvice(ao);
  3584. return mjp; // advanced users might want to fsck w/ the join point
  3585. // manually
  3586. }
  3587. this.log = function(a1, a2){
  3588. var kwArgs;
  3589. if((arguments.length == 1)&&(typeof a1 == "object")){
  3590. kwArgs = a1;
  3591. }else{
  3592. kwArgs = {
  3593. srcObj: a1,
  3594. srcFunc: a2
  3595. };
  3596. }
  3597. kwArgs.adviceFunc = function(){
  3598. var argsStr = [];
  3599. for(var x=0; x<arguments.length; x++){
  3600. argsStr.push(arguments[x]);
  3601. }
  3602. dojo.debug("("+kwArgs.srcObj+")."+kwArgs.srcFunc, ":", argsStr.join(", "));
  3603. }
  3604. this.kwConnect(kwArgs);
  3605. }
  3606. this.connectBefore = function(){
  3607. var args = ["before"];
  3608. for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
  3609. return this.connect.apply(this, args);
  3610. }
  3611. this.connectAround = function(){
  3612. var args = ["around"];
  3613. for(var i = 0; i < arguments.length; i++) { args.push(arguments[i]); }
  3614. return this.connect.apply(this, args);
  3615. }
  3616. this.connectOnce = function(){
  3617. var ao = interpolateArgs(arguments, true);
  3618. ao.once = true;
  3619. return this.connect(ao);
  3620. }
  3621. this._kwConnectImpl = function(kwArgs, disconnect){
  3622. var fn = (disconnect) ? "disconnect" : "connect";
  3623. if(typeof kwArgs["srcFunc"] == "function"){
  3624. kwArgs.srcObj = kwArgs["srcObj"]||dj_global;
  3625. var tmpName = dojo.lang.nameAnonFunc(kwArgs.srcFunc, kwArgs.srcObj, true);
  3626. kwArgs.srcFunc = tmpName;
  3627. }
  3628. if(typeof kwArgs["adviceFunc"] == "function"){
  3629. kwArgs.adviceObj = kwArgs["adviceObj"]||dj_global;
  3630. var tmpName = dojo.lang.nameAnonFunc(kwArgs.adviceFunc, kwArgs.adviceObj, true);
  3631. kwArgs.adviceFunc = tmpName;
  3632. }
  3633. return dojo.event[fn]( (kwArgs["type"]||kwArgs["adviceType"]||"after"),
  3634. kwArgs["srcObj"]||dj_global,
  3635. kwArgs["srcFunc"],
  3636. kwArgs["adviceObj"]||kwArgs["targetObj"]||dj_global,
  3637. kwArgs["adviceFunc"]||kwArgs["targetFunc"],
  3638. kwArgs["aroundObj"],
  3639. kwArgs["aroundFunc"],
  3640. kwArgs["once"],
  3641. kwArgs["delay"],
  3642. kwArgs["rate"],
  3643. kwArgs["adviceMsg"]||false );
  3644. }
  3645. this.kwConnect = function(kwArgs){
  3646. return this._kwConnectImpl(kwArgs, false);
  3647. }
  3648. this.disconnect = function(){
  3649. var ao = interpolateArgs(arguments, true);
  3650. if(!ao.adviceFunc){ return; } // nothing to disconnect
  3651. var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
  3652. return mjp.removeAdvice(ao.adviceObj, ao.adviceFunc, ao.adviceType, ao.once);
  3653. }
  3654. this.kwDisconnect = function(kwArgs){
  3655. return this._kwConnectImpl(kwArgs, true);
  3656. }
  3657. }
  3658. // exactly one of these is created whenever a method with a joint point is run,
  3659. // if there is at least one 'around' advice.
  3660. dojo.event.MethodInvocation = function(join_point, obj, args) {
  3661. this.jp_ = join_point;
  3662. this.object = obj;
  3663. this.args = [];
  3664. for(var x=0; x<args.length; x++){
  3665. this.args[x] = args[x];
  3666. }
  3667. // the index of the 'around' that is currently being executed.
  3668. this.around_index = -1;
  3669. }
  3670. dojo.event.MethodInvocation.prototype.proceed = function() {
  3671. this.around_index++;
  3672. if(this.around_index >= this.jp_.around.length){
  3673. return this.jp_.object[this.jp_.methodname].apply(this.jp_.object, this.args);
  3674. // return this.jp_.run_before_after(this.object, this.args);
  3675. }else{
  3676. var ti = this.jp_.around[this.around_index];
  3677. var mobj = ti[0]||dj_global;
  3678. var meth = ti[1];
  3679. return mobj[meth].call(mobj, this);
  3680. }
  3681. }
  3682. dojo.event.MethodJoinPoint = function(obj, methname){
  3683. this.object = obj||dj_global;
  3684. this.methodname = methname;
  3685. this.methodfunc = this.object[methname];
  3686. this.before = [];
  3687. this.after = [];
  3688. this.around = [];
  3689. }
  3690. dojo.event.MethodJoinPoint.getForMethod = function(obj, methname) {
  3691. // if(!(methname in obj)){
  3692. if(!obj){ obj = dj_global; }
  3693. if(!obj[methname]){
  3694. // supply a do-nothing method implementation
  3695. obj[methname] = function(){};
  3696. if(!obj[methname]){
  3697. // e.g. cannot add to inbuilt objects in IE6
  3698. dojo.raise("Cannot set do-nothing method on that object "+methname);
  3699. }
  3700. }else if((!dojo.lang.isFunction(obj[methname]))&&(!dojo.lang.isAlien(obj[methname]))){
  3701. return null; // FIXME: should we throw an exception here instead?
  3702. }
  3703. // we hide our joinpoint instance in obj[methname + '$joinpoint']
  3704. var jpname = methname + "$joinpoint";
  3705. var jpfuncname = methname + "$joinpoint$method";
  3706. var joinpoint = obj[jpname];
  3707. if(!joinpoint){
  3708. var isNode = false;
  3709. if(dojo.event["browser"]){
  3710. if( (obj["attachEvent"])||
  3711. (obj["nodeType"])||
  3712. (obj["addEventListener"]) ){
  3713. isNode = true;
  3714. dojo.event.browser.addClobberNodeAttrs(obj, [jpname, jpfuncname, methname]);
  3715. }
  3716. }
  3717. var origArity = obj[methname].length;
  3718. obj[jpfuncname] = obj[methname];
  3719. // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, methname);
  3720. joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, jpfuncname);
  3721. obj[methname] = function(){
  3722. var args = [];
  3723. if((isNode)&&(!arguments.length)){
  3724. var evt = null;
  3725. try{
  3726. if(obj.ownerDocument){
  3727. evt = obj.ownerDocument.parentWindow.event;
  3728. }else if(obj.documentElement){
  3729. evt = obj.documentElement.ownerDocument.parentWindow.event;
  3730. }else{
  3731. evt = window.event;
  3732. }
  3733. }catch(e){
  3734. evt = window.event;
  3735. }
  3736. if(evt){
  3737. args.push(dojo.event.browser.fixEvent(evt, this));
  3738. }
  3739. }else{
  3740. for(var x=0; x<arguments.length; x++){
  3741. if((x==0)&&(isNode)&&(dojo.event.browser.isEvent(arguments[x]))){
  3742. args.push(dojo.event.browser.fixEvent(arguments[x], this));
  3743. }else{
  3744. args.push(arguments[x]);
  3745. }
  3746. }
  3747. }
  3748. // return joinpoint.run.apply(joinpoint, arguments);
  3749. return joinpoint.run.apply(joinpoint, args);
  3750. }
  3751. obj[methname].__preJoinArity = origArity;
  3752. }
  3753. return joinpoint;
  3754. }
  3755. dojo.lang.extend(dojo.event.MethodJoinPoint, {
  3756. unintercept: function(){
  3757. this.object[this.methodname] = this.methodfunc;
  3758. this.before = [];
  3759. this.after = [];
  3760. this.around = [];
  3761. },
  3762. disconnect: dojo.lang.forward("unintercept"),
  3763. run: function() {
  3764. var obj = this.object||dj_global;
  3765. var args = arguments;
  3766. // optimization. We only compute once the array version of the arguments
  3767. // pseudo-arr in order to prevent building it each time advice is unrolled.
  3768. var aargs = [];
  3769. for(var x=0; x<args.length; x++){
  3770. aargs[x] = args[x];
  3771. }
  3772. var unrollAdvice = function(marr){
  3773. if(!marr){
  3774. dojo.debug("Null argument to unrollAdvice()");
  3775. return;
  3776. }
  3777. var callObj = marr[0]||dj_global;
  3778. var callFunc = marr[1];
  3779. if(!callObj[callFunc]){
  3780. dojo.raise("function \"" + callFunc + "\" does not exist on \"" + callObj + "\"");
  3781. }
  3782. var aroundObj = marr[2]||dj_global;
  3783. var aroundFunc = marr[3];
  3784. var msg = marr[6];
  3785. var undef;
  3786. var to = {
  3787. args: [],
  3788. jp_: this,
  3789. object: obj,
  3790. proceed: function(){
  3791. return callObj[callFunc].apply(callObj, to.args);
  3792. }
  3793. };
  3794. to.args = aargs;
  3795. var delay = parseInt(marr[4]);
  3796. var hasDelay = ((!isNaN(delay))&&(marr[4]!==null)&&(typeof marr[4] != "undefined"));
  3797. if(marr[5]){
  3798. var rate = parseInt(marr[5]);
  3799. var cur = new Date();
  3800. var timerSet = false;
  3801. if((marr["last"])&&((cur-marr.last)<=rate)){
  3802. if(dojo.event.canTimeout){
  3803. if(marr["delayTimer"]){
  3804. clearTimeout(marr.delayTimer);
  3805. }
  3806. var tod = parseInt(rate*2); // is rate*2 naive?
  3807. var mcpy = dojo.lang.shallowCopy(marr);
  3808. marr.delayTimer = setTimeout(function(){
  3809. // FIXME: on IE at least, event objects from the
  3810. // browser can go out of scope. How (or should?) we
  3811. // deal with it?
  3812. mcpy[5] = 0;
  3813. unrollAdvice(mcpy);
  3814. }, tod);
  3815. }
  3816. return;
  3817. }else{
  3818. marr.last = cur;
  3819. }
  3820. }
  3821. // FIXME: need to enforce rates for a connection here!
  3822. if(aroundFunc){
  3823. // NOTE: around advice can't delay since we might otherwise depend
  3824. // on execution order!
  3825. aroundObj[aroundFunc].call(aroundObj, to);
  3826. }else{
  3827. // var tmjp = dojo.event.MethodJoinPoint.getForMethod(obj, methname);
  3828. if((hasDelay)&&((dojo.render.html)||(dojo.render.svg))){ // FIXME: the render checks are grotty!
  3829. dj_global["setTimeout"](function(){
  3830. if(msg){
  3831. callObj[callFunc].call(callObj, to);
  3832. }else{
  3833. callObj[callFunc].apply(callObj, args);
  3834. }
  3835. }, delay);
  3836. }else{ // many environments can't support delay!
  3837. if(msg){
  3838. callObj[callFunc].call(callObj, to);
  3839. }else{
  3840. callObj[callFunc].apply(callObj, args);
  3841. }
  3842. }
  3843. }
  3844. }
  3845. if(this.before.length>0){
  3846. dojo.lang.forEach(this.before, unrollAdvice);
  3847. }
  3848. var result;
  3849. if(this.around.length>0){
  3850. var mi = new dojo.event.MethodInvocation(this, obj, args);
  3851. result = mi.proceed();
  3852. }else if(this.methodfunc){
  3853. result = this.object[this.methodname].apply(this.object, args);
  3854. }
  3855. if(this.after.length>0){
  3856. dojo.lang.forEach(this.after, unrollAdvice);
  3857. }
  3858. return (this.methodfunc) ? result : null;
  3859. },
  3860. getArr: function(kind){
  3861. var arr = this.after;
  3862. // FIXME: we should be able to do this through props or Array.in()
  3863. if((typeof kind == "string")&&(kind.indexOf("before")!=-1)){
  3864. arr = this.before;
  3865. }else if(kind=="around"){
  3866. arr = this.around;
  3867. }
  3868. return arr;
  3869. },
  3870. kwAddAdvice: function(args){
  3871. this.addAdvice( args["adviceObj"], args["adviceFunc"],
  3872. args["aroundObj"], args["aroundFunc"],
  3873. args["adviceType"], args["precedence"],
  3874. args["once"], args["delay"], args["rate"],
  3875. args["adviceMsg"]);
  3876. },
  3877. addAdvice: function( thisAdviceObj, thisAdvice,
  3878. thisAroundObj, thisAround,
  3879. advice_kind, precedence,
  3880. once, delay, rate, asMessage){
  3881. var arr = this.getArr(advice_kind);
  3882. if(!arr){
  3883. dojo.raise("bad this: " + this);
  3884. }
  3885. var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage];
  3886. if(once){
  3887. if(this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr) >= 0){
  3888. return;
  3889. }
  3890. }
  3891. if(precedence == "first"){
  3892. arr.unshift(ao);
  3893. }else{
  3894. arr.push(ao);
  3895. }
  3896. },
  3897. hasAdvice: function(thisAdviceObj, thisAdvice, advice_kind, arr){
  3898. if(!arr){ arr = this.getArr(advice_kind); }
  3899. var ind = -1;
  3900. for(var x=0; x<arr.length; x++){
  3901. var aao = (typeof thisAdvice == "object") ? (new String(thisAdvice)).toString() : thisAdvice;
  3902. var a1o = (typeof arr[x][1] == "object") ? (new String(arr[x][1])).toString() : arr[x][1];
  3903. if((arr[x][0] == thisAdviceObj)&&(a1o == aao)){
  3904. ind = x;
  3905. }
  3906. }
  3907. return ind;
  3908. },
  3909. removeAdvice: function(thisAdviceObj, thisAdvice, advice_kind, once){
  3910. var arr = this.getArr(advice_kind);
  3911. var ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
  3912. if(ind == -1){
  3913. return false;
  3914. }
  3915. while(ind != -1){
  3916. arr.splice(ind, 1);
  3917. if(once){ break; }
  3918. ind = this.hasAdvice(thisAdviceObj, thisAdvice, advice_kind, arr);
  3919. }
  3920. return true;
  3921. }
  3922. });
  3923. dojo.require("dojo.event");
  3924. dojo.provide("dojo.event.topic");
  3925. dojo.event.topic = new function(){
  3926. this.topics = {};
  3927. this.getTopic = function(topicName){
  3928. if(!this.topics[topicName]){
  3929. this.topics[topicName] = new this.TopicImpl(topicName);
  3930. }
  3931. return this.topics[topicName];
  3932. }
  3933. this.registerPublisher = function(topic, obj, funcName){
  3934. var topic = this.getTopic(topic);
  3935. topic.registerPublisher(obj, funcName);
  3936. }
  3937. this.subscribe = function(topic, obj, funcName){
  3938. var topic = this.getTopic(topic);
  3939. topic.subscribe(obj, funcName);
  3940. }
  3941. this.unsubscribe = function(topic, obj, funcName){
  3942. var topic = this.getTopic(topic);
  3943. topic.unsubscribe(obj, funcName);
  3944. }
  3945. this.destroy = function(topic){
  3946. this.getTopic(topic).destroy();
  3947. delete this.topics[topic];
  3948. }
  3949. this.publishApply = function(topic, args){
  3950. var topic = this.getTopic(topic);
  3951. topic.sendMessage.apply(topic, args);
  3952. }
  3953. this.publish = function(topic, message){
  3954. var topic = this.getTopic(topic);
  3955. // if message is an array, we treat it as a set of arguments,
  3956. // otherwise, we just pass on the arguments passed in as-is
  3957. var args = [];
  3958. // could we use concat instead here?
  3959. for(var x=1; x<arguments.length; x++){
  3960. args.push(arguments[x]);
  3961. }
  3962. topic.sendMessage.apply(topic, args);
  3963. }
  3964. }
  3965. dojo.event.topic.TopicImpl = function(topicName){
  3966. this.topicName = topicName;
  3967. this.subscribe = function(listenerObject, listenerMethod){
  3968. var tf = listenerMethod||listenerObject;
  3969. var to = (!listenerMethod) ? dj_global : listenerObject;
  3970. dojo.event.kwConnect({
  3971. srcObj: this,
  3972. srcFunc: "sendMessage",
  3973. adviceObj: to,
  3974. adviceFunc: tf
  3975. });
  3976. }
  3977. this.unsubscribe = function(listenerObject, listenerMethod){
  3978. var tf = (!listenerMethod) ? listenerObject : listenerMethod;
  3979. var to = (!listenerMethod) ? null : listenerObject;
  3980. dojo.event.kwDisconnect({
  3981. srcObj: this,
  3982. srcFunc: "sendMessage",
  3983. adviceObj: to,
  3984. adviceFunc: tf
  3985. });
  3986. }
  3987. this.destroy = function(){
  3988. dojo.event.MethodJoinPoint.getForMethod(this, "sendMessage").disconnect();
  3989. }
  3990. this.registerPublisher = function(publisherObject, publisherMethod){
  3991. dojo.event.connect(publisherObject, publisherMethod, this, "sendMessage");
  3992. }
  3993. this.sendMessage = function(message){
  3994. // The message has been propagated
  3995. }
  3996. }
  3997. dojo.provide("dojo.event.browser");
  3998. dojo.require("dojo.event");
  3999. // FIXME: any particular reason this is in the global scope?
  4000. dojo._ie_clobber = new function(){
  4001. this.clobberNodes = [];
  4002. function nukeProp(node, prop){
  4003. // try{ node.removeAttribute(prop); }catch(e){ /* squelch */ }
  4004. try{ node[prop] = null; }catch(e){ /* squelch */ }
  4005. try{ delete node[prop]; }catch(e){ /* squelch */ }
  4006. // FIXME: JotLive needs this, but I'm not sure if it's too slow or not
  4007. try{ node.removeAttribute(prop); }catch(e){ /* squelch */ }
  4008. }
  4009. this.clobber = function(nodeRef){
  4010. var na;
  4011. var tna;
  4012. if(nodeRef){
  4013. tna = nodeRef.all || nodeRef.getElementsByTagName("*");
  4014. na = [nodeRef];
  4015. for(var x=0; x<tna.length; x++){
  4016. // if we're gonna be clobbering the thing, at least make sure
  4017. // we aren't trying to do it twice
  4018. if(tna[x]["__doClobber__"]){
  4019. na.push(tna[x]);
  4020. }
  4021. }
  4022. }else{
  4023. try{ window.onload = null; }catch(e){}
  4024. na = (this.clobberNodes.length) ? this.clobberNodes : document.all;
  4025. }
  4026. tna = null;
  4027. var basis = {};
  4028. for(var i = na.length-1; i>=0; i=i-1){
  4029. var el = na[i];
  4030. if(el["__clobberAttrs__"]){
  4031. for(var j=0; j<el.__clobberAttrs__.length; j++){
  4032. nukeProp(el, el.__clobberAttrs__[j]);
  4033. }
  4034. nukeProp(el, "__clobberAttrs__");
  4035. nukeProp(el, "__doClobber__");
  4036. }
  4037. }
  4038. na = null;
  4039. }
  4040. }
  4041. if(dojo.render.html.ie){
  4042. dojo.addOnUnload(function(){
  4043. dojo._ie_clobber.clobber();
  4044. try{
  4045. if((dojo["widget"])&&(dojo.widget["manager"])){
  4046. dojo.widget.manager.destroyAll();
  4047. }
  4048. }catch(e){}
  4049. try{ window.onload = null; }catch(e){}
  4050. try{ window.onunload = null; }catch(e){}
  4051. dojo._ie_clobber.clobberNodes = [];
  4052. // CollectGarbage();
  4053. });
  4054. }
  4055. dojo.event.browser = new function(){
  4056. var clobberIdx = 0;
  4057. this.clean = function(node){
  4058. if(dojo.render.html.ie){
  4059. dojo._ie_clobber.clobber(node);
  4060. }
  4061. }
  4062. this.addClobberNode = function(node){
  4063. if(!dojo.render.html.ie){ return; }
  4064. if(!node["__doClobber__"]){
  4065. node.__doClobber__ = true;
  4066. dojo._ie_clobber.clobberNodes.push(node);
  4067. // this might not be the most efficient thing to do, but it's
  4068. // much less error prone than other approaches which were
  4069. // previously tried and failed
  4070. node.__clobberAttrs__ = [];
  4071. }
  4072. }
  4073. this.addClobberNodeAttrs = function(node, props){
  4074. if(!dojo.render.html.ie){ return; }
  4075. this.addClobberNode(node);
  4076. for(var x=0; x<props.length; x++){
  4077. node.__clobberAttrs__.push(props[x]);
  4078. }
  4079. }
  4080. this.removeListener = function(node, evtName, fp, capture){
  4081. if(!capture){ var capture = false; }
  4082. evtName = evtName.toLowerCase();
  4083. if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); }
  4084. // FIXME: this is mostly a punt, we aren't actually doing anything on IE
  4085. if(node.removeEventListener){
  4086. node.removeEventListener(evtName, fp, capture);
  4087. }
  4088. }
  4089. this.addListener = function(node, evtName, fp, capture, dontFix){
  4090. if(!node){ return; } // FIXME: log and/or bail?
  4091. if(!capture){ var capture = false; }
  4092. evtName = evtName.toLowerCase();
  4093. if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; }
  4094. if(!dontFix){
  4095. // build yet another closure around fp in order to inject fixEvent
  4096. // around the resulting event
  4097. var newfp = function(evt){
  4098. if(!evt){ evt = window.event; }
  4099. var ret = fp(dojo.event.browser.fixEvent(evt, this));
  4100. if(capture){
  4101. dojo.event.browser.stopEvent(evt);
  4102. }
  4103. return ret;
  4104. }
  4105. }else{
  4106. newfp = fp;
  4107. }
  4108. if(node.addEventListener){
  4109. node.addEventListener(evtName.substr(2), newfp, capture);
  4110. return newfp;
  4111. }else{
  4112. if(typeof node[evtName] == "function" ){
  4113. var oldEvt = node[evtName];
  4114. node[evtName] = function(e){
  4115. oldEvt(e);
  4116. return newfp(e);
  4117. }
  4118. }else{
  4119. node[evtName]=newfp;
  4120. }
  4121. if(dojo.render.html.ie){
  4122. this.addClobberNodeAttrs(node, [evtName]);
  4123. }
  4124. return newfp;
  4125. }
  4126. }
  4127. this.isEvent = function(obj){
  4128. // FIXME: event detection hack ... could test for additional attributes
  4129. // if necessary
  4130. return (typeof obj != "undefined")&&(typeof Event != "undefined")&&(obj.eventPhase);
  4131. // Event does not support instanceof in Opera, otherwise:
  4132. //return (typeof Event != "undefined")&&(obj instanceof Event);
  4133. }
  4134. this.currentEvent = null;
  4135. this.callListener = function(listener, curTarget){
  4136. if(typeof listener != 'function'){
  4137. dojo.raise("listener not a function: " + listener);
  4138. }
  4139. dojo.event.browser.currentEvent.currentTarget = curTarget;
  4140. return listener.call(curTarget, dojo.event.browser.currentEvent);
  4141. }
  4142. this.stopPropagation = function(){
  4143. dojo.event.browser.currentEvent.cancelBubble = true;
  4144. }
  4145. this.preventDefault = function(){
  4146. dojo.event.browser.currentEvent.returnValue = false;
  4147. }
  4148. this.keys = {
  4149. KEY_BACKSPACE: 8,
  4150. KEY_TAB: 9,
  4151. KEY_ENTER: 13,
  4152. KEY_SHIFT: 16,
  4153. KEY_CTRL: 17,
  4154. KEY_ALT: 18,
  4155. KEY_PAUSE: 19,
  4156. KEY_CAPS_LOCK: 20,
  4157. KEY_ESCAPE: 27,
  4158. KEY_SPACE: 32,
  4159. KEY_PAGE_UP: 33,
  4160. KEY_PAGE_DOWN: 34,
  4161. KEY_END: 35,
  4162. KEY_HOME: 36,
  4163. KEY_LEFT_ARROW: 37,
  4164. KEY_UP_ARROW: 38,
  4165. KEY_RIGHT_ARROW: 39,
  4166. KEY_DOWN_ARROW: 40,
  4167. KEY_INSERT: 45,
  4168. KEY_DELETE: 46,
  4169. KEY_LEFT_WINDOW: 91,
  4170. KEY_RIGHT_WINDOW: 92,
  4171. KEY_SELECT: 93,
  4172. KEY_F1: 112,
  4173. KEY_F2: 113,
  4174. KEY_F3: 114,
  4175. KEY_F4: 115,
  4176. KEY_F5: 116,
  4177. KEY_F6: 117,
  4178. KEY_F7: 118,
  4179. KEY_F8: 119,
  4180. KEY_F9: 120,
  4181. KEY_F10: 121,
  4182. KEY_F11: 122,
  4183. KEY_F12: 123,
  4184. KEY_NUM_LOCK: 144,
  4185. KEY_SCROLL_LOCK: 145
  4186. };
  4187. // reverse lookup
  4188. this.revKeys = [];
  4189. for(var key in this.keys){
  4190. this.revKeys[this.keys[key]] = key;
  4191. }
  4192. this.fixEvent = function(evt, sender){
  4193. if((!evt)&&(window["event"])){
  4194. var evt = window.event;
  4195. }
  4196. if((evt["type"])&&(evt["type"].indexOf("key") == 0)){ // key events
  4197. evt.keys = this.revKeys;
  4198. // FIXME: how can we eliminate this iteration?
  4199. for(var key in this.keys) {
  4200. evt[key] = this.keys[key];
  4201. }
  4202. if((dojo.render.html.ie)&&(evt["type"] == "keypress")){
  4203. evt.charCode = evt.keyCode;
  4204. }
  4205. }
  4206. if(dojo.render.html.ie){
  4207. if(!evt.target){ evt.target = evt.srcElement; }
  4208. if(!evt.currentTarget){ evt.currentTarget = (sender ? sender : evt.srcElement); }
  4209. if(!evt.layerX){ evt.layerX = evt.offsetX; }
  4210. if(!evt.layerY){ evt.layerY = evt.offsetY; }
  4211. // FIXME: scroll position query is duped from dojo.html to avoid dependency on that entire module
  4212. var docBody = ((dojo.render.html.ie55)||(document["compatMode"] == "BackCompat")) ? document.body : document.documentElement;
  4213. if(!evt.pageX){ evt.pageX = evt.clientX + (docBody.scrollLeft || 0) }
  4214. if(!evt.pageY){ evt.pageY = evt.clientY + (docBody.scrollTop || 0) }
  4215. // mouseover
  4216. if(evt.type == "mouseover"){ evt.relatedTarget = evt.fromElement; }
  4217. // mouseout
  4218. if(evt.type == "mouseout"){ evt.relatedTarget = evt.toElement; }
  4219. this.currentEvent = evt;
  4220. evt.callListener = this.callListener;
  4221. evt.stopPropagation = this.stopPropagation;
  4222. evt.preventDefault = this.preventDefault;
  4223. }
  4224. return evt;
  4225. }
  4226. this.stopEvent = function(ev) {
  4227. if(window.event){
  4228. ev.returnValue = false;
  4229. ev.cancelBubble = true;
  4230. }else{
  4231. ev.preventDefault();
  4232. ev.stopPropagation();
  4233. }
  4234. }
  4235. }
  4236. dojo.kwCompoundRequire({
  4237. common: ["dojo.event", "dojo.event.topic"],
  4238. browser: ["dojo.event.browser"],
  4239. dashboard: ["dojo.event.browser"]
  4240. });
  4241. dojo.provide("dojo.event.*");
  4242. dojo.provide("dojo.lfx.Animation");
  4243. dojo.provide("dojo.lfx.Line");
  4244. dojo.require("dojo.lang.func");
  4245. /*
  4246. Animation package based on Dan Pupius' work: http://pupius.co.uk/js/Toolkit.Drawing.js
  4247. */
  4248. dojo.lfx.Line = function(start, end){
  4249. this.start = start;
  4250. this.end = end;
  4251. if(dojo.lang.isArray(start)){
  4252. var diff = [];
  4253. dojo.lang.forEach(this.start, function(s,i){
  4254. diff[i] = this.end[i] - s;
  4255. }, this);
  4256. this.getValue = function(/*float*/ n){
  4257. var res = [];
  4258. dojo.lang.forEach(this.start, function(s, i){
  4259. res[i] = (diff[i] * n) + s;
  4260. }, this);
  4261. return res;
  4262. }
  4263. }else{
  4264. var diff = end - start;
  4265. this.getValue = function(/*float*/ n){
  4266. // summary: returns the point on the line
  4267. // n: a floating point number greater than 0 and less than 1
  4268. return (diff * n) + this.start;
  4269. }
  4270. }
  4271. }
  4272. dojo.lfx.easeIn = function(n){
  4273. // summary: returns the point on an easing curve
  4274. // n: a floating point number greater than 0 and less than 1
  4275. return Math.pow(n, 3);
  4276. }
  4277. dojo.lfx.easeOut = function(n){
  4278. // summary: returns the point on the line
  4279. // n: a floating point number greater than 0 and less than 1
  4280. return ( 1 - Math.pow(1 - n, 3) );
  4281. }
  4282. dojo.lfx.easeInOut = function(n){
  4283. // summary: returns the point on the line
  4284. // n: a floating point number greater than 0 and less than 1
  4285. return ( (3 * Math.pow(n, 2)) - (2 * Math.pow(n, 3)) );
  4286. }
  4287. dojo.lfx.IAnimation = function(){}
  4288. dojo.lang.extend(dojo.lfx.IAnimation, {
  4289. // public properties
  4290. curve: null,
  4291. duration: 1000,
  4292. easing: null,
  4293. repeatCount: 0,
  4294. rate: 25,
  4295. // events
  4296. handler: null,
  4297. beforeBegin: null,
  4298. onBegin: null,
  4299. onAnimate: null,
  4300. onEnd: null,
  4301. onPlay: null,
  4302. onPause: null,
  4303. onStop: null,
  4304. // public methods
  4305. play: null,
  4306. pause: null,
  4307. stop: null,
  4308. fire: function(evt, args){
  4309. if(this[evt]){
  4310. this[evt].apply(this, (args||[]));
  4311. }
  4312. },
  4313. // private properties
  4314. _active: false,
  4315. _paused: false
  4316. });
  4317. dojo.lfx.Animation = function(/*Object*/ handlers, /*int*/ duration, /*Array*/ curve, /*function*/ easing, /*int*/ repeatCount, /*int*/ rate){
  4318. // summary
  4319. // a generic animation object that fires callbacks into it's handlers
  4320. // object at various states
  4321. // handlers
  4322. // object {
  4323. // handler: function(){},
  4324. // onstart: function(){},
  4325. // onstop: function(){},
  4326. // onanimate: function(){}
  4327. // }
  4328. dojo.lfx.IAnimation.call(this);
  4329. if(dojo.lang.isNumber(handlers)||(!handlers && duration.getValue)){
  4330. // no handlers argument:
  4331. rate = repeatCount;
  4332. repeatCount = easing;
  4333. easing = curve;
  4334. curve = duration;
  4335. duration = handlers;
  4336. handlers = null;
  4337. }else if(handlers.getValue||dojo.lang.isArray(handlers)){
  4338. // no handlers or duration:
  4339. rate = easing;
  4340. repeatCount = curve;
  4341. easing = duration;
  4342. curve = handlers;
  4343. duration = null;
  4344. handlers = null;
  4345. }
  4346. if(dojo.lang.isArray(curve)){
  4347. this.curve = new dojo.lfx.Line(curve[0], curve[1]);
  4348. }else{
  4349. this.curve = curve;
  4350. }
  4351. if(duration != null && duration > 0){ this.duration = duration; }
  4352. if(repeatCount){ this.repeatCount = repeatCount; }
  4353. if(rate){ this.rate = rate; }
  4354. if(handlers){
  4355. this.handler = handlers.handler;
  4356. this.beforeBegin = handlers.beforeBegin;
  4357. this.onBegin = handlers.onBegin;
  4358. this.onEnd = handlers.onEnd;
  4359. this.onPlay = handlers.onPlay;
  4360. this.onPause = handlers.onPause;
  4361. this.onStop = handlers.onStop;
  4362. this.onAnimate = handlers.onAnimate;
  4363. }
  4364. if(easing && dojo.lang.isFunction(easing)){
  4365. this.easing=easing;
  4366. }
  4367. }
  4368. dojo.inherits(dojo.lfx.Animation, dojo.lfx.IAnimation);
  4369. dojo.lang.extend(dojo.lfx.Animation, {
  4370. // "private" properties
  4371. _startTime: null,
  4372. _endTime: null,
  4373. _timer: null,
  4374. _percent: 0,
  4375. _startRepeatCount: 0,
  4376. // public methods
  4377. play: function(delay, gotoStart){
  4378. if(gotoStart){
  4379. clearTimeout(this._timer);
  4380. this._active = false;
  4381. this._paused = false;
  4382. this._percent = 0;
  4383. }else if(this._active && !this._paused){
  4384. return this;
  4385. }
  4386. this.fire("handler", ["beforeBegin"]);
  4387. this.fire("beforeBegin");
  4388. if(delay > 0){
  4389. setTimeout(dojo.lang.hitch(this, function(){ this.play(null, gotoStart); }), delay);
  4390. return this;
  4391. }
  4392. this._startTime = new Date().valueOf();
  4393. if(this._paused){
  4394. this._startTime -= (this.duration * this._percent / 100);
  4395. }
  4396. this._endTime = this._startTime + this.duration;
  4397. this._active = true;
  4398. this._paused = false;
  4399. var step = this._percent / 100;
  4400. var value = this.curve.getValue(step);
  4401. if( this._percent == 0 ) {
  4402. if(!this._startRepeatCount) {
  4403. this._startRepeatCount = this.repeatCount;
  4404. }
  4405. this.fire("handler", ["begin", value]);
  4406. this.fire("onBegin", [value]);
  4407. }
  4408. this.fire("handler", ["play", value]);
  4409. this.fire("onPlay", [value]);
  4410. this._cycle();
  4411. return this;
  4412. },
  4413. pause: function() {
  4414. clearTimeout(this._timer);
  4415. if(!this._active){ return this; }
  4416. this._paused = true;
  4417. var value = this.curve.getValue(this._percent / 100);
  4418. this.fire("handler", ["pause", value]);
  4419. this.fire("onPause", [value]);
  4420. return this;
  4421. },
  4422. gotoPercent: function(pct, andPlay) {
  4423. clearTimeout(this._timer);
  4424. this._active = true;
  4425. this._paused = true;
  4426. this._percent = pct;
  4427. if( andPlay ) { this.play(); }
  4428. },
  4429. stop: function(gotoEnd) {
  4430. clearTimeout(this._timer);
  4431. var step = this._percent / 100;
  4432. if( gotoEnd ) {
  4433. step = 1;
  4434. }
  4435. var value = this.curve.getValue(step);
  4436. this.fire("handler", ["stop", value]);
  4437. this.fire("onStop", [value]);
  4438. this._active = false;
  4439. this._paused = false;
  4440. return this;
  4441. },
  4442. status: function() {
  4443. if( this._active ) {
  4444. return this._paused ? "paused" : "playing";
  4445. } else {
  4446. return "stopped";
  4447. }
  4448. },
  4449. // "private" methods
  4450. _cycle: function() {
  4451. clearTimeout(this._timer);
  4452. if(this._active){
  4453. var curr = new Date().valueOf();
  4454. var step = (curr - this._startTime) / (this._endTime - this._startTime);
  4455. if(step >= 1){
  4456. step = 1;
  4457. this._percent = 100;
  4458. }else{
  4459. this._percent = step * 100;
  4460. }
  4461. // Perform easing
  4462. if((this.easing)&&(dojo.lang.isFunction(this.easing))){
  4463. step = this.easing(step);
  4464. }
  4465. var value = this.curve.getValue(step);
  4466. this.fire("handler", ["animate", value]);
  4467. this.fire("onAnimate", [value]);
  4468. if( step < 1 ) {
  4469. this._timer = setTimeout(dojo.lang.hitch(this, "_cycle"), this.rate);
  4470. } else {
  4471. this._active = false;
  4472. this.fire("handler", ["end"]);
  4473. this.fire("onEnd");
  4474. if( this.repeatCount > 0 ) {
  4475. this.repeatCount--;
  4476. this.play(null, true);
  4477. } else if( this.repeatCount == -1 ) {
  4478. this.play(null, true);
  4479. } else {
  4480. if(this._startRepeatCount) {
  4481. this.repeatCount = this._startRepeatCount;
  4482. this._startRepeatCount = 0;
  4483. }
  4484. }
  4485. }
  4486. }
  4487. return this;
  4488. }
  4489. });
  4490. dojo.lfx.Combine = function(){
  4491. dojo.lfx.IAnimation.call(this);
  4492. this._anims = [];
  4493. this._animsEnded = 0;
  4494. var anims = arguments;
  4495. if(anims.length == 1 && (dojo.lang.isArray(anims[0]) || dojo.lang.isArrayLike(anims[0]))){
  4496. anims = anims[0];
  4497. }
  4498. var _this = this;
  4499. dojo.lang.forEach(anims, function(anim){
  4500. _this._anims.push(anim);
  4501. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  4502. anim.onEnd = function(){ oldOnEnd(); _this._onAnimsEnded(); };
  4503. });
  4504. }
  4505. dojo.inherits(dojo.lfx.Combine, dojo.lfx.IAnimation);
  4506. dojo.lang.extend(dojo.lfx.Combine, {
  4507. // private members
  4508. _animsEnded: 0,
  4509. // public methods
  4510. play: function(delay, gotoStart){
  4511. if( !this._anims.length ){ return this; }
  4512. this.fire("beforeBegin");
  4513. if(delay > 0){
  4514. setTimeout(dojo.lang.hitch(this, function(){ this.play(null, gotoStart); }), delay);
  4515. return this;
  4516. }
  4517. if(gotoStart || this._anims[0].percent == 0){
  4518. this.fire("onBegin");
  4519. }
  4520. this.fire("onPlay");
  4521. this._animsCall("play", null, gotoStart);
  4522. return this;
  4523. },
  4524. pause: function(){
  4525. this.fire("onPause");
  4526. this._animsCall("pause");
  4527. return this;
  4528. },
  4529. stop: function(gotoEnd){
  4530. this.fire("onStop");
  4531. this._animsCall("stop", gotoEnd);
  4532. return this;
  4533. },
  4534. // private methods
  4535. _onAnimsEnded: function(){
  4536. this._animsEnded++;
  4537. if(this._animsEnded >= this._anims.length){
  4538. this.fire("onEnd");
  4539. }
  4540. return this;
  4541. },
  4542. _animsCall: function(funcName){
  4543. var args = [];
  4544. if(arguments.length > 1){
  4545. for(var i = 1 ; i < arguments.length ; i++){
  4546. args.push(arguments[i]);
  4547. }
  4548. }
  4549. var _this = this;
  4550. dojo.lang.forEach(this._anims, function(anim){
  4551. anim[funcName](args);
  4552. }, _this);
  4553. return this;
  4554. }
  4555. });
  4556. dojo.lfx.Chain = function() {
  4557. dojo.lfx.IAnimation.call(this);
  4558. this._anims = [];
  4559. this._currAnim = -1;
  4560. var anims = arguments;
  4561. if(anims.length == 1 && (dojo.lang.isArray(anims[0]) || dojo.lang.isArrayLike(anims[0]))){
  4562. anims = anims[0];
  4563. }
  4564. var _this = this;
  4565. dojo.lang.forEach(anims, function(anim, i, anims_arr){
  4566. _this._anims.push(anim);
  4567. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  4568. if(i < anims_arr.length - 1){
  4569. anim.onEnd = function(){ oldOnEnd(); _this._playNext(); };
  4570. }else{
  4571. anim.onEnd = function(){ oldOnEnd(); _this.fire("onEnd"); };
  4572. }
  4573. }, _this);
  4574. }
  4575. dojo.inherits(dojo.lfx.Chain, dojo.lfx.IAnimation);
  4576. dojo.lang.extend(dojo.lfx.Chain, {
  4577. // private members
  4578. _currAnim: -1,
  4579. // public methods
  4580. play: function(delay, gotoStart){
  4581. if( !this._anims.length ) { return this; }
  4582. if( gotoStart || !this._anims[this._currAnim] ) {
  4583. this._currAnim = 0;
  4584. }
  4585. var currentAnimation = this._anims[this._currAnim];
  4586. this.fire("beforeBegin");
  4587. if(delay > 0){
  4588. setTimeout(dojo.lang.hitch(this, function(){ this.play(null, gotoStart); }), delay);
  4589. return this;
  4590. }
  4591. if(currentAnimation){
  4592. if(this._currAnim == 0){
  4593. this.fire("handler", ["begin", this._currAnim]);
  4594. this.fire("onBegin", [this._currAnim]);
  4595. }
  4596. this.fire("onPlay", [this._currAnim]);
  4597. currentAnimation.play(null, gotoStart);
  4598. }
  4599. return this;
  4600. },
  4601. pause: function(){
  4602. if( this._anims[this._currAnim] ) {
  4603. this._anims[this._currAnim].pause();
  4604. this.fire("onPause", [this._currAnim]);
  4605. }
  4606. return this;
  4607. },
  4608. playPause: function(){
  4609. if(this._anims.length == 0){ return this; }
  4610. if(this._currAnim == -1){ this._currAnim = 0; }
  4611. var currAnim = this._anims[this._currAnim];
  4612. if( currAnim ) {
  4613. if( !currAnim._active || currAnim._paused ) {
  4614. this.play();
  4615. } else {
  4616. this.pause();
  4617. }
  4618. }
  4619. return this;
  4620. },
  4621. stop: function(){
  4622. var currAnim = this._anims[this._currAnim];
  4623. if(currAnim){
  4624. currAnim.stop();
  4625. this.fire("onStop", [this._currAnim]);
  4626. }
  4627. return currAnim;
  4628. },
  4629. // private methods
  4630. _playNext: function(){
  4631. if( this._currAnim == -1 || this._anims.length == 0 ) { return this; }
  4632. this._currAnim++;
  4633. if( this._anims[this._currAnim] ){
  4634. this._anims[this._currAnim].play(null, true);
  4635. }
  4636. return this;
  4637. }
  4638. });
  4639. dojo.lfx.combine = function(){
  4640. var anims = arguments;
  4641. if(dojo.lang.isArray(arguments[0])){
  4642. anims = arguments[0];
  4643. }
  4644. return new dojo.lfx.Combine(anims);
  4645. }
  4646. dojo.lfx.chain = function(){
  4647. var anims = arguments;
  4648. if(dojo.lang.isArray(arguments[0])){
  4649. anims = arguments[0];
  4650. }
  4651. return new dojo.lfx.Chain(anims);
  4652. }
  4653. dojo.provide("dojo.graphics.color");
  4654. dojo.require("dojo.lang.array");
  4655. // TODO: rewrite the "x2y" methods to take advantage of the parsing
  4656. // abilities of the Color object. Also, beef up the Color
  4657. // object (as possible) to parse most common formats
  4658. // takes an r, g, b, a(lpha) value, [r, g, b, a] array, "rgb(...)" string, hex string (#aaa, #aaaaaa, aaaaaaa)
  4659. dojo.graphics.color.Color = function(r, g, b, a) {
  4660. // dojo.debug("r:", r[0], "g:", r[1], "b:", r[2]);
  4661. if(dojo.lang.isArray(r)) {
  4662. this.r = r[0];
  4663. this.g = r[1];
  4664. this.b = r[2];
  4665. this.a = r[3]||1.0;
  4666. } else if(dojo.lang.isString(r)) {
  4667. var rgb = dojo.graphics.color.extractRGB(r);
  4668. this.r = rgb[0];
  4669. this.g = rgb[1];
  4670. this.b = rgb[2];
  4671. this.a = g||1.0;
  4672. } else if(r instanceof dojo.graphics.color.Color) {
  4673. this.r = r.r;
  4674. this.b = r.b;
  4675. this.g = r.g;
  4676. this.a = r.a;
  4677. } else {
  4678. this.r = r;
  4679. this.g = g;
  4680. this.b = b;
  4681. this.a = a;
  4682. }
  4683. }
  4684. dojo.graphics.color.Color.fromArray = function(arr) {
  4685. return new dojo.graphics.color.Color(arr[0], arr[1], arr[2], arr[3]);
  4686. }
  4687. dojo.lang.extend(dojo.graphics.color.Color, {
  4688. toRgb: function(includeAlpha) {
  4689. if(includeAlpha) {
  4690. return this.toRgba();
  4691. } else {
  4692. return [this.r, this.g, this.b];
  4693. }
  4694. },
  4695. toRgba: function() {
  4696. return [this.r, this.g, this.b, this.a];
  4697. },
  4698. toHex: function() {
  4699. return dojo.graphics.color.rgb2hex(this.toRgb());
  4700. },
  4701. toCss: function() {
  4702. return "rgb(" + this.toRgb().join() + ")";
  4703. },
  4704. toString: function() {
  4705. return this.toHex(); // decent default?
  4706. },
  4707. blend: function(color, weight) {
  4708. return dojo.graphics.color.blend(this.toRgb(), new dojo.graphics.color.Color(color).toRgb(), weight);
  4709. }
  4710. });
  4711. dojo.graphics.color.named = {
  4712. white: [255,255,255],
  4713. black: [0,0,0],
  4714. red: [255,0,0],
  4715. green: [0,255,0],
  4716. blue: [0,0,255],
  4717. navy: [0,0,128],
  4718. gray: [128,128,128],
  4719. silver: [192,192,192]
  4720. };
  4721. // blend colors a and b (both as RGB array or hex strings) with weight from -1 to +1, 0 being a 50/50 blend
  4722. dojo.graphics.color.blend = function(a, b, weight) {
  4723. if(typeof a == "string") { return dojo.graphics.color.blendHex(a, b, weight); }
  4724. if(!weight) { weight = 0; }
  4725. else if(weight > 1) { weight = 1; }
  4726. else if(weight < -1) { weight = -1; }
  4727. var c = new Array(3);
  4728. for(var i = 0; i < 3; i++) {
  4729. var half = Math.abs(a[i] - b[i])/2;
  4730. c[i] = Math.floor(Math.min(a[i], b[i]) + half + (half * weight));
  4731. }
  4732. return c;
  4733. }
  4734. // very convenient blend that takes and returns hex values
  4735. // (will get called automatically by blend when blend gets strings)
  4736. dojo.graphics.color.blendHex = function(a, b, weight) {
  4737. return dojo.graphics.color.rgb2hex(dojo.graphics.color.blend(dojo.graphics.color.hex2rgb(a), dojo.graphics.color.hex2rgb(b), weight));
  4738. }
  4739. // get RGB array from css-style color declarations
  4740. dojo.graphics.color.extractRGB = function(color) {
  4741. var hex = "0123456789abcdef";
  4742. color = color.toLowerCase();
  4743. if( color.indexOf("rgb") == 0 ) {
  4744. var matches = color.match(/rgba*\((\d+), *(\d+), *(\d+)/i);
  4745. var ret = matches.splice(1, 3);
  4746. return ret;
  4747. } else {
  4748. var colors = dojo.graphics.color.hex2rgb(color);
  4749. if(colors) {
  4750. return colors;
  4751. } else {
  4752. // named color (how many do we support?)
  4753. return dojo.graphics.color.named[color] || [255, 255, 255];
  4754. }
  4755. }
  4756. }
  4757. dojo.graphics.color.hex2rgb = function(hex) {
  4758. var hexNum = "0123456789ABCDEF";
  4759. var rgb = new Array(3);
  4760. if( hex.indexOf("#") == 0 ) { hex = hex.substring(1); }
  4761. hex = hex.toUpperCase();
  4762. if(hex.replace(new RegExp("["+hexNum+"]", "g"), "") != "") {
  4763. return null;
  4764. }
  4765. if( hex.length == 3 ) {
  4766. rgb[0] = hex.charAt(0) + hex.charAt(0)
  4767. rgb[1] = hex.charAt(1) + hex.charAt(1)
  4768. rgb[2] = hex.charAt(2) + hex.charAt(2);
  4769. } else {
  4770. rgb[0] = hex.substring(0, 2);
  4771. rgb[1] = hex.substring(2, 4);
  4772. rgb[2] = hex.substring(4);
  4773. }
  4774. for(var i = 0; i < rgb.length; i++) {
  4775. rgb[i] = hexNum.indexOf(rgb[i].charAt(0)) * 16 + hexNum.indexOf(rgb[i].charAt(1));
  4776. }
  4777. return rgb;
  4778. }
  4779. dojo.graphics.color.rgb2hex = function(r, g, b) {
  4780. if(dojo.lang.isArray(r)) {
  4781. g = r[1] || 0;
  4782. b = r[2] || 0;
  4783. r = r[0] || 0;
  4784. }
  4785. var ret = dojo.lang.map([r, g, b], function(x) {
  4786. x = new Number(x);
  4787. var s = x.toString(16);
  4788. while(s.length < 2) { s = "0" + s; }
  4789. return s;
  4790. });
  4791. ret.unshift("#");
  4792. return ret.join("");
  4793. }
  4794. dojo.provide("dojo.uri.Uri");
  4795. dojo.uri = new function() {
  4796. this.joinPath = function() {
  4797. // DEPRECATED: use the dojo.uri.Uri object instead
  4798. var arr = [];
  4799. for(var i = 0; i < arguments.length; i++) { arr.push(arguments[i]); }
  4800. return arr.join("/").replace(/\/{2,}/g, "/").replace(/((https*|ftps*):)/i, "$1/");
  4801. }
  4802. this.dojoUri = function (uri) {
  4803. // returns a Uri object resolved relative to the dojo root
  4804. return new dojo.uri.Uri(dojo.hostenv.getBaseScriptUri(), uri);
  4805. }
  4806. this.Uri = function (/*uri1, uri2, [...]*/) {
  4807. // An object representing a Uri.
  4808. // Each argument is evaluated in order relative to the next until
  4809. // a conanical uri is producued. To get an absolute Uri relative
  4810. // to the current document use
  4811. // new dojo.uri.Uri(document.baseURI, uri)
  4812. // TODO: support for IPv6, see RFC 2732
  4813. // resolve uri components relative to each other
  4814. var uri = arguments[0];
  4815. for (var i = 1; i < arguments.length; i++) {
  4816. if(!arguments[i]) { continue; }
  4817. // Safari doesn't support this.constructor so we have to be explicit
  4818. var relobj = new dojo.uri.Uri(arguments[i].toString());
  4819. var uriobj = new dojo.uri.Uri(uri.toString());
  4820. if (relobj.path == "" && relobj.scheme == null &&
  4821. relobj.authority == null && relobj.query == null) {
  4822. if (relobj.fragment != null) { uriobj.fragment = relobj.fragment; }
  4823. relobj = uriobj;
  4824. } else if (relobj.scheme == null) {
  4825. relobj.scheme = uriobj.scheme;
  4826. if (relobj.authority == null) {
  4827. relobj.authority = uriobj.authority;
  4828. if (relobj.path.charAt(0) != "/") {
  4829. var path = uriobj.path.substring(0,
  4830. uriobj.path.lastIndexOf("/") + 1) + relobj.path;
  4831. var segs = path.split("/");
  4832. for (var j = 0; j < segs.length; j++) {
  4833. if (segs[j] == ".") {
  4834. if (j == segs.length - 1) { segs[j] = ""; }
  4835. else { segs.splice(j, 1); j--; }
  4836. } else if (j > 0 && !(j == 1 && segs[0] == "") &&
  4837. segs[j] == ".." && segs[j-1] != "..") {
  4838. if (j == segs.length - 1) { segs.splice(j, 1); segs[j - 1] = ""; }
  4839. else { segs.splice(j - 1, 2); j -= 2; }
  4840. }
  4841. }
  4842. relobj.path = segs.join("/");
  4843. }
  4844. }
  4845. }
  4846. uri = "";
  4847. if (relobj.scheme != null) { uri += relobj.scheme + ":"; }
  4848. if (relobj.authority != null) { uri += "//" + relobj.authority; }
  4849. uri += relobj.path;
  4850. if (relobj.query != null) { uri += "?" + relobj.query; }
  4851. if (relobj.fragment != null) { uri += "#" + relobj.fragment; }
  4852. }
  4853. this.uri = uri.toString();
  4854. // break the uri into its main components
  4855. var regexp = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$";
  4856. var r = this.uri.match(new RegExp(regexp));
  4857. this.scheme = r[2] || (r[1] ? "" : null);
  4858. this.authority = r[4] || (r[3] ? "" : null);
  4859. this.path = r[5]; // can never be undefined
  4860. this.query = r[7] || (r[6] ? "" : null);
  4861. this.fragment = r[9] || (r[8] ? "" : null);
  4862. if (this.authority != null) {
  4863. // server based naming authority
  4864. regexp = "^((([^:]+:)?([^@]+))@)?([^:]*)(:([0-9]+))?$";
  4865. r = this.authority.match(new RegExp(regexp));
  4866. this.user = r[3] || null;
  4867. this.password = r[4] || null;
  4868. this.host = r[5];
  4869. this.port = r[7] || null;
  4870. }
  4871. this.toString = function(){ return this.uri; }
  4872. }
  4873. };
  4874. dojo.provide("dojo.style");
  4875. dojo.require("dojo.graphics.color");
  4876. dojo.require("dojo.uri.Uri");
  4877. dojo.require("dojo.lang.common");
  4878. (function(){
  4879. var h = dojo.render.html;
  4880. var ds = dojo.style;
  4881. var db = document["body"]||document["documentElement"];
  4882. ds.boxSizing = {
  4883. MARGIN_BOX: "margin-box",
  4884. BORDER_BOX: "border-box",
  4885. PADDING_BOX: "padding-box",
  4886. CONTENT_BOX: "content-box"
  4887. };
  4888. var bs = ds.boxSizing;
  4889. ds.getBoxSizing = function(node){
  4890. if((h.ie)||(h.opera)){
  4891. var cm = document["compatMode"];
  4892. if((cm == "BackCompat")||(cm == "QuirksMode")){
  4893. return bs.BORDER_BOX;
  4894. }else{
  4895. return bs.CONTENT_BOX;
  4896. }
  4897. }else{
  4898. if(arguments.length == 0){ node = document.documentElement; }
  4899. var sizing = ds.getStyle(node, "-moz-box-sizing");
  4900. if(!sizing){ sizing = ds.getStyle(node, "box-sizing"); }
  4901. return (sizing ? sizing : bs.CONTENT_BOX);
  4902. }
  4903. }
  4904. /*
  4905. The following several function use the dimensions shown below
  4906. +-------------------------+
  4907. | margin |
  4908. | +---------------------+ |
  4909. | | border | |
  4910. | | +-----------------+ | |
  4911. | | | padding | | |
  4912. | | | +-------------+ | | |
  4913. | | | | content | | | |
  4914. | | | +-------------+ | | |
  4915. | | +-|-------------|-+ | |
  4916. | +-|-|-------------|-|-+ |
  4917. +-|-|-|-------------|-|-|-+
  4918. | | | | | | | |
  4919. | | | |<- content ->| | | |
  4920. | |<------ inner ------>| |
  4921. |<-------- outer -------->|
  4922. +-------------------------+
  4923. * content-box
  4924. |m|b|p| |p|b|m|
  4925. | |<------ offset ----->| |
  4926. | | |<---- client --->| | |
  4927. | | | |<-- width -->| | | |
  4928. * border-box
  4929. |m|b|p| |p|b|m|
  4930. | |<------ offset ----->| |
  4931. | | |<---- client --->| | |
  4932. | |<------ width ------>| |
  4933. */
  4934. /*
  4935. Notes:
  4936. General:
  4937. - Uncomputable values are returned as NaN.
  4938. - setOuterWidth/Height return *false* if the outer size could not
  4939. be computed, otherwise *true*.
  4940. - (sjmiles) knows no way to find the calculated values for auto-margins.
  4941. - All returned values are floating point in 'px' units. If a
  4942. non-zero computed style value is not specified in 'px', NaN is
  4943. returned.
  4944. FF:
  4945. - styles specified as '0' (unitless 0) show computed as '0pt'.
  4946. IE:
  4947. - clientWidth/Height are unreliable (0 unless the object has 'layout').
  4948. - margins must be specified in px, or 0 (in any unit) for any
  4949. sizing function to work. Otherwise margins detect as 'auto'.
  4950. - padding can be empty or, if specified, must be in px, or 0 (in
  4951. any unit) for any sizing function to work.
  4952. Safari:
  4953. - Safari defaults padding values to 'auto'.
  4954. See the unit tests for examples of (un)computable values in a given browser.
  4955. */
  4956. // FIXME: these work for some elements (e.g. DIV) but not others (e.g. TABLE, TEXTAREA)
  4957. ds.isBorderBox = function(node){
  4958. return (ds.getBoxSizing(node) == bs.BORDER_BOX);
  4959. }
  4960. ds.getUnitValue = function(node, cssSelector, autoIsZero){
  4961. var s = ds.getComputedStyle(node, cssSelector);
  4962. if((!s)||((s == 'auto')&&(autoIsZero))){ return { value: 0, units: 'px' }; }
  4963. if(dojo.lang.isUndefined(s)){return ds.getUnitValue.bad;}
  4964. // FIXME: is regex inefficient vs. parseInt or some manual test?
  4965. var match = s.match(/(\-?[\d.]+)([a-z%]*)/i);
  4966. if (!match){return ds.getUnitValue.bad;}
  4967. return { value: Number(match[1]), units: match[2].toLowerCase() };
  4968. }
  4969. // FIXME: 'bad' value should be 0?
  4970. ds.getUnitValue.bad = { value: NaN, units: '' };
  4971. ds.getPixelValue = function(node, cssSelector, autoIsZero){
  4972. var result = ds.getUnitValue(node, cssSelector, autoIsZero);
  4973. // FIXME: there is serious debate as to whether or not this is the right solution
  4974. if(isNaN(result.value)){ return 0; }
  4975. // FIXME: code exists for converting other units to px (see Dean Edward's IE7)
  4976. // but there are cross-browser complexities
  4977. if((result.value)&&(result.units != 'px')){ return NaN; }
  4978. return result.value;
  4979. }
  4980. // FIXME: deprecated
  4981. ds.getNumericStyle = function() {
  4982. dojo.deprecated('dojo.(style|html).getNumericStyle', 'in favor of dojo.(style|html).getPixelValue', '0.4');
  4983. return ds.getPixelValue.apply(this, arguments);
  4984. }
  4985. ds.setPositivePixelValue = function(node, selector, value){
  4986. if(isNaN(value)){return false;}
  4987. node.style[selector] = Math.max(0, value) + 'px';
  4988. return true;
  4989. }
  4990. ds._sumPixelValues = function(node, selectors, autoIsZero){
  4991. var total = 0;
  4992. for(var x=0; x<selectors.length; x++){
  4993. total += ds.getPixelValue(node, selectors[x], autoIsZero);
  4994. }
  4995. return total;
  4996. }
  4997. ds.isPositionAbsolute = function(node){
  4998. return (ds.getComputedStyle(node, 'position') == 'absolute');
  4999. }
  5000. ds.getBorderExtent = function(node, side){
  5001. return (ds.getStyle(node, 'border-' + side + '-style') == 'none' ? 0 : ds.getPixelValue(node, 'border-' + side + '-width'));
  5002. }
  5003. ds.getMarginWidth = function(node){
  5004. return ds._sumPixelValues(node, ["margin-left", "margin-right"], ds.isPositionAbsolute(node));
  5005. }
  5006. ds.getBorderWidth = function(node){
  5007. return ds.getBorderExtent(node, 'left') + ds.getBorderExtent(node, 'right');
  5008. }
  5009. ds.getPaddingWidth = function(node){
  5010. return ds._sumPixelValues(node, ["padding-left", "padding-right"], true);
  5011. }
  5012. ds.getPadBorderWidth = function(node) {
  5013. return ds.getPaddingWidth(node) + ds.getBorderWidth(node);
  5014. }
  5015. ds.getContentBoxWidth = function(node){
  5016. node = dojo.byId(node);
  5017. return node.offsetWidth - ds.getPadBorderWidth(node);
  5018. }
  5019. ds.getBorderBoxWidth = function(node){
  5020. node = dojo.byId(node);
  5021. return node.offsetWidth;
  5022. }
  5023. ds.getMarginBoxWidth = function(node){
  5024. return ds.getInnerWidth(node) + ds.getMarginWidth(node);
  5025. }
  5026. ds.setContentBoxWidth = function(node, pxWidth){
  5027. node = dojo.byId(node);
  5028. if (ds.isBorderBox(node)){
  5029. pxWidth += ds.getPadBorderWidth(node);
  5030. }
  5031. return ds.setPositivePixelValue(node, "width", pxWidth);
  5032. }
  5033. ds.setMarginBoxWidth = function(node, pxWidth){
  5034. node = dojo.byId(node);
  5035. if (!ds.isBorderBox(node)){
  5036. pxWidth -= ds.getPadBorderWidth(node);
  5037. }
  5038. pxWidth -= ds.getMarginWidth(node);
  5039. return ds.setPositivePixelValue(node, "width", pxWidth);
  5040. }
  5041. // FIXME: deprecate and remove
  5042. ds.getContentWidth = ds.getContentBoxWidth;
  5043. ds.getInnerWidth = ds.getBorderBoxWidth;
  5044. ds.getOuterWidth = ds.getMarginBoxWidth;
  5045. ds.setContentWidth = ds.setContentBoxWidth;
  5046. ds.setOuterWidth = ds.setMarginBoxWidth;
  5047. ds.getMarginHeight = function(node){
  5048. return ds._sumPixelValues(node, ["margin-top", "margin-bottom"], ds.isPositionAbsolute(node));
  5049. }
  5050. ds.getBorderHeight = function(node){
  5051. return ds.getBorderExtent(node, 'top') + ds.getBorderExtent(node, 'bottom');
  5052. }
  5053. ds.getPaddingHeight = function(node){
  5054. return ds._sumPixelValues(node, ["padding-top", "padding-bottom"], true);
  5055. }
  5056. ds.getPadBorderHeight = function(node) {
  5057. return ds.getPaddingHeight(node) + ds.getBorderHeight(node);
  5058. }
  5059. ds.getContentBoxHeight = function(node){
  5060. node = dojo.byId(node);
  5061. return node.offsetHeight - ds.getPadBorderHeight(node);
  5062. }
  5063. ds.getBorderBoxHeight = function(node){
  5064. node = dojo.byId(node);
  5065. return node.offsetHeight; // FIXME: does this work?
  5066. }
  5067. ds.getMarginBoxHeight = function(node){
  5068. return ds.getInnerHeight(node) + ds.getMarginHeight(node);
  5069. }
  5070. ds.setContentBoxHeight = function(node, pxHeight){
  5071. node = dojo.byId(node);
  5072. if (ds.isBorderBox(node)){
  5073. pxHeight += ds.getPadBorderHeight(node);
  5074. }
  5075. return ds.setPositivePixelValue(node, "height", pxHeight);
  5076. }
  5077. ds.setMarginBoxHeight = function(node, pxHeight){
  5078. node = dojo.byId(node);
  5079. if (!ds.isBorderBox(node)){
  5080. pxHeight -= ds.getPadBorderHeight(node);
  5081. }
  5082. pxHeight -= ds.getMarginHeight(node);
  5083. return ds.setPositivePixelValue(node, "height", pxHeight);
  5084. }
  5085. // FIXME: deprecate and remove
  5086. ds.getContentHeight = ds.getContentBoxHeight;
  5087. ds.getInnerHeight = ds.getBorderBoxHeight;
  5088. ds.getOuterHeight = ds.getMarginBoxHeight;
  5089. ds.setContentHeight = ds.setContentBoxHeight;
  5090. ds.setOuterHeight = ds.setMarginBoxHeight;
  5091. /**
  5092. * dojo.style.getAbsolutePosition(xyz, true) returns xyz's position relative to the document.
  5093. * Itells you where you would position a node
  5094. * inside document.body such that it was on top of xyz. Most people set the flag to true when calling
  5095. * getAbsolutePosition().
  5096. *
  5097. * dojo.style.getAbsolutePosition(xyz, false) returns xyz's position relative to the viewport.
  5098. * It returns the position that would be returned
  5099. * by event.clientX/Y if the mouse were directly over the top/left of this node.
  5100. */
  5101. ds.getAbsolutePosition = ds.abs = function(node, includeScroll){
  5102. node = dojo.byId(node);
  5103. var ret = [];
  5104. ret.x = ret.y = 0;
  5105. var st = dojo.html.getScrollTop();
  5106. var sl = dojo.html.getScrollLeft();
  5107. if(h.ie){
  5108. with(node.getBoundingClientRect()){
  5109. ret.x = left-2;
  5110. ret.y = top-2;
  5111. }
  5112. }else if(document.getBoxObjectFor){
  5113. // mozilla
  5114. var bo = document.getBoxObjectFor(node);
  5115. ret.x = bo.x - ds.sumAncestorProperties(node, "scrollLeft");
  5116. ret.y = bo.y - ds.sumAncestorProperties(node, "scrollTop");
  5117. }else{
  5118. if(node["offsetParent"]){
  5119. var endNode;
  5120. // in Safari, if the node is an absolutely positioned child of
  5121. // the body and the body has a margin the offset of the child
  5122. // and the body contain the body's margins, so we need to end
  5123. // at the body
  5124. if( (h.safari)&&
  5125. (node.style.getPropertyValue("position") == "absolute")&&
  5126. (node.parentNode == db)){
  5127. endNode = db;
  5128. }else{
  5129. endNode = db.parentNode;
  5130. }
  5131. if(node.parentNode != db){
  5132. var nd = node;
  5133. if(window.opera){ nd = db; }
  5134. ret.x -= ds.sumAncestorProperties(nd, "scrollLeft");
  5135. ret.y -= ds.sumAncestorProperties(nd, "scrollTop");
  5136. }
  5137. do{
  5138. var n = node["offsetLeft"];
  5139. ret.x += isNaN(n) ? 0 : n;
  5140. var m = node["offsetTop"];
  5141. ret.y += isNaN(m) ? 0 : m;
  5142. node = node.offsetParent;
  5143. }while((node != endNode)&&(node != null));
  5144. }else if(node["x"]&&node["y"]){
  5145. ret.x += isNaN(node.x) ? 0 : node.x;
  5146. ret.y += isNaN(node.y) ? 0 : node.y;
  5147. }
  5148. }
  5149. // account for document scrolling!
  5150. if(includeScroll){
  5151. ret.y += st;
  5152. ret.x += sl;
  5153. }
  5154. ret[0] = ret.x;
  5155. ret[1] = ret.y;
  5156. return ret;
  5157. }
  5158. ds.sumAncestorProperties = function(node, prop){
  5159. node = dojo.byId(node);
  5160. if(!node){ return 0; } // FIXME: throw an error?
  5161. var retVal = 0;
  5162. while(node){
  5163. var val = node[prop];
  5164. if(val){
  5165. retVal += val - 0;
  5166. if(node==document.body){ break; }// opera and khtml #body & #html has the same values, we only need one value
  5167. }
  5168. node = node.parentNode;
  5169. }
  5170. return retVal;
  5171. }
  5172. ds.getTotalOffset = function(node, type, includeScroll){
  5173. return ds.abs(node, includeScroll)[(type == "top") ? "y" : "x"];
  5174. }
  5175. ds.getAbsoluteX = ds.totalOffsetLeft = function(node, includeScroll){
  5176. return ds.getTotalOffset(node, "left", includeScroll);
  5177. }
  5178. ds.getAbsoluteY = ds.totalOffsetTop = function(node, includeScroll){
  5179. return ds.getTotalOffset(node, "top", includeScroll);
  5180. }
  5181. ds.styleSheet = null;
  5182. // FIXME: this is a really basic stub for adding and removing cssRules, but
  5183. // it assumes that you know the index of the cssRule that you want to add
  5184. // or remove, making it less than useful. So we need something that can
  5185. // search for the selector that you you want to remove.
  5186. ds.insertCssRule = function(selector, declaration, index) {
  5187. if (!ds.styleSheet) {
  5188. if (document.createStyleSheet) { // IE
  5189. ds.styleSheet = document.createStyleSheet();
  5190. } else if (document.styleSheets[0]) { // rest
  5191. // FIXME: should create a new style sheet here
  5192. // fall back on an exsiting style sheet
  5193. ds.styleSheet = document.styleSheets[0];
  5194. } else { return null; } // fail
  5195. }
  5196. if (arguments.length < 3) { // index may == 0
  5197. if (ds.styleSheet.cssRules) { // W3
  5198. index = ds.styleSheet.cssRules.length;
  5199. } else if (ds.styleSheet.rules) { // IE
  5200. index = ds.styleSheet.rules.length;
  5201. } else { return null; } // fail
  5202. }
  5203. if (ds.styleSheet.insertRule) { // W3
  5204. var rule = selector + " { " + declaration + " }";
  5205. return ds.styleSheet.insertRule(rule, index);
  5206. } else if (ds.styleSheet.addRule) { // IE
  5207. return ds.styleSheet.addRule(selector, declaration, index);
  5208. } else { return null; } // fail
  5209. }
  5210. ds.removeCssRule = function(index){
  5211. if(!ds.styleSheet){
  5212. dojo.debug("no stylesheet defined for removing rules");
  5213. return false;
  5214. }
  5215. if(h.ie){
  5216. if(!index){
  5217. index = ds.styleSheet.rules.length;
  5218. ds.styleSheet.removeRule(index);
  5219. }
  5220. }else if(document.styleSheets[0]){
  5221. if(!index){
  5222. index = ds.styleSheet.cssRules.length;
  5223. }
  5224. ds.styleSheet.deleteRule(index);
  5225. }
  5226. return true;
  5227. }
  5228. // calls css by XmlHTTP and inserts it into DOM as <style [widgetType="widgetType"]> *downloaded cssText*</style>
  5229. ds.insertCssFile = function(URI, doc, checkDuplicates){
  5230. if(!URI){ return; }
  5231. if(!doc){ doc = document; }
  5232. var cssStr = dojo.hostenv.getText(URI);
  5233. cssStr = ds.fixPathsInCssText(cssStr, URI);
  5234. if(checkDuplicates){
  5235. var styles = doc.getElementsByTagName("style");
  5236. var cssText = "";
  5237. for(var i = 0; i<styles.length; i++){
  5238. cssText = (styles[i].styleSheet && styles[i].styleSheet.cssText) ? styles[i].styleSheet.cssText : styles[i].innerHTML;
  5239. if(cssStr == cssText){ return; }
  5240. }
  5241. }
  5242. var style = ds.insertCssText(cssStr);
  5243. // insert custom attribute ex dbgHref="../foo.css" usefull when debugging in DOM inspectors, no?
  5244. if(style && djConfig.isDebug){
  5245. style.setAttribute("dbgHref", URI);
  5246. }
  5247. return style
  5248. }
  5249. // DomNode Style = insertCssText(String ".dojoMenu {color: green;}"[, DomDoc document, dojo.uri.Uri Url ])
  5250. ds.insertCssText = function(cssStr, doc, URI){
  5251. if(!cssStr){ return; }
  5252. if(!doc){ doc = document; }
  5253. if(URI){// fix paths in cssStr
  5254. cssStr = ds.fixPathsInCssText(cssStr, URI);
  5255. }
  5256. var style = doc.createElement("style");
  5257. style.setAttribute("type", "text/css");
  5258. // IE is b0rken enough to require that we add the element to the doc
  5259. // before changing it's properties
  5260. var head = doc.getElementsByTagName("head")[0];
  5261. if(!head){ // must have a head tag
  5262. dojo.debug("No head tag in document, aborting styles");
  5263. return;
  5264. }else{
  5265. head.appendChild(style);
  5266. }
  5267. if(style.styleSheet){// IE
  5268. style.styleSheet.cssText = cssStr;
  5269. }else{ // w3c
  5270. var cssText = doc.createTextNode(cssStr);
  5271. style.appendChild(cssText);
  5272. }
  5273. return style;
  5274. }
  5275. // String cssText = fixPathsInCssText(String cssStr, dojo.uri.Uri URI)
  5276. // usage: cssText comes from dojoroot/src/widget/templates/HtmlFoobar.css
  5277. // it has .dojoFoo { background-image: url(images/bar.png);}
  5278. // then uri should point to dojoroot/src/widget/templates/
  5279. ds.fixPathsInCssText = function(cssStr, URI){
  5280. if(!cssStr || !URI){ return; }
  5281. var pos = 0; var str = ""; var url = "";
  5282. while(pos!=-1){
  5283. pos = 0;url = "";
  5284. pos = cssStr.indexOf("url(", pos);
  5285. if(pos<0){ break; }
  5286. str += cssStr.slice(0,pos+4);
  5287. cssStr = cssStr.substring(pos+4, cssStr.length);
  5288. url += cssStr.match(/^[\t\s\w()\/.\\'"-:#=&?]*\)/)[0]; // url string
  5289. cssStr = cssStr.substring(url.length-1, cssStr.length); // remove url from css string til next loop
  5290. url = url.replace(/^[\s\t]*(['"]?)([\w()\/.\\'"-:#=&?]*)\1[\s\t]*?\)/,"$2"); // clean string
  5291. if(url.search(/(file|https?|ftps?):\/\//)==-1){
  5292. url = (new dojo.uri.Uri(URI,url).toString());
  5293. }
  5294. str += url;
  5295. };
  5296. return str+cssStr;
  5297. }
  5298. ds.getBackgroundColor = function(node) {
  5299. node = dojo.byId(node);
  5300. var color;
  5301. do{
  5302. color = ds.getStyle(node, "background-color");
  5303. // Safari doesn't say "transparent"
  5304. if(color.toLowerCase() == "rgba(0, 0, 0, 0)") { color = "transparent"; }
  5305. if(node == document.getElementsByTagName("body")[0]) { node = null; break; }
  5306. node = node.parentNode;
  5307. }while(node && dojo.lang.inArray(color, ["transparent", ""]));
  5308. if(color == "transparent"){
  5309. color = [255, 255, 255, 0];
  5310. }else{
  5311. color = dojo.graphics.color.extractRGB(color);
  5312. }
  5313. return color;
  5314. }
  5315. ds.getComputedStyle = function(node, cssSelector, inValue){
  5316. node = dojo.byId(node);
  5317. // cssSelector may actually be in camel case, so force selector version
  5318. var cssSelector = ds.toSelectorCase(cssSelector);
  5319. var property = ds.toCamelCase(cssSelector);
  5320. if(!node || !node.style){
  5321. return inValue;
  5322. }else if(document.defaultView){ // W3, gecko, KHTML
  5323. try{
  5324. var cs = document.defaultView.getComputedStyle(node, "");
  5325. if (cs){
  5326. return cs.getPropertyValue(cssSelector);
  5327. }
  5328. }catch(e){ // reports are that Safari can throw an exception above
  5329. if (node.style.getPropertyValue){ // W3
  5330. return node.style.getPropertyValue(cssSelector);
  5331. }else return inValue;
  5332. }
  5333. }else if(node.currentStyle){ // IE
  5334. return node.currentStyle[property];
  5335. }if(node.style.getPropertyValue){ // W3
  5336. return node.style.getPropertyValue(cssSelector);
  5337. }else{
  5338. return inValue;
  5339. }
  5340. }
  5341. /**
  5342. * Retrieve a property value from a node's style object.
  5343. */
  5344. ds.getStyleProperty = function(node, cssSelector){
  5345. node = dojo.byId(node);
  5346. // FIXME: should we use node.style.getPropertyValue over style[property]?
  5347. // style[property] works in all (modern) browsers, getPropertyValue is W3 but not supported in IE
  5348. // FIXME: what about runtimeStyle?
  5349. return (node && node.style ? node.style[ds.toCamelCase(cssSelector)] : undefined);
  5350. }
  5351. /**
  5352. * Retrieve a property value from a node's style object.
  5353. */
  5354. ds.getStyle = function(node, cssSelector){
  5355. var value = ds.getStyleProperty(node, cssSelector);
  5356. return (value ? value : ds.getComputedStyle(node, cssSelector));
  5357. }
  5358. ds.setStyle = function(node, cssSelector, value){
  5359. node = dojo.byId(node);
  5360. if(node && node.style){
  5361. var camelCased = ds.toCamelCase(cssSelector);
  5362. node.style[camelCased] = value;
  5363. }
  5364. }
  5365. ds.toCamelCase = function(selector) {
  5366. var arr = selector.split('-'), cc = arr[0];
  5367. for(var i = 1; i < arr.length; i++) {
  5368. cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
  5369. }
  5370. return cc;
  5371. }
  5372. ds.toSelectorCase = function(selector) {
  5373. return selector.replace(/([A-Z])/g, "-$1" ).toLowerCase() ;
  5374. }
  5375. /* float between 0.0 (transparent) and 1.0 (opaque) */
  5376. ds.setOpacity = function setOpacity(node, opacity, dontFixOpacity) {
  5377. node = dojo.byId(node);
  5378. if(!dontFixOpacity){
  5379. if( opacity >= 1.0){
  5380. if(h.ie){
  5381. ds.clearOpacity(node);
  5382. return;
  5383. }else{
  5384. opacity = 0.999999;
  5385. }
  5386. }else if( opacity < 0.0){ opacity = 0; }
  5387. }
  5388. if(h.ie){
  5389. if(node.nodeName.toLowerCase() == "tr"){
  5390. // FIXME: is this too naive? will we get more than we want?
  5391. var tds = node.getElementsByTagName("td");
  5392. for(var x=0; x<tds.length; x++){
  5393. tds[x].style.filter = "Alpha(Opacity="+opacity*100+")";
  5394. }
  5395. }
  5396. node.style.filter = "Alpha(Opacity="+opacity*100+")";
  5397. }else if(h.moz){
  5398. node.style.opacity = opacity; // ffox 1.0 directly supports "opacity"
  5399. node.style.MozOpacity = opacity;
  5400. }else if(h.safari){
  5401. node.style.opacity = opacity; // 1.3 directly supports "opacity"
  5402. node.style.KhtmlOpacity = opacity;
  5403. }else{
  5404. node.style.opacity = opacity;
  5405. }
  5406. }
  5407. ds.getOpacity = function getOpacity (node){
  5408. node = dojo.byId(node);
  5409. if(h.ie){
  5410. var opac = (node.filters && node.filters.alpha &&
  5411. typeof node.filters.alpha.opacity == "number"
  5412. ? node.filters.alpha.opacity : 100) / 100;
  5413. }else{
  5414. var opac = node.style.opacity || node.style.MozOpacity ||
  5415. node.style.KhtmlOpacity || 1;
  5416. }
  5417. return opac >= 0.999999 ? 1.0 : Number(opac);
  5418. }
  5419. ds.clearOpacity = function clearOpacity(node){
  5420. node = dojo.byId(node);
  5421. var ns = node.style;
  5422. if(h.ie){
  5423. try {
  5424. if( node.filters && node.filters.alpha ){
  5425. ns.filter = ""; // FIXME: may get rid of other filter effects
  5426. }
  5427. } catch(e) {
  5428. /*
  5429. * IE7 gives error if node.filters not set;
  5430. * don't know why or how to workaround (other than this)
  5431. */
  5432. }
  5433. }else if(h.moz){
  5434. ns.opacity = 1;
  5435. ns.MozOpacity = 1;
  5436. }else if(h.safari){
  5437. ns.opacity = 1;
  5438. ns.KhtmlOpacity = 1;
  5439. }else{
  5440. ns.opacity = 1;
  5441. }
  5442. }
  5443. /**
  5444. * Set the given style attributes for the node.
  5445. * Patch submitted by Wolfram Kriesing, 22/03/2006.
  5446. *
  5447. * Ie. dojo.style.setStyleAttributes(myNode, "position:absolute; left:10px; top:10px;")
  5448. * This just makes it easier to set a style directly without the need to
  5449. * override it completely (as node.setAttribute() would).
  5450. * If there is a dojo-method for an attribute, like for "opacity" there
  5451. * is setOpacity, the dojo method is called instead.
  5452. * For example: dojo.style.setStyleAttributes(myNode, "opacity: .4");
  5453. *
  5454. * Additionally all the dojo.style.set* methods can also be used.
  5455. * Ie. when attributes contains "outer-height: 10;" it will call dojo.style.setOuterHeight("10");
  5456. *
  5457. * @param object The node to set the style attributes for.
  5458. * @param string Ie. "position:absolute; left:10px; top:10px;"
  5459. */
  5460. ds.setStyleAttributes = function(node, attributes) {
  5461. var methodMap={
  5462. "opacity":dojo.style.setOpacity,
  5463. "content-height":dojo.style.setContentHeight,
  5464. "content-width":dojo.style.setContentWidth,
  5465. "outer-height":dojo.style.setOuterHeight,
  5466. "outer-width":dojo.style.setOuterWidth
  5467. }
  5468. var splittedAttribs=attributes.replace(/(;)?\s*$/, "").split(";");
  5469. for(var i=0; i<splittedAttribs.length; i++){
  5470. var nameValue=splittedAttribs[i].split(":");
  5471. var name=nameValue[0].replace(/\s*$/, "").replace(/^\s*/, "").toLowerCase();
  5472. var value=nameValue[1].replace(/\s*$/, "").replace(/^\s*/, "");
  5473. if(dojo.lang.has(methodMap,name)) {
  5474. methodMap[name](node,value);
  5475. } else {
  5476. node.style[dojo.style.toCamelCase(name)]=value;
  5477. }
  5478. }
  5479. }
  5480. ds._toggle = function(node, tester, setter){
  5481. node = dojo.byId(node);
  5482. setter(node, !tester(node));
  5483. return tester(node);
  5484. }
  5485. // show/hide are library constructs
  5486. // show()
  5487. // if the node.style.display == 'none' then
  5488. // set style.display to '' or the value cached by hide()
  5489. ds.show = function(node){
  5490. node = dojo.byId(node);
  5491. if(ds.getStyleProperty(node, 'display')=='none'){
  5492. ds.setStyle(node, 'display', (node.dojoDisplayCache||''));
  5493. node.dojoDisplayCache = undefined; // cannot use delete on a node in IE6
  5494. }
  5495. }
  5496. // if the node.style.display == 'none' then
  5497. // set style.display to '' or the value cached by hide()
  5498. ds.hide = function(node){
  5499. node = dojo.byId(node);
  5500. if(typeof node["dojoDisplayCache"] == "undefined"){ // it could == '', so we cannot say !node.dojoDisplayCount
  5501. var d = ds.getStyleProperty(node, 'display')
  5502. if(d!='none'){
  5503. node.dojoDisplayCache = d;
  5504. }
  5505. }
  5506. ds.setStyle(node, 'display', 'none');
  5507. }
  5508. // setShowing() calls show() if showing is true, hide() otherwise
  5509. ds.setShowing = function(node, showing){
  5510. ds[(showing ? 'show' : 'hide')](node);
  5511. }
  5512. // isShowing() is true if the node.style.display is not 'none'
  5513. // FIXME: returns true if node is bad, isHidden would be easier to make correct
  5514. ds.isShowing = function(node){
  5515. return (ds.getStyleProperty(node, 'display') != 'none');
  5516. }
  5517. // Call setShowing() on node with the complement of isShowing(), then return the new value of isShowing()
  5518. ds.toggleShowing = function(node){
  5519. return ds._toggle(node, ds.isShowing, ds.setShowing);
  5520. }
  5521. // display is a CSS concept
  5522. // Simple mapping of tag names to display values
  5523. // FIXME: simplistic
  5524. ds.displayMap = { tr: '', td: '', th: '', img: 'inline', span: 'inline', input: 'inline', button: 'inline' };
  5525. // Suggest a value for the display property that will show 'node' based on it's tag
  5526. ds.suggestDisplayByTagName = function(node)
  5527. {
  5528. node = dojo.byId(node);
  5529. if(node && node.tagName){
  5530. var tag = node.tagName.toLowerCase();
  5531. return (tag in ds.displayMap ? ds.displayMap[tag] : 'block');
  5532. }
  5533. }
  5534. // setDisplay() sets the value of style.display to value of 'display' parameter if it is a string.
  5535. // Otherwise, if 'display' is false, set style.display to 'none'.
  5536. // Finally, set 'display' to a suggested display value based on the node's tag
  5537. ds.setDisplay = function(node, display){
  5538. ds.setStyle(node, 'display', (dojo.lang.isString(display) ? display : (display ? ds.suggestDisplayByTagName(node) : 'none')));
  5539. }
  5540. // isDisplayed() is true if the the computed display style for node is not 'none'
  5541. // FIXME: returns true if node is bad, isNotDisplayed would be easier to make correct
  5542. ds.isDisplayed = function(node){
  5543. return (ds.getComputedStyle(node, 'display') != 'none');
  5544. }
  5545. // Call setDisplay() on node with the complement of isDisplayed(), then
  5546. // return the new value of isDisplayed()
  5547. ds.toggleDisplay = function(node){
  5548. return ds._toggle(node, ds.isDisplayed, ds.setDisplay);
  5549. }
  5550. // visibility is a CSS concept
  5551. // setVisibility() sets the value of style.visibility to value of
  5552. // 'visibility' parameter if it is a string.
  5553. // Otherwise, if 'visibility' is false, set style.visibility to 'hidden'.
  5554. // Finally, set style.visibility to 'visible'.
  5555. ds.setVisibility = function(node, visibility){
  5556. ds.setStyle(node, 'visibility', (dojo.lang.isString(visibility) ? visibility : (visibility ? 'visible' : 'hidden')));
  5557. }
  5558. // isVisible() is true if the the computed visibility style for node is not 'hidden'
  5559. // FIXME: returns true if node is bad, isInvisible would be easier to make correct
  5560. ds.isVisible = function(node){
  5561. return (ds.getComputedStyle(node, 'visibility') != 'hidden');
  5562. }
  5563. // Call setVisibility() on node with the complement of isVisible(), then
  5564. // return the new value of isVisible()
  5565. ds.toggleVisibility = function(node){
  5566. return ds._toggle(node, ds.isVisible, ds.setVisibility);
  5567. }
  5568. // in: coordinate array [x,y,w,h] or dom node
  5569. // return: coordinate array
  5570. ds.toCoordinateArray = function(coords, includeScroll) {
  5571. if(dojo.lang.isArray(coords)){
  5572. // coords is already an array (of format [x,y,w,h]), just return it
  5573. while ( coords.length < 4 ) { coords.push(0); }
  5574. while ( coords.length > 4 ) { coords.pop(); }
  5575. var ret = coords;
  5576. } else {
  5577. // coords is an dom object (or dom object id); return it's coordinates
  5578. var node = dojo.byId(coords);
  5579. var pos = ds.getAbsolutePosition(node, includeScroll);
  5580. var ret = [
  5581. pos.x,
  5582. pos.y,
  5583. ds.getBorderBoxWidth(node),
  5584. ds.getBorderBoxHeight(node)
  5585. ];
  5586. }
  5587. ret.x = ret[0];
  5588. ret.y = ret[1];
  5589. ret.w = ret[2];
  5590. ret.h = ret[3];
  5591. return ret;
  5592. };
  5593. })();
  5594. dojo.provide("dojo.html");
  5595. dojo.require("dojo.lang.func");
  5596. dojo.require("dojo.dom");
  5597. dojo.require("dojo.style");
  5598. dojo.require("dojo.string");
  5599. dojo.lang.mixin(dojo.html, dojo.dom);
  5600. dojo.lang.mixin(dojo.html, dojo.style);
  5601. // FIXME: we are going to assume that we can throw any and every rendering
  5602. // engine into the IE 5.x box model. In Mozilla, we do this w/ CSS.
  5603. // Need to investigate for KHTML and Opera
  5604. dojo.html.clearSelection = function(){
  5605. try{
  5606. if(window["getSelection"]){
  5607. if(dojo.render.html.safari){
  5608. // pulled from WebCore/ecma/kjs_window.cpp, line 2536
  5609. window.getSelection().collapse();
  5610. }else{
  5611. window.getSelection().removeAllRanges();
  5612. }
  5613. }else if(document.selection){
  5614. if(document.selection.empty){
  5615. document.selection.empty();
  5616. }else if(document.selection.clear){
  5617. document.selection.clear();
  5618. }
  5619. }
  5620. return true;
  5621. }catch(e){
  5622. dojo.debug(e);
  5623. return false;
  5624. }
  5625. }
  5626. dojo.html.disableSelection = function(element){
  5627. element = dojo.byId(element)||document.body;
  5628. var h = dojo.render.html;
  5629. if(h.mozilla){
  5630. element.style.MozUserSelect = "none";
  5631. }else if(h.safari){
  5632. element.style.KhtmlUserSelect = "none";
  5633. }else if(h.ie){
  5634. element.unselectable = "on";
  5635. }else{
  5636. return false;
  5637. }
  5638. return true;
  5639. }
  5640. dojo.html.enableSelection = function(element){
  5641. element = dojo.byId(element)||document.body;
  5642. var h = dojo.render.html;
  5643. if(h.mozilla){
  5644. element.style.MozUserSelect = "";
  5645. }else if(h.safari){
  5646. element.style.KhtmlUserSelect = "";
  5647. }else if(h.ie){
  5648. element.unselectable = "off";
  5649. }else{
  5650. return false;
  5651. }
  5652. return true;
  5653. }
  5654. dojo.html.selectElement = function(element){
  5655. element = dojo.byId(element);
  5656. if(document.selection && document.body.createTextRange){ // IE
  5657. var range = document.body.createTextRange();
  5658. range.moveToElementText(element);
  5659. range.select();
  5660. }else if(window["getSelection"]){
  5661. var selection = window.getSelection();
  5662. // FIXME: does this work on Safari?
  5663. if(selection["selectAllChildren"]){ // Mozilla
  5664. selection.selectAllChildren(element);
  5665. }
  5666. }
  5667. }
  5668. dojo.html.selectInputText = function(element){
  5669. element = dojo.byId(element);
  5670. if(document.selection && document.body.createTextRange){ // IE
  5671. var range = element.createTextRange();
  5672. range.moveStart("character", 0);
  5673. range.moveEnd("character", element.value.length);
  5674. range.select();
  5675. }else if(window["getSelection"]){
  5676. var selection = window.getSelection();
  5677. // FIXME: does this work on Safari?
  5678. element.setSelectionRange(0, element.value.length);
  5679. }
  5680. element.focus();
  5681. }
  5682. dojo.html.isSelectionCollapsed = function(){
  5683. if(document["selection"]){ // IE
  5684. return document.selection.createRange().text == "";
  5685. }else if(window["getSelection"]){
  5686. var selection = window.getSelection();
  5687. if(dojo.lang.isString(selection)){ // Safari
  5688. return selection == "";
  5689. }else{ // Mozilla/W3
  5690. return selection.isCollapsed;
  5691. }
  5692. }
  5693. }
  5694. dojo.html.getEventTarget = function(evt){
  5695. if(!evt) { evt = window.event || {} };
  5696. var t = (evt.srcElement ? evt.srcElement : (evt.target ? evt.target : null));
  5697. while((t)&&(t.nodeType!=1)){ t = t.parentNode; }
  5698. return t;
  5699. }
  5700. dojo.html.getDocumentWidth = function(){
  5701. dojo.deprecated("dojo.html.getDocument*", "replaced by dojo.html.getViewport*", "0.4");
  5702. return dojo.html.getViewportWidth();
  5703. }
  5704. dojo.html.getDocumentHeight = function(){
  5705. dojo.deprecated("dojo.html.getDocument*", "replaced by dojo.html.getViewport*", "0.4");
  5706. return dojo.html.getViewportHeight();
  5707. }
  5708. dojo.html.getDocumentSize = function(){
  5709. dojo.deprecated("dojo.html.getDocument*", "replaced of dojo.html.getViewport*", "0.4");
  5710. return dojo.html.getViewportSize();
  5711. }
  5712. dojo.html.getViewportWidth = function(){
  5713. var w = 0;
  5714. if(window.innerWidth){
  5715. w = window.innerWidth;
  5716. }
  5717. if(dojo.exists(document, "documentElement.clientWidth")){
  5718. // IE6 Strict
  5719. var w2 = document.documentElement.clientWidth;
  5720. // this lets us account for scrollbars
  5721. if(!w || w2 && w2 < w) {
  5722. w = w2;
  5723. }
  5724. return w;
  5725. }
  5726. if(document.body){
  5727. // IE
  5728. return document.body.clientWidth;
  5729. }
  5730. return 0;
  5731. }
  5732. dojo.html.getViewportHeight = function(){
  5733. if (window.innerHeight){
  5734. return window.innerHeight;
  5735. }
  5736. if (dojo.exists(document, "documentElement.clientHeight")){
  5737. // IE6 Strict
  5738. return document.documentElement.clientHeight;
  5739. }
  5740. if (document.body){
  5741. // IE
  5742. return document.body.clientHeight;
  5743. }
  5744. return 0;
  5745. }
  5746. dojo.html.getViewportSize = function(){
  5747. var ret = [dojo.html.getViewportWidth(), dojo.html.getViewportHeight()];
  5748. ret.w = ret[0];
  5749. ret.h = ret[1];
  5750. return ret;
  5751. }
  5752. dojo.html.getScrollTop = function(){
  5753. return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  5754. }
  5755. dojo.html.getScrollLeft = function(){
  5756. return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
  5757. }
  5758. dojo.html.getScrollOffset = function(){
  5759. var off = [dojo.html.getScrollLeft(), dojo.html.getScrollTop()];
  5760. off.x = off[0];
  5761. off.y = off[1];
  5762. return off;
  5763. }
  5764. dojo.html.getParentOfType = function(node, type){
  5765. dojo.deprecated("dojo.html.getParentOfType", "replaced by dojo.html.getParentByType*", "0.4");
  5766. return dojo.html.getParentByType(node, type);
  5767. }
  5768. dojo.html.getParentByType = function(node, type) {
  5769. var parent = dojo.byId(node);
  5770. type = type.toLowerCase();
  5771. while((parent)&&(parent.nodeName.toLowerCase()!=type)){
  5772. if(parent==(document["body"]||document["documentElement"])){
  5773. return null;
  5774. }
  5775. parent = parent.parentNode;
  5776. }
  5777. return parent;
  5778. }
  5779. // RAR: this function comes from nwidgets and is more-or-less unmodified.
  5780. // We should probably look ant Burst and f(m)'s equivalents
  5781. dojo.html.getAttribute = function(node, attr){
  5782. node = dojo.byId(node);
  5783. // FIXME: need to add support for attr-specific accessors
  5784. if((!node)||(!node.getAttribute)){
  5785. // if(attr !== 'nwType'){
  5786. // alert("getAttr of '" + attr + "' with bad node");
  5787. // }
  5788. return null;
  5789. }
  5790. var ta = typeof attr == 'string' ? attr : new String(attr);
  5791. // first try the approach most likely to succeed
  5792. var v = node.getAttribute(ta.toUpperCase());
  5793. if((v)&&(typeof v == 'string')&&(v!="")){ return v; }
  5794. // try returning the attributes value, if we couldn't get it as a string
  5795. if(v && v.value){ return v.value; }
  5796. // this should work on Opera 7, but it's a little on the crashy side
  5797. if((node.getAttributeNode)&&(node.getAttributeNode(ta))){
  5798. return (node.getAttributeNode(ta)).value;
  5799. }else if(node.getAttribute(ta)){
  5800. return node.getAttribute(ta);
  5801. }else if(node.getAttribute(ta.toLowerCase())){
  5802. return node.getAttribute(ta.toLowerCase());
  5803. }
  5804. return null;
  5805. }
  5806. /**
  5807. * Determines whether or not the specified node carries a value for the
  5808. * attribute in question.
  5809. */
  5810. dojo.html.hasAttribute = function(node, attr){
  5811. node = dojo.byId(node);
  5812. return dojo.html.getAttribute(node, attr) ? true : false;
  5813. }
  5814. /**
  5815. * Returns the string value of the list of CSS classes currently assigned
  5816. * directly to the node in question. Returns an empty string if no class attribute
  5817. * is found;
  5818. */
  5819. dojo.html.getClass = function(node){
  5820. node = dojo.byId(node);
  5821. if(!node){ return ""; }
  5822. var cs = "";
  5823. if(node.className){
  5824. cs = node.className;
  5825. }else if(dojo.html.hasAttribute(node, "class")){
  5826. cs = dojo.html.getAttribute(node, "class");
  5827. }
  5828. return dojo.string.trim(cs);
  5829. }
  5830. /**
  5831. * Returns an array of CSS classes currently assigned
  5832. * directly to the node in question. Returns an empty array if no classes
  5833. * are found;
  5834. */
  5835. dojo.html.getClasses = function(node) {
  5836. var c = dojo.html.getClass(node);
  5837. return (c == "") ? [] : c.split(/\s+/g);
  5838. }
  5839. /**
  5840. * Returns whether or not the specified classname is a portion of the
  5841. * class list currently applied to the node. Does not cover cascaded
  5842. * styles, only classes directly applied to the node.
  5843. */
  5844. dojo.html.hasClass = function(node, classname){
  5845. return dojo.lang.inArray(dojo.html.getClasses(node), classname);
  5846. }
  5847. /**
  5848. * Adds the specified class to the beginning of the class list on the
  5849. * passed node. This gives the specified class the highest precidence
  5850. * when style cascading is calculated for the node. Returns true or
  5851. * false; indicating success or failure of the operation, respectively.
  5852. */
  5853. dojo.html.prependClass = function(node, classStr){
  5854. classStr += " " + dojo.html.getClass(node);
  5855. return dojo.html.setClass(node, classStr);
  5856. }
  5857. /**
  5858. * Adds the specified class to the end of the class list on the
  5859. * passed &node;. Returns &true; or &false; indicating success or failure.
  5860. */
  5861. dojo.html.addClass = function(node, classStr){
  5862. if (dojo.html.hasClass(node, classStr)) {
  5863. return false;
  5864. }
  5865. classStr = dojo.string.trim(dojo.html.getClass(node) + " " + classStr);
  5866. return dojo.html.setClass(node, classStr);
  5867. }
  5868. /**
  5869. * Clobbers the existing list of classes for the node, replacing it with
  5870. * the list given in the 2nd argument. Returns true or false
  5871. * indicating success or failure.
  5872. */
  5873. dojo.html.setClass = function(node, classStr){
  5874. node = dojo.byId(node);
  5875. var cs = new String(classStr);
  5876. try{
  5877. if(typeof node.className == "string"){
  5878. node.className = cs;
  5879. }else if(node.setAttribute){
  5880. node.setAttribute("class", classStr);
  5881. node.className = cs;
  5882. }else{
  5883. return false;
  5884. }
  5885. }catch(e){
  5886. dojo.debug("dojo.html.setClass() failed", e);
  5887. }
  5888. return true;
  5889. }
  5890. /**
  5891. * Removes the className from the node;. Returns
  5892. * true or false indicating success or failure.
  5893. */
  5894. dojo.html.removeClass = function(node, classStr, allowPartialMatches){
  5895. var classStr = dojo.string.trim(new String(classStr));
  5896. try{
  5897. var cs = dojo.html.getClasses(node);
  5898. var nca = [];
  5899. if(allowPartialMatches){
  5900. for(var i = 0; i<cs.length; i++){
  5901. if(cs[i].indexOf(classStr) == -1){
  5902. nca.push(cs[i]);
  5903. }
  5904. }
  5905. }else{
  5906. for(var i=0; i<cs.length; i++){
  5907. if(cs[i] != classStr){
  5908. nca.push(cs[i]);
  5909. }
  5910. }
  5911. }
  5912. dojo.html.setClass(node, nca.join(" "));
  5913. }catch(e){
  5914. dojo.debug("dojo.html.removeClass() failed", e);
  5915. }
  5916. return true;
  5917. }
  5918. /**
  5919. * Replaces 'oldClass' and adds 'newClass' to node
  5920. */
  5921. dojo.html.replaceClass = function(node, newClass, oldClass) {
  5922. dojo.html.removeClass(node, oldClass);
  5923. dojo.html.addClass(node, newClass);
  5924. }
  5925. // Enum type for getElementsByClass classMatchType arg:
  5926. dojo.html.classMatchType = {
  5927. ContainsAll : 0, // all of the classes are part of the node's class (default)
  5928. ContainsAny : 1, // any of the classes are part of the node's class
  5929. IsOnly : 2 // only all of the classes are part of the node's class
  5930. }
  5931. /**
  5932. * Returns an array of nodes for the given classStr, children of a
  5933. * parent, and optionally of a certain nodeType
  5934. */
  5935. dojo.html.getElementsByClass = function(classStr, parent, nodeType, classMatchType, useNonXpath){
  5936. parent = dojo.byId(parent) || document;
  5937. var classes = classStr.split(/\s+/g);
  5938. var nodes = [];
  5939. if( classMatchType != 1 && classMatchType != 2 ) classMatchType = 0; // make it enum
  5940. var reClass = new RegExp("(\\s|^)((" + classes.join(")|(") + "))(\\s|$)");
  5941. var candidateNodes = [];
  5942. if(!useNonXpath && document.evaluate) { // supports dom 3 xpath
  5943. var xpath = "//" + (nodeType || "*") + "[contains(";
  5944. if(classMatchType != dojo.html.classMatchType.ContainsAny){
  5945. xpath += "concat(' ',@class,' '), ' " +
  5946. classes.join(" ') and contains(concat(' ',@class,' '), ' ") +
  5947. " ')]";
  5948. }else{
  5949. xpath += "concat(' ',@class,' '), ' " +
  5950. classes.join(" ')) or contains(concat(' ',@class,' '), ' ") +
  5951. " ')]";
  5952. }
  5953. var xpathResult = document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
  5954. var result = xpathResult.iterateNext();
  5955. while(result){
  5956. try{
  5957. candidateNodes.push(result);
  5958. result = xpathResult.iterateNext();
  5959. }catch(e){ break; }
  5960. }
  5961. return candidateNodes;
  5962. }else{
  5963. if(!nodeType){
  5964. nodeType = "*";
  5965. }
  5966. candidateNodes = parent.getElementsByTagName(nodeType);
  5967. var node, i = 0;
  5968. outer:
  5969. while(node = candidateNodes[i++]){
  5970. var nodeClasses = dojo.html.getClasses(node);
  5971. if(nodeClasses.length == 0){ continue outer; }
  5972. var matches = 0;
  5973. for(var j = 0; j < nodeClasses.length; j++){
  5974. if(reClass.test(nodeClasses[j])){
  5975. if(classMatchType == dojo.html.classMatchType.ContainsAny){
  5976. nodes.push(node);
  5977. continue outer;
  5978. }else{
  5979. matches++;
  5980. }
  5981. }else{
  5982. if(classMatchType == dojo.html.classMatchType.IsOnly){
  5983. continue outer;
  5984. }
  5985. }
  5986. }
  5987. if(matches == classes.length){
  5988. if( (classMatchType == dojo.html.classMatchType.IsOnly)&&
  5989. (matches == nodeClasses.length)){
  5990. nodes.push(node);
  5991. }else if(classMatchType == dojo.html.classMatchType.ContainsAll){
  5992. nodes.push(node);
  5993. }
  5994. }
  5995. }
  5996. return nodes;
  5997. }
  5998. }
  5999. dojo.html.getElementsByClassName = dojo.html.getElementsByClass;
  6000. /**
  6001. * Returns the mouse position relative to the document (not the viewport).
  6002. * For example, if you have a document that is 10000px tall,
  6003. * but your browser window is only 100px tall,
  6004. * if you scroll to the bottom of the document and call this function it
  6005. * will return {x: 0, y: 10000}
  6006. */
  6007. dojo.html.getCursorPosition = function(e){
  6008. e = e || window.event;
  6009. var cursor = {x:0, y:0};
  6010. if(e.pageX || e.pageY){
  6011. cursor.x = e.pageX;
  6012. cursor.y = e.pageY;
  6013. }else{
  6014. var de = document.documentElement;
  6015. var db = document.body;
  6016. cursor.x = e.clientX + ((de||db)["scrollLeft"]) - ((de||db)["clientLeft"]);
  6017. cursor.y = e.clientY + ((de||db)["scrollTop"]) - ((de||db)["clientTop"]);
  6018. }
  6019. return cursor;
  6020. }
  6021. dojo.html.overElement = function(element, e){
  6022. element = dojo.byId(element);
  6023. var mouse = dojo.html.getCursorPosition(e);
  6024. with(dojo.html){
  6025. var top = getAbsoluteY(element, true);
  6026. var bottom = top + getInnerHeight(element);
  6027. var left = getAbsoluteX(element, true);
  6028. var right = left + getInnerWidth(element);
  6029. }
  6030. return (mouse.x >= left && mouse.x <= right &&
  6031. mouse.y >= top && mouse.y <= bottom);
  6032. }
  6033. dojo.html.setActiveStyleSheet = function(title){
  6034. var i = 0, a, els = document.getElementsByTagName("link");
  6035. while (a = els[i++]) {
  6036. if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")){
  6037. a.disabled = true;
  6038. if (a.getAttribute("title") == title) { a.disabled = false; }
  6039. }
  6040. }
  6041. }
  6042. dojo.html.getActiveStyleSheet = function(){
  6043. var i = 0, a, els = document.getElementsByTagName("link");
  6044. while (a = els[i++]) {
  6045. if (a.getAttribute("rel").indexOf("style") != -1 &&
  6046. a.getAttribute("title") && !a.disabled) { return a.getAttribute("title"); }
  6047. }
  6048. return null;
  6049. }
  6050. dojo.html.getPreferredStyleSheet = function(){
  6051. var i = 0, a, els = document.getElementsByTagName("link");
  6052. while (a = els[i++]) {
  6053. if(a.getAttribute("rel").indexOf("style") != -1
  6054. && a.getAttribute("rel").indexOf("alt") == -1
  6055. && a.getAttribute("title")) { return a.getAttribute("title"); }
  6056. }
  6057. return null;
  6058. }
  6059. dojo.html.body = function(){
  6060. // Note: document.body is not defined for a strict xhtml document
  6061. return document.body || document.getElementsByTagName("body")[0];
  6062. }
  6063. /**
  6064. * Like dojo.dom.isTag, except case-insensitive
  6065. **/
  6066. dojo.html.isTag = function(node /* ... */) {
  6067. node = dojo.byId(node);
  6068. if(node && node.tagName) {
  6069. var arr = dojo.lang.map(dojo.lang.toArray(arguments, 1),
  6070. function(a) { return String(a).toLowerCase(); });
  6071. return arr[ dojo.lang.find(node.tagName.toLowerCase(), arr) ] || "";
  6072. }
  6073. return "";
  6074. }
  6075. dojo.html.copyStyle = function(target, source){
  6076. // work around for opera which doesn't have cssText, and for IE which fails on setAttribute
  6077. if(dojo.lang.isUndefined(source.style.cssText)){
  6078. target.setAttribute("style", source.getAttribute("style"));
  6079. }else{
  6080. target.style.cssText = source.style.cssText;
  6081. }
  6082. dojo.html.addClass(target, dojo.html.getClass(source));
  6083. }
  6084. dojo.html._callExtrasDeprecated = function(inFunc, args) {
  6085. var module = "dojo.html.extras";
  6086. dojo.deprecated("dojo.html." + inFunc, "moved to " + module, "0.4");
  6087. dojo["require"](module); // weird syntax to fool list-profile-deps (build)
  6088. return dojo.html[inFunc].apply(dojo.html, args);
  6089. }
  6090. dojo.html.createNodesFromText = function() {
  6091. return dojo.html._callExtrasDeprecated('createNodesFromText', arguments);
  6092. }
  6093. dojo.html.gravity = function() {
  6094. return dojo.html._callExtrasDeprecated('gravity', arguments);
  6095. }
  6096. dojo.html.placeOnScreen = function() {
  6097. return dojo.html._callExtrasDeprecated('placeOnScreen', arguments);
  6098. }
  6099. dojo.html.placeOnScreenPoint = function() {
  6100. return dojo.html._callExtrasDeprecated('placeOnScreenPoint', arguments);
  6101. }
  6102. dojo.html.renderedTextContent = function() {
  6103. return dojo.html._callExtrasDeprecated('renderedTextContent', arguments);
  6104. }
  6105. dojo.html.BackgroundIframe = function() {
  6106. return dojo.html._callExtrasDeprecated('BackgroundIframe', arguments);
  6107. }
  6108. dojo.provide("dojo.lfx.html");
  6109. dojo.require("dojo.lfx.Animation");
  6110. dojo.require("dojo.html");
  6111. dojo.lfx.html._byId = function(nodes){
  6112. if(!nodes){ return []; }
  6113. if(dojo.lang.isArray(nodes)){
  6114. if(!nodes.alreadyChecked){
  6115. var n = [];
  6116. dojo.lang.forEach(nodes, function(node){
  6117. n.push(dojo.byId(node));
  6118. });
  6119. n.alreadyChecked = true;
  6120. return n;
  6121. }else{
  6122. return nodes;
  6123. }
  6124. }else{
  6125. var n = [];
  6126. n.push(dojo.byId(nodes));
  6127. n.alreadyChecked = true;
  6128. return n;
  6129. }
  6130. }
  6131. dojo.lfx.html.propertyAnimation = function( /*DOMNode*/ nodes,
  6132. /*Array*/ propertyMap,
  6133. /*int*/ duration,
  6134. /*function*/ easing){
  6135. nodes = dojo.lfx.html._byId(nodes);
  6136. if(nodes.length==1){
  6137. // FIXME: we're only supporting start-value filling when one node is
  6138. // passed
  6139. dojo.lang.forEach(propertyMap, function(prop){
  6140. if(typeof prop["start"] == "undefined"){
  6141. if(prop.property != "opacity"){
  6142. prop.start = parseInt(dojo.style.getComputedStyle(nodes[0], prop.property));
  6143. }else{
  6144. prop.start = dojo.style.getOpacity(nodes[0]);
  6145. }
  6146. }
  6147. });
  6148. }
  6149. var coordsAsInts = function(coords){
  6150. var cints = new Array(coords.length);
  6151. for(var i = 0; i < coords.length; i++){
  6152. cints[i] = Math.round(coords[i]);
  6153. }
  6154. return cints;
  6155. }
  6156. var setStyle = function(n, style){
  6157. n = dojo.byId(n);
  6158. if(!n || !n.style){ return; }
  6159. for(var s in style){
  6160. if(s == "opacity"){
  6161. dojo.style.setOpacity(n, style[s]);
  6162. }else{
  6163. n.style[s] = style[s];
  6164. }
  6165. }
  6166. }
  6167. var propLine = function(properties){
  6168. this._properties = properties;
  6169. this.diffs = new Array(properties.length);
  6170. dojo.lang.forEach(properties, function(prop, i){
  6171. // calculate the end - start to optimize a bit
  6172. if(dojo.lang.isArray(prop.start)){
  6173. // don't loop through the arrays
  6174. this.diffs[i] = null;
  6175. }else if(prop.start instanceof dojo.graphics.color.Color){
  6176. // save these so we don't have to call toRgb() every getValue() call
  6177. prop.startRgb = prop.start.toRgb();
  6178. prop.endRgb = prop.end.toRgb();
  6179. }else{
  6180. this.diffs[i] = prop.end - prop.start;
  6181. }
  6182. }, this);
  6183. this.getValue = function(n){
  6184. var ret = {};
  6185. dojo.lang.forEach(this._properties, function(prop, i){
  6186. var value = null;
  6187. if(dojo.lang.isArray(prop.start)){
  6188. // FIXME: what to do here?
  6189. }else if(prop.start instanceof dojo.graphics.color.Color){
  6190. value = (prop.units||"rgb") + "(";
  6191. for(var j = 0 ; j < prop.startRgb.length ; j++){
  6192. value += Math.round(((prop.endRgb[j] - prop.startRgb[j]) * n) + prop.startRgb[j]) + (j < prop.startRgb.length - 1 ? "," : "");
  6193. }
  6194. value += ")";
  6195. }else{
  6196. value = ((this.diffs[i]) * n) + prop.start + (prop.property != "opacity" ? prop.units||"px" : "");
  6197. }
  6198. ret[dojo.style.toCamelCase(prop.property)] = value;
  6199. }, this);
  6200. return ret;
  6201. }
  6202. }
  6203. var anim = new dojo.lfx.Animation({
  6204. onAnimate: function(propValues){
  6205. dojo.lang.forEach(nodes, function(node){
  6206. setStyle(node, propValues);
  6207. });
  6208. } }, duration, new propLine(propertyMap), easing);
  6209. return anim;
  6210. }
  6211. dojo.lfx.html._makeFadeable = function(nodes){
  6212. var makeFade = function(node){
  6213. if(dojo.render.html.ie){
  6214. // only set the zoom if the "tickle" value would be the same as the
  6215. // default
  6216. if( (node.style.zoom.length == 0) &&
  6217. (dojo.style.getStyle(node, "zoom") == "normal") ){
  6218. // make sure the node "hasLayout"
  6219. // NOTE: this has been tested with larger and smaller user-set text
  6220. // sizes and works fine
  6221. node.style.zoom = "1";
  6222. // node.style.zoom = "normal";
  6223. }
  6224. // don't set the width to auto if it didn't already cascade that way.
  6225. // We don't want to f anyones designs
  6226. if( (node.style.width.length == 0) &&
  6227. (dojo.style.getStyle(node, "width") == "auto") ){
  6228. node.style.width = "auto";
  6229. }
  6230. }
  6231. }
  6232. if(dojo.lang.isArrayLike(nodes)){
  6233. dojo.lang.forEach(nodes, makeFade);
  6234. }else{
  6235. makeFade(nodes);
  6236. }
  6237. }
  6238. dojo.lfx.html.fadeIn = function(nodes, duration, easing, callback){
  6239. nodes = dojo.lfx.html._byId(nodes);
  6240. dojo.lfx.html._makeFadeable(nodes);
  6241. var anim = dojo.lfx.propertyAnimation(nodes, [
  6242. { property: "opacity",
  6243. start: dojo.style.getOpacity(nodes[0]),
  6244. end: 1 } ], duration, easing);
  6245. if(callback){
  6246. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6247. anim.onEnd = function(){ oldOnEnd(); callback(nodes, anim); };
  6248. }
  6249. return anim;
  6250. }
  6251. dojo.lfx.html.fadeOut = function(nodes, duration, easing, callback){
  6252. nodes = dojo.lfx.html._byId(nodes);
  6253. dojo.lfx.html._makeFadeable(nodes);
  6254. var anim = dojo.lfx.propertyAnimation(nodes, [
  6255. { property: "opacity",
  6256. start: dojo.style.getOpacity(nodes[0]),
  6257. end: 0 } ], duration, easing);
  6258. if(callback){
  6259. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6260. anim.onEnd = function(){ oldOnEnd(); callback(nodes, anim); };
  6261. }
  6262. return anim;
  6263. }
  6264. dojo.lfx.html.fadeShow = function(nodes, duration, easing, callback){
  6265. var anim = dojo.lfx.html.fadeIn(nodes, duration, easing, callback);
  6266. var oldBb = (anim["beforeBegin"]) ? dojo.lang.hitch(anim, "beforeBegin") : function(){};
  6267. anim.beforeBegin = function(){
  6268. oldBb();
  6269. if(dojo.lang.isArrayLike(nodes)){
  6270. dojo.lang.forEach(nodes, dojo.style.show);
  6271. }else{
  6272. dojo.style.show(nodes);
  6273. }
  6274. };
  6275. return anim;
  6276. }
  6277. dojo.lfx.html.fadeHide = function(nodes, duration, easing, callback){
  6278. var anim = dojo.lfx.html.fadeOut(nodes, duration, easing, function(){
  6279. if(dojo.lang.isArrayLike(nodes)){
  6280. dojo.lang.forEach(nodes, dojo.style.hide);
  6281. }else{
  6282. dojo.style.hide(nodes);
  6283. }
  6284. if(callback){ callback(nodes, anim); }
  6285. });
  6286. return anim;
  6287. }
  6288. dojo.lfx.html.wipeIn = function(nodes, duration, easing, callback){
  6289. nodes = dojo.lfx.html._byId(nodes);
  6290. var anims = [];
  6291. dojo.lang.forEach(nodes, function(node){
  6292. var overflow = dojo.style.getStyle(node, "overflow");
  6293. if(overflow == "visible") {
  6294. node.style.overflow = "hidden";
  6295. }
  6296. node.style.height = "0px";
  6297. dojo.style.show(node);
  6298. var anim = dojo.lfx.propertyAnimation(node,
  6299. [{ property: "height",
  6300. start: 0,
  6301. end: node.scrollHeight }], duration, easing);
  6302. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6303. anim.onEnd = function(){
  6304. oldOnEnd();
  6305. node.style.overflow = overflow;
  6306. node.style.height = "auto";
  6307. if(callback){ callback(node, anim); }
  6308. };
  6309. anims.push(anim);
  6310. });
  6311. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6312. else{ return anims[0]; }
  6313. }
  6314. dojo.lfx.html.wipeOut = function(nodes, duration, easing, callback){
  6315. nodes = dojo.lfx.html._byId(nodes);
  6316. var anims = [];
  6317. dojo.lang.forEach(nodes, function(node){
  6318. var overflow = dojo.style.getStyle(node, "overflow");
  6319. if(overflow == "visible") {
  6320. node.style.overflow = "hidden";
  6321. }
  6322. dojo.style.show(node);
  6323. var anim = dojo.lfx.propertyAnimation(node,
  6324. [{ property: "height",
  6325. start: dojo.style.getContentBoxHeight(node),
  6326. end: 0 } ], duration, easing);
  6327. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6328. anim.onEnd = function(){
  6329. oldOnEnd();
  6330. dojo.style.hide(node);
  6331. node.style.overflow = overflow;
  6332. if(callback){ callback(node, anim); }
  6333. };
  6334. anims.push(anim);
  6335. });
  6336. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6337. else { return anims[0]; }
  6338. }
  6339. dojo.lfx.html.slideTo = function(nodes, coords, duration, easing, callback){
  6340. nodes = dojo.lfx.html._byId(nodes);
  6341. var anims = [];
  6342. dojo.lang.forEach(nodes, function(node){
  6343. var top = null;
  6344. var left = null;
  6345. var init = (function(){
  6346. var innerNode = node;
  6347. return function(){
  6348. top = innerNode.offsetTop;
  6349. left = innerNode.offsetLeft;
  6350. if (!dojo.style.isPositionAbsolute(innerNode)) {
  6351. var ret = dojo.style.abs(innerNode, true);
  6352. dojo.style.setStyleAttributes(innerNode, "position:absolute;top:"+ret.y+"px;left:"+ret.x+"px;");
  6353. top = ret.y;
  6354. left = ret.x;
  6355. }
  6356. }
  6357. })();
  6358. init();
  6359. var anim = dojo.lfx.propertyAnimation(node,
  6360. [{ property: "top",
  6361. start: top,
  6362. end: coords[0] },
  6363. { property: "left",
  6364. start: left,
  6365. end: coords[1] }], duration, easing);
  6366. var oldBb = (anim["beforeBegin"]) ? dojo.lang.hitch(anim, "beforeBegin") : function(){};
  6367. anim.beforeBegin = function(){ oldBb(); init(); };
  6368. if(callback){
  6369. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6370. anim.onEnd = function(){ oldOnEnd(); callback(nodes, anim); };
  6371. }
  6372. anims.push(anim);
  6373. });
  6374. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6375. else{ return anims[0]; }
  6376. }
  6377. dojo.lfx.html.slideBy = function(nodes, coords, duration, easing, callback){
  6378. nodes = dojo.lfx.html._byId(nodes);
  6379. var anims = [];
  6380. dojo.lang.forEach(nodes, function(node){
  6381. var top = null;
  6382. var left = null;
  6383. var init = (function(){
  6384. var innerNode = node;
  6385. return function(){
  6386. top = node.offsetTop;
  6387. left = node.offsetLeft;
  6388. if (!dojo.style.isPositionAbsolute(innerNode)) {
  6389. var ret = dojo.style.abs(innerNode);
  6390. dojo.style.setStyleAttributes(innerNode, "position:absolute;top:"+ret.y+"px;left:"+ret.x+"px;");
  6391. top = ret.y;
  6392. left = ret.x;
  6393. }
  6394. }
  6395. })();
  6396. init();
  6397. var anim = dojo.lfx.propertyAnimation(node,
  6398. [{ property: "top",
  6399. start: top,
  6400. end: top+coords[0] },
  6401. { property: "left",
  6402. start: left,
  6403. end: left+coords[1] }], duration, easing);
  6404. var oldBb = (anim["beforeBegin"]) ? dojo.lang.hitch(anim, "beforeBegin") : function(){};
  6405. anim.beforeBegin = function(){ oldBb(); init(); };
  6406. if(callback){
  6407. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6408. anim.onEnd = function(){ oldOnEnd(); callback(nodes, anim); };
  6409. }
  6410. anims.push(anim);
  6411. });
  6412. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6413. else{ return anims[0]; }
  6414. }
  6415. dojo.lfx.html.explode = function(start, endNode, duration, easing, callback){
  6416. start = dojo.byId(start);
  6417. endNode = dojo.byId(endNode);
  6418. var startCoords = dojo.style.toCoordinateArray(start, true);
  6419. var outline = document.createElement("div");
  6420. dojo.html.copyStyle(outline, endNode);
  6421. with(outline.style){
  6422. position = "absolute";
  6423. display = "none";
  6424. }
  6425. document.body.appendChild(outline);
  6426. with(endNode.style){
  6427. visibility = "hidden";
  6428. display = "block";
  6429. }
  6430. var endCoords = dojo.style.toCoordinateArray(endNode, true);
  6431. with(endNode.style){
  6432. display = "none";
  6433. visibility = "visible";
  6434. }
  6435. var anim = new dojo.lfx.propertyAnimation(outline, [
  6436. { property: "height", start: startCoords[3], end: endCoords[3] },
  6437. { property: "width", start: startCoords[2], end: endCoords[2] },
  6438. { property: "top", start: startCoords[1], end: endCoords[1] },
  6439. { property: "left", start: startCoords[0], end: endCoords[0] },
  6440. { property: "opacity", start: 0.3, end: 1.0 }
  6441. ], duration, easing);
  6442. anim.beforeBegin = function(){
  6443. dojo.style.setDisplay(outline, "block");
  6444. };
  6445. anim.onEnd = function(){
  6446. dojo.style.setDisplay(endNode, "block");
  6447. outline.parentNode.removeChild(outline);
  6448. };
  6449. if(callback){
  6450. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6451. anim.onEnd = function(){ oldOnEnd(); callback(endNode, anim); };
  6452. }
  6453. return anim;
  6454. }
  6455. dojo.lfx.html.implode = function(startNode, end, duration, easing, callback){
  6456. startNode = dojo.byId(startNode);
  6457. end = dojo.byId(end);
  6458. var startCoords = dojo.style.toCoordinateArray(startNode, true);
  6459. var endCoords = dojo.style.toCoordinateArray(end, true);
  6460. var outline = document.createElement("div");
  6461. dojo.html.copyStyle(outline, startNode);
  6462. dojo.style.setOpacity(outline, 0.3);
  6463. with(outline.style){
  6464. position = "absolute";
  6465. display = "none";
  6466. }
  6467. document.body.appendChild(outline);
  6468. var anim = new dojo.lfx.propertyAnimation(outline, [
  6469. { property: "height", start: startCoords[3], end: endCoords[3] },
  6470. { property: "width", start: startCoords[2], end: endCoords[2] },
  6471. { property: "top", start: startCoords[1], end: endCoords[1] },
  6472. { property: "left", start: startCoords[0], end: endCoords[0] },
  6473. { property: "opacity", start: 1.0, end: 0.3 }
  6474. ], duration, easing);
  6475. anim.beforeBegin = function(){
  6476. dojo.style.hide(startNode);
  6477. dojo.style.show(outline);
  6478. };
  6479. anim.onEnd = function(){
  6480. outline.parentNode.removeChild(outline);
  6481. };
  6482. if(callback){
  6483. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6484. anim.onEnd = function(){ oldOnEnd(); callback(startNode, anim); };
  6485. }
  6486. return anim;
  6487. }
  6488. dojo.lfx.html.highlight = function(nodes, startColor, duration, easing, callback){
  6489. nodes = dojo.lfx.html._byId(nodes);
  6490. var anims = [];
  6491. dojo.lang.forEach(nodes, function(node){
  6492. var color = dojo.style.getBackgroundColor(node);
  6493. var bg = dojo.style.getStyle(node, "background-color").toLowerCase();
  6494. var bgImage = dojo.style.getStyle(node, "background-image");
  6495. var wasTransparent = (bg == "transparent" || bg == "rgba(0, 0, 0, 0)");
  6496. while(color.length > 3) { color.pop(); }
  6497. var rgb = new dojo.graphics.color.Color(startColor);
  6498. var endRgb = new dojo.graphics.color.Color(color);
  6499. var anim = dojo.lfx.propertyAnimation(node, [{
  6500. property: "background-color",
  6501. start: rgb,
  6502. end: endRgb
  6503. }], duration, easing);
  6504. var oldbb = (anim["beforeBegin"]) ? dojo.lang.hitch(anim, "beforeBegin") : function(){};
  6505. anim.beforeBegin = function(){
  6506. oldbb();
  6507. if(bgImage){
  6508. node.style.backgroundImage = "none";
  6509. }
  6510. node.style.backgroundColor = "rgb(" + rgb.toRgb().join(",") + ")";
  6511. };
  6512. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6513. anim.onEnd = function(){
  6514. oldOnEnd();
  6515. if(bgImage){
  6516. node.style.backgroundImage = bgImage;
  6517. }
  6518. if(wasTransparent){
  6519. node.style.backgroundColor = "transparent";
  6520. }
  6521. if(callback){
  6522. callback(node, anim);
  6523. }
  6524. };
  6525. anims.push(anim);
  6526. });
  6527. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6528. else{ return anims[0]; }
  6529. }
  6530. dojo.lfx.html.unhighlight = function(nodes, endColor, duration, easing, callback){
  6531. nodes = dojo.lfx.html._byId(nodes);
  6532. var anims = [];
  6533. dojo.lang.forEach(nodes, function(node){
  6534. var color = new dojo.graphics.color.Color(dojo.style.getBackgroundColor(node));
  6535. var rgb = new dojo.graphics.color.Color(endColor);
  6536. var bgImage = dojo.style.getStyle(node, "background-image");
  6537. var anim = dojo.lfx.propertyAnimation(node, [{
  6538. property: "background-color",
  6539. start: color,
  6540. end: rgb
  6541. }], duration, easing);
  6542. var oldbb = (anim["beforeBegin"]) ? dojo.lang.hitch(anim, "beforeBegin") : function(){};
  6543. anim.beforeBegin = function(){
  6544. oldbb();
  6545. if(bgImage){
  6546. node.style.backgroundImage = "none";
  6547. }
  6548. node.style.backgroundColor = "rgb(" + color.toRgb().join(",") + ")";
  6549. };
  6550. var oldOnEnd = (anim["onEnd"]) ? dojo.lang.hitch(anim, "onEnd") : function(){};
  6551. anim.onEnd = function(){
  6552. oldOnEnd();
  6553. if(callback){
  6554. callback(node, anim);
  6555. }
  6556. };
  6557. anims.push(anim);
  6558. });
  6559. if(nodes.length > 1){ return dojo.lfx.combine(anims); }
  6560. else{ return anims[0]; }
  6561. }
  6562. dojo.lang.mixin(dojo.lfx, dojo.lfx.html);
  6563. dojo.kwCompoundRequire({
  6564. browser: ["dojo.lfx.html"],
  6565. dashboard: ["dojo.lfx.html"]
  6566. });
  6567. dojo.provide("dojo.lfx.*");