PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/SyracavaMVC/WebContent/scripts/extjs/air/samples/tasks/ext-2.0/adapter/ext/ext-base.js

http://syracava.googlecode.com/
JavaScript | 2218 lines | 1700 code | 504 blank | 14 comment | 465 complexity | 6bf10d24d0e67394eca3c2c45f605d2f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1

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

  1. /*
  2. * Ext JS Library 0.20
  3. * Copyright(c) 2006-2008, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://extjs.com/license
  7. */
  8. /*
  9. * Ext JS Library 2.0.1
  10. * Copyright(c) 2006-2008, Ext JS, LLC.
  11. * licensing@extjs.com
  12. *
  13. * http://extjs.com/license
  14. */
  15. Ext = {version: '2.0.1'};
  16. window["undefined"] = window["undefined"];
  17. Ext.apply = function(o, c, defaults){
  18. if(defaults){
  19. Ext.apply(o, defaults);
  20. }
  21. if(o && c && typeof c == 'object'){
  22. for(var p in c){
  23. o[p] = c[p];
  24. }
  25. }
  26. return o;
  27. };
  28. (function(){
  29. var idSeed = 0;
  30. var ua = navigator.userAgent.toLowerCase();
  31. var isStrict = document.compatMode == "CSS1Compat",
  32. isOpera = ua.indexOf("opera") > -1,
  33. isSafari = (/webkit|khtml/).test(ua),
  34. isSafari3 = isSafari && ua.indexOf('webkit/5') != -1,
  35. isIE = !isOpera && ua.indexOf("msie") > -1,
  36. isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
  37. isGecko = !isSafari && ua.indexOf("gecko") > -1,
  38. isBorderBox = isIE && !isStrict,
  39. isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
  40. isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
  41. isAir = (ua.indexOf("adobeair") != -1),
  42. isLinux = (ua.indexOf("linux") != -1),
  43. isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
  44. if(isIE && !isIE7){
  45. try{
  46. document.execCommand("BackgroundImageCache", false, true);
  47. }catch(e){}
  48. }
  49. Ext.apply(Ext, {
  50. isStrict : isStrict,
  51. isSecure : isSecure,
  52. isReady : false,
  53. enableGarbageCollector : true,
  54. enableListenerCollection:false,
  55. SSL_SECURE_URL : "javascript:false",
  56. BLANK_IMAGE_URL : "http:/"+"/extjs.com/s.gif",
  57. emptyFn : function(){},
  58. applyIf : function(o, c){
  59. if(o && c){
  60. for(var p in c){
  61. if(typeof o[p] == "undefined"){ o[p] = c[p]; }
  62. }
  63. }
  64. return o;
  65. },
  66. addBehaviors : function(o){
  67. if(!Ext.isReady){
  68. Ext.onReady(function(){
  69. Ext.addBehaviors(o);
  70. });
  71. return;
  72. }
  73. var cache = {};
  74. for(var b in o){
  75. var parts = b.split('@');
  76. if(parts[1]){
  77. var s = parts[0];
  78. if(!cache[s]){
  79. cache[s] = Ext.select(s);
  80. }
  81. cache[s].on(parts[1], o[b]);
  82. }
  83. }
  84. cache = null;
  85. },
  86. id : function(el, prefix){
  87. prefix = prefix || "ext-gen";
  88. el = Ext.getDom(el);
  89. var id = prefix + (++idSeed);
  90. return el ? (el.id ? el.id : (el.id = id)) : id;
  91. },
  92. extend : function(){
  93. var io = function(o){
  94. for(var m in o){
  95. this[m] = o[m];
  96. }
  97. };
  98. var oc = Object.prototype.constructor;
  99. return function(sb, sp, overrides){
  100. if(typeof sp == 'object'){
  101. overrides = sp;
  102. sp = sb;
  103. sb = overrides.constructor != oc ? overrides.constructor : function(){sp.apply(this, arguments);};
  104. }
  105. var F = function(){}, sbp, spp = sp.prototype;
  106. F.prototype = spp;
  107. sbp = sb.prototype = new F();
  108. sbp.constructor=sb;
  109. sb.superclass=spp;
  110. if(spp.constructor == oc){
  111. spp.constructor=sp;
  112. }
  113. sb.override = function(o){
  114. Ext.override(sb, o);
  115. };
  116. sbp.override = io;
  117. Ext.override(sb, overrides);
  118. return sb;
  119. };
  120. }(),
  121. override : function(origclass, overrides){
  122. if(overrides){
  123. var p = origclass.prototype;
  124. for(var method in overrides){
  125. p[method] = overrides[method];
  126. }
  127. }
  128. },
  129. namespace : function(){
  130. var a=arguments, o=null, i, j, d, rt;
  131. for (i=0; i<a.length; ++i) {
  132. d=a[i].split(".");
  133. rt = d[0];
  134. eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
  135. for (j=1; j<d.length; ++j) {
  136. o[d[j]]=o[d[j]] || {};
  137. o=o[d[j]];
  138. }
  139. }
  140. },
  141. urlEncode : function(o){
  142. if(!o){
  143. return "";
  144. }
  145. var buf = [];
  146. for(var key in o){
  147. var ov = o[key], k = encodeURIComponent(key);
  148. var type = typeof ov;
  149. if(type == 'undefined'){
  150. buf.push(k, "=&");
  151. }else if(type != "function" && type != "object"){
  152. buf.push(k, "=", encodeURIComponent(ov), "&");
  153. }else if(Ext.isArray(ov)){
  154. if (ov.length) {
  155. for(var i = 0, len = ov.length; i < len; i++) {
  156. buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
  157. }
  158. } else {
  159. buf.push(k, "=&");
  160. }
  161. }
  162. }
  163. buf.pop();
  164. return buf.join("");
  165. },
  166. urlDecode : function(string, overwrite){
  167. if(!string || !string.length){
  168. return {};
  169. }
  170. var obj = {};
  171. var pairs = string.split('&');
  172. var pair, name, value;
  173. for(var i = 0, len = pairs.length; i < len; i++){
  174. pair = pairs[i].split('=');
  175. name = decodeURIComponent(pair[0]);
  176. value = decodeURIComponent(pair[1]);
  177. if(overwrite !== true){
  178. if(typeof obj[name] == "undefined"){
  179. obj[name] = value;
  180. }else if(typeof obj[name] == "string"){
  181. obj[name] = [obj[name]];
  182. obj[name].push(value);
  183. }else{
  184. obj[name].push(value);
  185. }
  186. }else{
  187. obj[name] = value;
  188. }
  189. }
  190. return obj;
  191. },
  192. each : function(array, fn, scope){
  193. if(typeof array.length == "undefined" || typeof array == "string"){
  194. array = [array];
  195. }
  196. for(var i = 0, len = array.length; i < len; i++){
  197. if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
  198. }
  199. },
  200. combine : function(){
  201. var as = arguments, l = as.length, r = [];
  202. for(var i = 0; i < l; i++){
  203. var a = as[i];
  204. if(Ext.isArray(a)){
  205. r = r.concat(a);
  206. }else if(a.length !== undefined && !a.substr){
  207. r = r.concat(Array.prototype.slice.call(a, 0));
  208. }else{
  209. r.push(a);
  210. }
  211. }
  212. return r;
  213. },
  214. escapeRe : function(s) {
  215. return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
  216. },
  217. callback : function(cb, scope, args, delay){
  218. if(typeof cb == "function"){
  219. if(delay){
  220. cb.defer(delay, scope, args || []);
  221. }else{
  222. cb.apply(scope, args || []);
  223. }
  224. }
  225. },
  226. getDom : function(el){
  227. if(!el || !document){
  228. return null;
  229. }
  230. return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
  231. },
  232. getDoc : function(){
  233. return Ext.get(document);
  234. },
  235. getBody : function(){
  236. return Ext.get(document.body || document.documentElement);
  237. },
  238. getCmp : function(id){
  239. return Ext.ComponentMgr.get(id);
  240. },
  241. num : function(v, defaultValue){
  242. if(typeof v != 'number'){
  243. return defaultValue;
  244. }
  245. return v;
  246. },
  247. destroy : function(){
  248. for(var i = 0, a = arguments, len = a.length; i < len; i++) {
  249. var as = a[i];
  250. if(as){
  251. if(as.dom){
  252. as.removeAllListeners();
  253. as.remove();
  254. continue;
  255. }
  256. if(typeof as.destroy == 'function'){
  257. as.destroy();
  258. }
  259. }
  260. }
  261. },
  262. removeNode : isIE ? function(){
  263. var d;
  264. return function(n){
  265. if(n){
  266. d = d || document.createElement('div');
  267. d.appendChild(n);
  268. d.innerHTML = '';
  269. }
  270. }
  271. }() : function(n){
  272. if(n && n.parentNode){
  273. n.parentNode.removeChild(n);
  274. }
  275. },
  276. type : function(o){
  277. if(o === undefined || o === null){
  278. return false;
  279. }
  280. if(o.htmlElement){
  281. return 'element';
  282. }
  283. var t = typeof o;
  284. if(t == 'object' && o.nodeName) {
  285. switch(o.nodeType) {
  286. case 1: return 'element';
  287. case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
  288. }
  289. }
  290. if(t == 'object' || t == 'function') {
  291. switch(o.constructor) {
  292. case Array: return 'array';
  293. case RegExp: return 'regexp';
  294. }
  295. if(typeof o.length == 'number' && typeof o.item == 'function') {
  296. return 'nodelist';
  297. }
  298. }
  299. return t;
  300. },
  301. isEmpty : function(v, allowBlank){
  302. return v === null || v === undefined || (!allowBlank ? v === '' : false);
  303. },
  304. value : function(v, defaultValue, allowBlank){
  305. return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
  306. },
  307. isArray : function(v){
  308. return v && typeof v.pop == 'function';
  309. },
  310. isDate : function(v){
  311. return v && typeof v.getFullYear == 'function';
  312. },
  313. isOpera : isOpera,
  314. isSafari : isSafari,
  315. isSafari3 : isSafari3,
  316. isSafari2 : isSafari && !isSafari3,
  317. isIE : isIE,
  318. isIE6 : isIE && !isIE7,
  319. isIE7 : isIE7,
  320. isGecko : isGecko,
  321. isBorderBox : isBorderBox,
  322. isLinux : isLinux,
  323. isWindows : isWindows,
  324. isMac : isMac,
  325. isAir : isAir,
  326. useShims : ((isIE && !isIE7) || (isGecko && isMac))
  327. });
  328. Ext.ns = Ext.namespace;
  329. })();
  330. Ext.ns("Ext", "Ext.util", "Ext.grid", "Ext.dd", "Ext.tree", "Ext.data",
  331. "Ext.form", "Ext.menu", "Ext.state", "Ext.lib", "Ext.layout", "Ext.app", "Ext.ux");
  332. Ext.apply(Function.prototype, {
  333. createCallback : function(){
  334. var args = arguments;
  335. var method = this;
  336. return function() {
  337. return method.apply(window, args);
  338. };
  339. },
  340. createDelegate : function(obj, args, appendArgs){
  341. var method = this;
  342. return function() {
  343. var callArgs = args || arguments;
  344. if(appendArgs === true){
  345. callArgs = Array.prototype.slice.call(arguments, 0);
  346. callArgs = callArgs.concat(args);
  347. }else if(typeof appendArgs == "number"){
  348. callArgs = Array.prototype.slice.call(arguments, 0);
  349. var applyArgs = [appendArgs, 0].concat(args);
  350. Array.prototype.splice.apply(callArgs, applyArgs);
  351. }
  352. return method.apply(obj || window, callArgs);
  353. };
  354. },
  355. defer : function(millis, obj, args, appendArgs){
  356. var fn = this.createDelegate(obj, args, appendArgs);
  357. if(millis){
  358. return setTimeout(fn, millis);
  359. }
  360. fn();
  361. return 0;
  362. },
  363. createSequence : function(fcn, scope){
  364. if(typeof fcn != "function"){
  365. return this;
  366. }
  367. var method = this;
  368. return function() {
  369. var retval = method.apply(this || window, arguments);
  370. fcn.apply(scope || this || window, arguments);
  371. return retval;
  372. };
  373. },
  374. createInterceptor : function(fcn, scope){
  375. if(typeof fcn != "function"){
  376. return this;
  377. }
  378. var method = this;
  379. return function() {
  380. fcn.target = this;
  381. fcn.method = method;
  382. if(fcn.apply(scope || this || window, arguments) === false){
  383. return;
  384. }
  385. return method.apply(this || window, arguments);
  386. };
  387. }
  388. });
  389. Ext.applyIf(String, {
  390. escape : function(string) {
  391. return string.replace(/('|\\)/g, "\\$1");
  392. },
  393. leftPad : function (val, size, ch) {
  394. var result = new String(val);
  395. if(!ch) {
  396. ch = " ";
  397. }
  398. while (result.length < size) {
  399. result = ch + result;
  400. }
  401. return result.toString();
  402. },
  403. format : function(format){
  404. var args = Array.prototype.slice.call(arguments, 1);
  405. return format.replace(/\{(\d+)\}/g, function(m, i){
  406. return args[i];
  407. });
  408. }
  409. });
  410. String.prototype.toggle = function(value, other){
  411. return this == value ? other : value;
  412. };
  413. String.prototype.trim = function(){
  414. var re = /^\s+|\s+$/g;
  415. return function(){ return this.replace(re, ""); };
  416. }();
  417. Ext.applyIf(Number.prototype, {
  418. constrain : function(min, max){
  419. return Math.min(Math.max(this, min), max);
  420. }
  421. });
  422. Ext.applyIf(Array.prototype, {
  423. indexOf : function(o){
  424. for (var i = 0, len = this.length; i < len; i++){
  425. if(this[i] == o) return i;
  426. }
  427. return -1;
  428. },
  429. remove : function(o){
  430. var index = this.indexOf(o);
  431. if(index != -1){
  432. this.splice(index, 1);
  433. }
  434. return this;
  435. }
  436. });
  437. Date.prototype.getElapsed = function(date) {
  438. return Math.abs((date || new Date()).getTime()-this.getTime());
  439. };
  440. (function() {
  441. var libFlyweight;
  442. Ext.lib.Dom = {
  443. getViewWidth : function(full) {
  444. return full ? this.getDocumentWidth() : this.getViewportWidth();
  445. },
  446. getViewHeight : function(full) {
  447. return full ? this.getDocumentHeight() : this.getViewportHeight();
  448. },
  449. getDocumentHeight: function() {
  450. var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
  451. return Math.max(scrollHeight, this.getViewportHeight());
  452. },
  453. getDocumentWidth: function() {
  454. var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
  455. return Math.max(scrollWidth, this.getViewportWidth());
  456. },
  457. getViewportHeight: function(){
  458. if(Ext.isIE){
  459. return Ext.isStrict ? document.documentElement.clientHeight :
  460. document.body.clientHeight;
  461. }else{
  462. return self.innerHeight;
  463. }
  464. },
  465. getViewportWidth: function() {
  466. if(Ext.isIE){
  467. return Ext.isStrict ? document.documentElement.clientWidth :
  468. document.body.clientWidth;
  469. }else{
  470. return self.innerWidth;
  471. }
  472. },
  473. isAncestor : function(p, c) {
  474. p = Ext.getDom(p);
  475. c = Ext.getDom(c);
  476. if (!p || !c) {
  477. return false;
  478. }
  479. if (p.contains && !Ext.isSafari) {
  480. return p.contains(c);
  481. } else if (p.compareDocumentPosition) {
  482. return !!(p.compareDocumentPosition(c) & 16);
  483. } else {
  484. var parent = c.parentNode;
  485. while (parent) {
  486. if (parent == p) {
  487. return true;
  488. }
  489. else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
  490. return false;
  491. }
  492. parent = parent.parentNode;
  493. }
  494. return false;
  495. }
  496. },
  497. getRegion : function(el) {
  498. return Ext.lib.Region.getRegion(el);
  499. },
  500. getY : function(el) {
  501. return this.getXY(el)[1];
  502. },
  503. getX : function(el) {
  504. return this.getXY(el)[0];
  505. },
  506. getXY : function(el) {
  507. var p, pe, b, scroll, bd = (document.body || document.documentElement);
  508. el = Ext.getDom(el);
  509. if(el == bd){
  510. return [0, 0];
  511. }
  512. if (el.getBoundingClientRect) {
  513. b = el.getBoundingClientRect();
  514. scroll = fly(document).getScroll();
  515. return [b.left + scroll.left, b.top + scroll.top];
  516. }
  517. var x = 0, y = 0;
  518. p = el;
  519. var hasAbsolute = fly(el).getStyle("position") == "absolute";
  520. while (p) {
  521. x += p.offsetLeft;
  522. y += p.offsetTop;
  523. if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
  524. hasAbsolute = true;
  525. }
  526. if (Ext.isGecko) {
  527. pe = fly(p);
  528. var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
  529. var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
  530. x += bl;
  531. y += bt;
  532. if (p != el && pe.getStyle('overflow') != 'visible') {
  533. x += bl;
  534. y += bt;
  535. }
  536. }
  537. p = p.offsetParent;
  538. }
  539. if (Ext.isSafari && hasAbsolute) {
  540. x -= bd.offsetLeft;
  541. y -= bd.offsetTop;
  542. }
  543. if (Ext.isGecko && !hasAbsolute) {
  544. var dbd = fly(bd);
  545. x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
  546. y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
  547. }
  548. p = el.parentNode;
  549. while (p && p != bd) {
  550. if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
  551. x -= p.scrollLeft;
  552. y -= p.scrollTop;
  553. }
  554. p = p.parentNode;
  555. }
  556. return [x, y];
  557. },
  558. setXY : function(el, xy) {
  559. el = Ext.fly(el, '_setXY');
  560. el.position();
  561. var pts = el.translatePoints(xy);
  562. if (xy[0] !== false) {
  563. el.dom.style.left = pts.left + "px";
  564. }
  565. if (xy[1] !== false) {
  566. el.dom.style.top = pts.top + "px";
  567. }
  568. },
  569. setX : function(el, x) {
  570. this.setXY(el, [x, false]);
  571. },
  572. setY : function(el, y) {
  573. this.setXY(el, [false, y]);
  574. }
  575. };
  576. Ext.lib.Event = function() {
  577. var loadComplete = false;
  578. var listeners = [];
  579. var unloadListeners = [];
  580. var retryCount = 0;
  581. var onAvailStack = [];
  582. var counter = 0;
  583. var lastError = null;
  584. return {
  585. POLL_RETRYS: 200,
  586. POLL_INTERVAL: 20,
  587. EL: 0,
  588. TYPE: 1,
  589. FN: 2,
  590. WFN: 3,
  591. OBJ: 3,
  592. ADJ_SCOPE: 4,
  593. _interval: null,
  594. startInterval: function() {
  595. if (!this._interval) {
  596. var self = this;
  597. var callback = function() {
  598. self._tryPreloadAttach();
  599. };
  600. this._interval = setInterval(callback, this.POLL_INTERVAL);
  601. }
  602. },
  603. onAvailable: function(p_id, p_fn, p_obj, p_override) {
  604. onAvailStack.push({ id: p_id,
  605. fn: p_fn,
  606. obj: p_obj,
  607. override: p_override,
  608. checkReady: false });
  609. retryCount = this.POLL_RETRYS;
  610. this.startInterval();
  611. },
  612. addListener: function(el, eventName, fn) {
  613. el = Ext.getDom(el);
  614. if (!el || !fn) {
  615. return false;
  616. }
  617. if ("unload" == eventName) {
  618. unloadListeners[unloadListeners.length] =
  619. [el, eventName, fn];
  620. return true;
  621. }
  622. var wrappedFn = function(e) {
  623. return typeof Ext != 'undefined' ? fn(Ext.lib.Event.getEvent(e)) : false;
  624. };
  625. var li = [el, eventName, fn, wrappedFn];
  626. var index = listeners.length;
  627. listeners[index] = li;
  628. this.doAdd(el, eventName, wrappedFn, false);
  629. return true;
  630. },
  631. removeListener: function(el, eventName, fn) {
  632. var i, len;
  633. el = Ext.getDom(el);
  634. if(!fn) {
  635. return this.purgeElement(el, false, eventName);
  636. }
  637. if ("unload" == eventName) {
  638. for (i = 0,len = unloadListeners.length; i < len; i++) {
  639. var li = unloadListeners[i];
  640. if (li &&
  641. li[0] == el &&
  642. li[1] == eventName &&
  643. li[2] == fn) {
  644. unloadListeners.splice(i, 1);
  645. return true;
  646. }
  647. }
  648. return false;
  649. }
  650. var cacheItem = null;
  651. var index = arguments[3];
  652. if ("undefined" == typeof index) {
  653. index = this._getCacheIndex(el, eventName, fn);
  654. }
  655. if (index >= 0) {
  656. cacheItem = listeners[index];
  657. }
  658. if (!el || !cacheItem) {
  659. return false;
  660. }
  661. this.doRemove(el, eventName, cacheItem[this.WFN], false);
  662. delete listeners[index][this.WFN];
  663. delete listeners[index][this.FN];
  664. listeners.splice(index, 1);
  665. return true;
  666. },
  667. getTarget: function(ev, resolveTextNode) {
  668. ev = ev.browserEvent || ev;
  669. var t = ev.target || ev.srcElement;
  670. return this.resolveTextNode(t);
  671. },
  672. resolveTextNode: function(node) {
  673. if (Ext.isSafari && node && 3 == node.nodeType) {
  674. return node.parentNode;
  675. } else {
  676. return node;
  677. }
  678. },
  679. getPageX: function(ev) {
  680. ev = ev.browserEvent || ev;
  681. var x = ev.pageX;
  682. if (!x && 0 !== x) {
  683. x = ev.clientX || 0;
  684. if (Ext.isIE) {
  685. x += this.getScroll()[1];
  686. }
  687. }
  688. return x;
  689. },
  690. getPageY: function(ev) {
  691. ev = ev.browserEvent || ev;
  692. var y = ev.pageY;
  693. if (!y && 0 !== y) {
  694. y = ev.clientY || 0;
  695. if (Ext.isIE) {
  696. y += this.getScroll()[0];
  697. }
  698. }
  699. return y;
  700. },
  701. getXY: function(ev) {
  702. ev = ev.browserEvent || ev;
  703. return [this.getPageX(ev), this.getPageY(ev)];
  704. },
  705. getRelatedTarget: function(ev) {
  706. ev = ev.browserEvent || ev;
  707. var t = ev.relatedTarget;
  708. if (!t) {
  709. if (ev.type == "mouseout") {
  710. t = ev.toElement;
  711. } else if (ev.type == "mouseover") {
  712. t = ev.fromElement;
  713. }
  714. }
  715. return this.resolveTextNode(t);
  716. },
  717. getTime: function(ev) {
  718. ev = ev.browserEvent || ev;
  719. if (!ev.time) {
  720. var t = new Date().getTime();
  721. try {
  722. ev.time = t;
  723. } catch(ex) {
  724. this.lastError = ex;
  725. return t;
  726. }
  727. }
  728. return ev.time;
  729. },
  730. stopEvent: function(ev) {
  731. this.stopPropagation(ev);
  732. this.preventDefault(ev);
  733. },
  734. stopPropagation: function(ev) {
  735. ev = ev.browserEvent || ev;
  736. if (ev.stopPropagation) {
  737. ev.stopPropagation();
  738. } else {
  739. ev.cancelBubble = true;
  740. }
  741. },
  742. preventDefault: function(ev) {
  743. ev = ev.browserEvent || ev;
  744. if(ev.preventDefault) {
  745. ev.preventDefault();
  746. } else {
  747. ev.returnValue = false;
  748. }
  749. },
  750. getEvent: function(e) {
  751. var ev = e || window.event;
  752. if (!ev) {
  753. var c = this.getEvent.caller;
  754. while (c) {
  755. ev = c.arguments[0];
  756. if (ev && Event == ev.constructor) {
  757. break;
  758. }
  759. c = c.caller;
  760. }
  761. }
  762. return ev;
  763. },
  764. getCharCode: function(ev) {
  765. ev = ev.browserEvent || ev;
  766. return ev.charCode || ev.keyCode || 0;
  767. },
  768. _getCacheIndex: function(el, eventName, fn) {
  769. for (var i = 0,len = listeners.length; i < len; ++i) {
  770. var li = listeners[i];
  771. if (li &&
  772. li[this.FN] == fn &&
  773. li[this.EL] == el &&
  774. li[this.TYPE] == eventName) {
  775. return i;
  776. }
  777. }
  778. return -1;
  779. },
  780. elCache: {},
  781. getEl: function(id) {
  782. return document.getElementById(id);
  783. },
  784. clearCache: function() {
  785. },
  786. _load: function(e) {
  787. loadComplete = true;
  788. var EU = Ext.lib.Event;
  789. if (Ext.isIE) {
  790. EU.doRemove(window, "load", EU._load);
  791. }
  792. },
  793. _tryPreloadAttach: function() {
  794. if (this.locked) {
  795. return false;
  796. }
  797. this.locked = true;
  798. var tryAgain = !loadComplete;
  799. if (!tryAgain) {
  800. tryAgain = (retryCount > 0);
  801. }
  802. var notAvail = [];
  803. for (var i = 0,len = onAvailStack.length; i < len; ++i) {
  804. var item = onAvailStack[i];
  805. if (item) {
  806. var el = this.getEl(item.id);
  807. if (el) {
  808. if (!item.checkReady ||
  809. loadComplete ||
  810. el.nextSibling ||
  811. (document && document.body)) {
  812. var scope = el;
  813. if (item.override) {
  814. if (item.override === true) {
  815. scope = item.obj;
  816. } else {
  817. scope = item.override;
  818. }
  819. }
  820. item.fn.call(scope, item.obj);
  821. onAvailStack[i] = null;
  822. }
  823. } else {
  824. notAvail.push(item);
  825. }
  826. }
  827. }
  828. retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
  829. if (tryAgain) {
  830. this.startInterval();
  831. } else {
  832. clearInterval(this._interval);
  833. this._interval = null;
  834. }
  835. this.locked = false;
  836. return true;
  837. },
  838. purgeElement: function(el, recurse, eventName) {
  839. var elListeners = this.getListeners(el, eventName);
  840. if (elListeners) {
  841. for (var i = 0,len = elListeners.length; i < len; ++i) {
  842. var l = elListeners[i];
  843. this.removeListener(el, l.type, l.fn);
  844. }
  845. }
  846. if (recurse && el && el.childNodes) {
  847. for (i = 0,len = el.childNodes.length; i < len; ++i) {
  848. this.purgeElement(el.childNodes[i], recurse, eventName);
  849. }
  850. }
  851. },
  852. getListeners: function(el, eventName) {
  853. var results = [], searchLists;
  854. if (!eventName) {
  855. searchLists = [listeners, unloadListeners];
  856. } else if (eventName == "unload") {
  857. searchLists = [unloadListeners];
  858. } else {
  859. searchLists = [listeners];
  860. }
  861. for (var j = 0; j < searchLists.length; ++j) {
  862. var searchList = searchLists[j];
  863. if (searchList && searchList.length > 0) {
  864. for (var i = 0,len = searchList.length; i < len; ++i) {
  865. var l = searchList[i];
  866. if (l && l[this.EL] === el &&
  867. (!eventName || eventName === l[this.TYPE])) {
  868. results.push({
  869. type: l[this.TYPE],
  870. fn: l[this.FN],
  871. obj: l[this.OBJ],
  872. adjust: l[this.ADJ_SCOPE],
  873. index: i
  874. });
  875. }
  876. }
  877. }
  878. }
  879. return (results.length) ? results : null;
  880. },
  881. _unload: function(e) {
  882. var EU = Ext.lib.Event, i, j, l, len, index;
  883. for (i = 0,len = unloadListeners.length; i < len; ++i) {
  884. l = unloadListeners[i];
  885. if (l) {
  886. var scope = window;
  887. if (l[EU.ADJ_SCOPE]) {
  888. if (l[EU.ADJ_SCOPE] === true) {
  889. scope = l[EU.OBJ];
  890. } else {
  891. scope = l[EU.ADJ_SCOPE];
  892. }
  893. }
  894. l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
  895. unloadListeners[i] = null;
  896. l = null;
  897. scope = null;
  898. }
  899. }
  900. unloadListeners = null;
  901. if (listeners && listeners.length > 0) {
  902. j = listeners.length;
  903. while (j) {
  904. index = j - 1;
  905. l = listeners[index];
  906. if (l) {
  907. EU.removeListener(l[EU.EL], l[EU.TYPE],
  908. l[EU.FN], index);
  909. }
  910. j = j - 1;
  911. }
  912. l = null;
  913. EU.clearCache();
  914. }
  915. EU.doRemove(window, "unload", EU._unload);
  916. },
  917. getScroll: function() {
  918. var dd = document.documentElement, db = document.body;
  919. if (dd && (dd.scrollTop || dd.scrollLeft)) {
  920. return [dd.scrollTop, dd.scrollLeft];
  921. } else if (db) {
  922. return [db.scrollTop, db.scrollLeft];
  923. } else {
  924. return [0, 0];
  925. }
  926. },
  927. doAdd: function () {
  928. if (window.addEventListener) {
  929. return function(el, eventName, fn, capture) {
  930. el.addEventListener(eventName, fn, (capture));
  931. };
  932. } else if (window.attachEvent) {
  933. return function(el, eventName, fn, capture) {
  934. el.attachEvent("on" + eventName, fn);
  935. };
  936. } else {
  937. return function() {
  938. };
  939. }
  940. }(),
  941. doRemove: function() {
  942. if (window.removeEventListener) {
  943. return function (el, eventName, fn, capture) {
  944. el.removeEventListener(eventName, fn, (capture));
  945. };
  946. } else if (window.detachEvent) {
  947. return function (el, eventName, fn) {
  948. el.detachEvent("on" + eventName, fn);
  949. };
  950. } else {
  951. return function() {
  952. };
  953. }
  954. }()
  955. };
  956. }();
  957. var E = Ext.lib.Event;
  958. E.on = E.addListener;
  959. E.un = E.removeListener;
  960. if (document && document.body) {
  961. E._load();
  962. } else {
  963. E.doAdd(window, "load", E._load);
  964. }
  965. E.doAdd(window, "unload", E._unload);
  966. E._tryPreloadAttach();
  967. Ext.lib.Ajax = {
  968. request : function(method, uri, cb, data, options) {
  969. if(options){
  970. var hs = options.headers;
  971. if(hs){
  972. for(var h in hs){
  973. if(hs.hasOwnProperty(h)){
  974. this.initHeader(h, hs[h], false);
  975. }
  976. }
  977. }
  978. if(options.xmlData){
  979. this.initHeader('Content-Type', 'text/xml', false);
  980. method = 'POST';
  981. data = options.xmlData;
  982. }else if(options.jsonData){
  983. this.initHeader('Content-Type', 'text/javascript', false);
  984. method = 'POST';
  985. data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
  986. }
  987. }
  988. return this.asyncRequest(method, uri, cb, data);
  989. },
  990. serializeForm : function(form) {
  991. if(typeof form == 'string') {
  992. form = (document.getElementById(form) || document.forms[form]);
  993. }
  994. var el, name, val, disabled, data = '', hasSubmit = false;
  995. for (var i = 0; i < form.elements.length; i++) {
  996. el = form.elements[i];
  997. disabled = form.elements[i].disabled;
  998. name = form.elements[i].name;
  999. val = form.elements[i].value;
  1000. if (!disabled && name){
  1001. switch (el.type)
  1002. {
  1003. case 'select-one':
  1004. case 'select-multiple':
  1005. for (var j = 0; j < el.options.length; j++) {
  1006. if (el.options[j].selected) {
  1007. if (Ext.isIE) {
  1008. data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
  1009. }
  1010. else {
  1011. data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
  1012. }
  1013. }
  1014. }
  1015. break;
  1016. case 'radio':
  1017. case 'checkbox':
  1018. if (el.checked) {
  1019. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  1020. }
  1021. break;
  1022. case 'file':
  1023. case undefined:
  1024. case 'reset':
  1025. case 'button':
  1026. break;
  1027. case 'submit':
  1028. if(hasSubmit == false) {
  1029. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  1030. hasSubmit = true;
  1031. }
  1032. break;
  1033. default:
  1034. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  1035. break;
  1036. }
  1037. }
  1038. }
  1039. data = data.substr(0, data.length - 1);
  1040. return data;
  1041. },
  1042. headers:{},
  1043. hasHeaders:false,
  1044. useDefaultHeader:true,
  1045. defaultPostHeader:'application/x-www-form-urlencoded',
  1046. useDefaultXhrHeader:true,
  1047. defaultXhrHeader:'XMLHttpRequest',
  1048. hasDefaultHeaders:true,
  1049. defaultHeaders:{},
  1050. poll:{},
  1051. timeout:{},
  1052. pollInterval:50,
  1053. transactionId:0,
  1054. setProgId:function(id)
  1055. {
  1056. this.activeX.unshift(id);
  1057. },
  1058. setDefaultPostHeader:function(b)
  1059. {
  1060. this.useDefaultHeader = b;
  1061. },
  1062. setDefaultXhrHeader:function(b)
  1063. {
  1064. this.useDefaultXhrHeader = b;
  1065. },
  1066. setPollingInterval:function(i)
  1067. {
  1068. if (typeof i == 'number' && isFinite(i)) {
  1069. this.pollInterval = i;
  1070. }
  1071. },
  1072. createXhrObject:function(transactionId)
  1073. {
  1074. var obj,http;
  1075. try
  1076. {
  1077. http = new XMLHttpRequest();
  1078. obj = { conn:http, tId:transactionId };
  1079. }
  1080. catch(e)
  1081. {
  1082. for (var i = 0; i < this.activeX.length; ++i) {
  1083. try
  1084. {
  1085. http = new ActiveXObject(this.activeX[i]);
  1086. obj = { conn:http, tId:transactionId };
  1087. break;
  1088. }
  1089. catch(e) {
  1090. }
  1091. }
  1092. }
  1093. finally
  1094. {
  1095. return obj;
  1096. }
  1097. },
  1098. getConnectionObject:function()
  1099. {
  1100. var o;
  1101. var tId = this.transactionId;
  1102. try
  1103. {
  1104. o = this.createXhrObject(tId);
  1105. if (o) {
  1106. this.transactionId++;
  1107. }
  1108. }
  1109. catch(e) {
  1110. }
  1111. finally
  1112. {
  1113. return o;
  1114. }
  1115. },
  1116. asyncRequest:function(method, uri, callback, postData)
  1117. {
  1118. var o = this.getConnectionObject();
  1119. if (!o) {
  1120. return null;
  1121. }
  1122. else {
  1123. o.conn.open(method, uri, true);
  1124. if (this.useDefaultXhrHeader) {
  1125. if (!this.defaultHeaders['X-Requested-With']) {
  1126. this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
  1127. }
  1128. }
  1129. if(postData && this.useDefaultHeader){
  1130. this.initHeader('Content-Type', this.defaultPostHeader);
  1131. }
  1132. if (this.hasDefaultHeaders || this.hasHeaders) {
  1133. this.setHeader(o);
  1134. }
  1135. this.handleReadyState(o, callback);
  1136. o.conn.send(postData || null);
  1137. return o;
  1138. }
  1139. },
  1140. handleReadyState:function(o, callback)
  1141. {
  1142. var oConn = this;
  1143. if (callback && callback.timeout) {
  1144. this.timeout[o.tId] = window.setTimeout(function() {
  1145. oConn.abort(o, callback, true);
  1146. }, callback.timeout);
  1147. }
  1148. this.poll[o.tId] = window.setInterval(
  1149. function() {
  1150. if (o.conn && o.conn.readyState == 4) {
  1151. window.clearInterval(oConn.poll[o.tId]);
  1152. delete oConn.poll[o.tId];
  1153. if (callback && callback.timeout) {
  1154. window.clearTimeout(oConn.timeout[o.tId]);
  1155. delete oConn.timeout[o.tId];
  1156. }
  1157. oConn.handleTransactionResponse(o, callback);
  1158. }
  1159. }
  1160. , this.pollInterval);
  1161. },
  1162. handleTransactionResponse:function(o, callback, isAbort)
  1163. {
  1164. if (!callback) {
  1165. this.releaseObject(o);
  1166. return;
  1167. }
  1168. var httpStatus, responseObject;
  1169. try
  1170. {
  1171. if (o.conn.status !== undefined && o.conn.status != 0) {
  1172. httpStatus = o.conn.status;
  1173. }
  1174. else {
  1175. httpStatus = 13030;
  1176. }
  1177. }
  1178. catch(e) {
  1179. httpStatus = 13030;
  1180. }
  1181. if (httpStatus >= 200 && httpStatus < 300) {
  1182. responseObject = this.createResponseObject(o, callback.argument);
  1183. if (callback.success) {
  1184. if (!callback.scope) {
  1185. callback.success(responseObject);
  1186. }
  1187. else {
  1188. callback.success.apply(callback.scope, [responseObject]);
  1189. }
  1190. }
  1191. }
  1192. else {
  1193. switch (httpStatus) {
  1194. case 12002:
  1195. case 12029:
  1196. case 12030:
  1197. case 12031:
  1198. case 12152:
  1199. case 13030:
  1200. responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
  1201. if (callback.failure) {
  1202. if (!callback.scope) {
  1203. callback.failure(responseObject);
  1204. }
  1205. else {
  1206. callback.failure.apply(callback.scope, [responseObject]);
  1207. }
  1208. }
  1209. break;
  1210. default:
  1211. responseObject = this.createResponseObject(o, callback.argument);
  1212. if (callback.failure) {
  1213. if (!callback.scope) {
  1214. callback.failure(responseObject);
  1215. }
  1216. else {
  1217. callback.failure.apply(callback.scope, [responseObject]);
  1218. }
  1219. }
  1220. }
  1221. }
  1222. this.releaseObject(o);
  1223. responseObject = null;
  1224. },
  1225. createResponseObject:function(o, callbackArg)
  1226. {
  1227. var obj = {};
  1228. var headerObj = {};
  1229. try
  1230. {
  1231. var headerStr = o.conn.getAllResponseHeaders();
  1232. var header = headerStr.split('\n');
  1233. for (var i = 0; i < header.length; i++) {
  1234. var delimitPos = header[i].indexOf(':');
  1235. if (delimitPos != -1) {
  1236. headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
  1237. }
  1238. }
  1239. }
  1240. catch(e) {
  1241. }
  1242. obj.tId = o.tId;
  1243. obj.status = o.conn.status;
  1244. obj.statusText = o.conn.statusText;
  1245. obj.getResponseHeader = headerObj;
  1246. obj.getAllResponseHeaders = headerStr;
  1247. obj.responseText = o.conn.responseText;
  1248. obj.responseXML = o.conn.responseXML;
  1249. if (typeof callbackArg !== undefined) {
  1250. obj.argument = callbackArg;
  1251. }
  1252. return obj;
  1253. },
  1254. createExceptionObject:function(tId, callbackArg, isAbort)
  1255. {
  1256. var COMM_CODE = 0;
  1257. var COMM_ERROR = 'communication failure';
  1258. var ABORT_CODE = -1;
  1259. var ABORT_ERROR = 'transaction aborted';
  1260. var obj = {};
  1261. obj.tId = tId;
  1262. if (isAbort) {
  1263. obj.status = ABORT_CODE;
  1264. obj.statusText = ABORT_ERROR;
  1265. }
  1266. else {
  1267. obj.status = COMM_CODE;
  1268. obj.statusText = COMM_ERROR;
  1269. }
  1270. if (callbackArg) {
  1271. obj.argument = callbackArg;
  1272. }
  1273. return obj;
  1274. },
  1275. initHeader:function(label, value, isDefault)
  1276. {
  1277. var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
  1278. if (headerObj[label] === undefined) {
  1279. headerObj[label] = value;
  1280. }
  1281. else {
  1282. headerObj[label] = value + "," + headerObj[label];
  1283. }
  1284. if (isDefault) {
  1285. this.hasDefaultHeaders = true;
  1286. }
  1287. else {
  1288. this.hasHeaders = true;
  1289. }
  1290. },
  1291. setHeader:function(o)
  1292. {
  1293. if (this.hasDefaultHeaders) {
  1294. for (var prop in this.defaultHeaders) {
  1295. if (this.defaultHeaders.hasOwnProperty(prop)) {
  1296. o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
  1297. }
  1298. }
  1299. }
  1300. if (this.hasHeaders) {
  1301. for (var prop in this.headers) {
  1302. if (this.headers.hasOwnProperty(prop)) {
  1303. o.conn.setRequestHeader(prop, this.headers[prop]);
  1304. }
  1305. }
  1306. this.headers = {};
  1307. this.hasHeaders = false;
  1308. }
  1309. },
  1310. resetDefaultHeaders:function() {
  1311. delete this.defaultHeaders;
  1312. this.defaultHeaders = {};

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