PageRenderTime 74ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/branches/1.0/www/js/extjs/ext-base.js

http://scalr.googlecode.com/
JavaScript | 2135 lines | 1636 code | 485 blank | 14 comment | 426 complexity | ef6f3c404b09973c4a39a8b0d143fd6e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. /*
  2. * Ext JS Library 2.2.1
  3. * Copyright(c) 2006-2009, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://extjs.com/license
  7. */
  8. (function() {
  9. var libFlyweight;
  10. Ext.lib.Dom = {
  11. getViewWidth : function(full) {
  12. return full ? this.getDocumentWidth() : this.getViewportWidth();
  13. },
  14. getViewHeight : function(full) {
  15. return full ? this.getDocumentHeight() : this.getViewportHeight();
  16. },
  17. getDocumentHeight: function() {
  18. var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
  19. return Math.max(scrollHeight, this.getViewportHeight());
  20. },
  21. getDocumentWidth: function() {
  22. var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
  23. return Math.max(scrollWidth, this.getViewportWidth());
  24. },
  25. getViewportHeight: function(){
  26. if(Ext.isIE){
  27. return Ext.isStrict ? document.documentElement.clientHeight :
  28. document.body.clientHeight;
  29. }else{
  30. return self.innerHeight;
  31. }
  32. },
  33. getViewportWidth: function() {
  34. if(Ext.isIE){
  35. return Ext.isStrict ? document.documentElement.clientWidth :
  36. document.body.clientWidth;
  37. }else{
  38. return self.innerWidth;
  39. }
  40. },
  41. isAncestor : function(p, c) {
  42. p = Ext.getDom(p);
  43. c = Ext.getDom(c);
  44. if (!p || !c) {
  45. return false;
  46. }
  47. if (p.contains && !Ext.isSafari) {
  48. return p.contains(c);
  49. } else if (p.compareDocumentPosition) {
  50. return !!(p.compareDocumentPosition(c) & 16);
  51. } else {
  52. var parent = c.parentNode;
  53. while (parent) {
  54. if (parent == p) {
  55. return true;
  56. }
  57. else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
  58. return false;
  59. }
  60. parent = parent.parentNode;
  61. }
  62. return false;
  63. }
  64. },
  65. getRegion : function(el) {
  66. return Ext.lib.Region.getRegion(el);
  67. },
  68. getY : function(el) {
  69. return this.getXY(el)[1];
  70. },
  71. getX : function(el) {
  72. return this.getXY(el)[0];
  73. },
  74. getXY : function(el) {
  75. var p, pe, b, scroll, bd = (document.body || document.documentElement);
  76. el = Ext.getDom(el);
  77. if(el == bd){
  78. return [0, 0];
  79. }
  80. if (el.getBoundingClientRect) {
  81. b = el.getBoundingClientRect();
  82. scroll = fly(document).getScroll();
  83. return [b.left + scroll.left, b.top + scroll.top];
  84. }
  85. var x = 0, y = 0;
  86. p = el;
  87. var hasAbsolute = fly(el).getStyle("position") == "absolute";
  88. while (p) {
  89. x += p.offsetLeft;
  90. y += p.offsetTop;
  91. if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
  92. hasAbsolute = true;
  93. }
  94. if (Ext.isGecko) {
  95. pe = fly(p);
  96. var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
  97. var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
  98. x += bl;
  99. y += bt;
  100. if (p != el && pe.getStyle('overflow') != 'visible') {
  101. x += bl;
  102. y += bt;
  103. }
  104. }
  105. p = p.offsetParent;
  106. }
  107. if (Ext.isSafari && hasAbsolute) {
  108. x -= bd.offsetLeft;
  109. y -= bd.offsetTop;
  110. }
  111. if (Ext.isGecko && !hasAbsolute) {
  112. var dbd = fly(bd);
  113. x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
  114. y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
  115. }
  116. p = el.parentNode;
  117. while (p && p != bd) {
  118. if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
  119. x -= p.scrollLeft;
  120. y -= p.scrollTop;
  121. }
  122. p = p.parentNode;
  123. }
  124. return [x, y];
  125. },
  126. setXY : function(el, xy) {
  127. el = Ext.fly(el, '_setXY');
  128. el.position();
  129. var pts = el.translatePoints(xy);
  130. if (xy[0] !== false) {
  131. el.dom.style.left = pts.left + "px";
  132. }
  133. if (xy[1] !== false) {
  134. el.dom.style.top = pts.top + "px";
  135. }
  136. },
  137. setX : function(el, x) {
  138. this.setXY(el, [x, false]);
  139. },
  140. setY : function(el, y) {
  141. this.setXY(el, [false, y]);
  142. }
  143. };
  144. /*
  145. * Portions of this file are based on pieces of Yahoo User Interface Library
  146. * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
  147. * YUI licensed under the BSD License:
  148. * http://developer.yahoo.net/yui/license.txt
  149. */
  150. Ext.lib.Event = function() {
  151. var loadComplete = false;
  152. var listeners = [];
  153. var unloadListeners = [];
  154. var retryCount = 0;
  155. var onAvailStack = [];
  156. var counter = 0;
  157. var lastError = null;
  158. return {
  159. POLL_RETRYS: 200,
  160. POLL_INTERVAL: 20,
  161. EL: 0,
  162. TYPE: 1,
  163. FN: 2,
  164. WFN: 3,
  165. OBJ: 3,
  166. ADJ_SCOPE: 4,
  167. _interval: null,
  168. startInterval: function() {
  169. if (!this._interval) {
  170. var self = this;
  171. var callback = function() {
  172. self._tryPreloadAttach();
  173. };
  174. this._interval = setInterval(callback, this.POLL_INTERVAL);
  175. }
  176. },
  177. onAvailable: function(p_id, p_fn, p_obj, p_override) {
  178. onAvailStack.push({ id: p_id,
  179. fn: p_fn,
  180. obj: p_obj,
  181. override: p_override,
  182. checkReady: false });
  183. retryCount = this.POLL_RETRYS;
  184. this.startInterval();
  185. },
  186. addListener: function(el, eventName, fn) {
  187. el = Ext.getDom(el);
  188. if (!el || !fn) {
  189. return false;
  190. }
  191. if ("unload" == eventName) {
  192. unloadListeners[unloadListeners.length] =
  193. [el, eventName, fn];
  194. return true;
  195. }
  196. // prevent unload errors with simple check
  197. var wrappedFn = function(e) {
  198. return typeof Ext != 'undefined' ? fn(Ext.lib.Event.getEvent(e)) : false;
  199. };
  200. var li = [el, eventName, fn, wrappedFn];
  201. var index = listeners.length;
  202. listeners[index] = li;
  203. this.doAdd(el, eventName, wrappedFn, false);
  204. return true;
  205. },
  206. removeListener: function(el, eventName, fn) {
  207. var i, len;
  208. el = Ext.getDom(el);
  209. if(!fn) {
  210. return this.purgeElement(el, false, eventName);
  211. }
  212. if ("unload" == eventName) {
  213. for (i = 0,len = unloadListeners.length; i < len; i++) {
  214. var li = unloadListeners[i];
  215. if (li &&
  216. li[0] == el &&
  217. li[1] == eventName &&
  218. li[2] == fn) {
  219. unloadListeners.splice(i, 1);
  220. return true;
  221. }
  222. }
  223. return false;
  224. }
  225. var cacheItem = null;
  226. var index = arguments[3];
  227. if ("undefined" == typeof index) {
  228. index = this._getCacheIndex(el, eventName, fn);
  229. }
  230. if (index >= 0) {
  231. cacheItem = listeners[index];
  232. }
  233. if (!el || !cacheItem) {
  234. return false;
  235. }
  236. this.doRemove(el, eventName, cacheItem[this.WFN], false);
  237. delete listeners[index][this.WFN];
  238. delete listeners[index][this.FN];
  239. listeners.splice(index, 1);
  240. return true;
  241. },
  242. getTarget: function(ev, resolveTextNode) {
  243. ev = ev.browserEvent || ev;
  244. var t = ev.target || ev.srcElement;
  245. return this.resolveTextNode(t);
  246. },
  247. resolveTextNode: function(node) {
  248. if (Ext.isSafari && node && 3 == node.nodeType) {
  249. return node.parentNode;
  250. } else {
  251. return node;
  252. }
  253. },
  254. getPageX: function(ev) {
  255. ev = ev.browserEvent || ev;
  256. var x = ev.pageX;
  257. if (!x && 0 !== x) {
  258. x = ev.clientX || 0;
  259. if (Ext.isIE) {
  260. x += this.getScroll()[1];
  261. }
  262. }
  263. return x;
  264. },
  265. getPageY: function(ev) {
  266. ev = ev.browserEvent || ev;
  267. var y = ev.pageY;
  268. if (!y && 0 !== y) {
  269. y = ev.clientY || 0;
  270. if (Ext.isIE) {
  271. y += this.getScroll()[0];
  272. }
  273. }
  274. return y;
  275. },
  276. getXY: function(ev) {
  277. ev = ev.browserEvent || ev;
  278. return [this.getPageX(ev), this.getPageY(ev)];
  279. },
  280. getRelatedTarget: function(ev) {
  281. ev = ev.browserEvent || ev;
  282. var t = ev.relatedTarget;
  283. if (!t) {
  284. if (ev.type == "mouseout") {
  285. t = ev.toElement;
  286. } else if (ev.type == "mouseover") {
  287. t = ev.fromElement;
  288. }
  289. }
  290. return this.resolveTextNode(t);
  291. },
  292. getTime: function(ev) {
  293. ev = ev.browserEvent || ev;
  294. if (!ev.time) {
  295. var t = new Date().getTime();
  296. try {
  297. ev.time = t;
  298. } catch(ex) {
  299. this.lastError = ex;
  300. return t;
  301. }
  302. }
  303. return ev.time;
  304. },
  305. stopEvent: function(ev) {
  306. this.stopPropagation(ev);
  307. this.preventDefault(ev);
  308. },
  309. stopPropagation: function(ev) {
  310. ev = ev.browserEvent || ev;
  311. if (ev.stopPropagation) {
  312. ev.stopPropagation();
  313. } else {
  314. ev.cancelBubble = true;
  315. }
  316. },
  317. preventDefault: function(ev) {
  318. ev = ev.browserEvent || ev;
  319. if(ev.preventDefault) {
  320. ev.preventDefault();
  321. } else {
  322. ev.returnValue = false;
  323. }
  324. },
  325. getEvent: function(e) {
  326. var ev = e || window.event;
  327. if (!ev) {
  328. var c = this.getEvent.caller;
  329. while (c) {
  330. ev = c.arguments[0];
  331. if (ev && Event == ev.constructor) {
  332. break;
  333. }
  334. c = c.caller;
  335. }
  336. }
  337. return ev;
  338. },
  339. getCharCode: function(ev) {
  340. ev = ev.browserEvent || ev;
  341. return ev.charCode || ev.keyCode || 0;
  342. },
  343. _getCacheIndex: function(el, eventName, fn) {
  344. for (var i = 0,len = listeners.length; i < len; ++i) {
  345. var li = listeners[i];
  346. if (li &&
  347. li[this.FN] == fn &&
  348. li[this.EL] == el &&
  349. li[this.TYPE] == eventName) {
  350. return i;
  351. }
  352. }
  353. return -1;
  354. },
  355. elCache: {},
  356. getEl: function(id) {
  357. return document.getElementById(id);
  358. },
  359. clearCache: function() {
  360. },
  361. _load: function(e) {
  362. loadComplete = true;
  363. var EU = Ext.lib.Event;
  364. if (Ext.isIE) {
  365. EU.doRemove(window, "load", EU._load);
  366. }
  367. },
  368. _tryPreloadAttach: function() {
  369. if (this.locked) {
  370. return false;
  371. }
  372. this.locked = true;
  373. var tryAgain = !loadComplete;
  374. if (!tryAgain) {
  375. tryAgain = (retryCount > 0);
  376. }
  377. var notAvail = [];
  378. for (var i = 0,len = onAvailStack.length; i < len; ++i) {
  379. var item = onAvailStack[i];
  380. if (item) {
  381. var el = this.getEl(item.id);
  382. if (el) {
  383. if (!item.checkReady ||
  384. loadComplete ||
  385. el.nextSibling ||
  386. (document && document.body)) {
  387. var scope = el;
  388. if (item.override) {
  389. if (item.override === true) {
  390. scope = item.obj;
  391. } else {
  392. scope = item.override;
  393. }
  394. }
  395. item.fn.call(scope, item.obj);
  396. onAvailStack[i] = null;
  397. }
  398. } else {
  399. notAvail.push(item);
  400. }
  401. }
  402. }
  403. retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
  404. if (tryAgain) {
  405. this.startInterval();
  406. } else {
  407. clearInterval(this._interval);
  408. this._interval = null;
  409. }
  410. this.locked = false;
  411. return true;
  412. },
  413. purgeElement: function(el, recurse, eventName) {
  414. var elListeners = this.getListeners(el, eventName);
  415. if (elListeners) {
  416. for (var i = 0,len = elListeners.length; i < len; ++i) {
  417. var l = elListeners[i];
  418. this.removeListener(el, l.type, l.fn);
  419. }
  420. }
  421. if (recurse && el && el.childNodes) {
  422. for (i = 0,len = el.childNodes.length; i < len; ++i) {
  423. this.purgeElement(el.childNodes[i], recurse, eventName);
  424. }
  425. }
  426. },
  427. getListeners: function(el, eventName) {
  428. var results = [], searchLists;
  429. if (!eventName) {
  430. searchLists = [listeners, unloadListeners];
  431. } else if (eventName == "unload") {
  432. searchLists = [unloadListeners];
  433. } else {
  434. searchLists = [listeners];
  435. }
  436. for (var j = 0; j < searchLists.length; ++j) {
  437. var searchList = searchLists[j];
  438. if (searchList && searchList.length > 0) {
  439. for (var i = 0,len = searchList.length; i < len; ++i) {
  440. var l = searchList[i];
  441. if (l && l[this.EL] === el &&
  442. (!eventName || eventName === l[this.TYPE])) {
  443. results.push({
  444. type: l[this.TYPE],
  445. fn: l[this.FN],
  446. obj: l[this.OBJ],
  447. adjust: l[this.ADJ_SCOPE],
  448. index: i
  449. });
  450. }
  451. }
  452. }
  453. }
  454. return (results.length) ? results : null;
  455. },
  456. _unload: function(e) {
  457. var EU = Ext.lib.Event, i, j, l, len, index;
  458. for (i = 0,len = unloadListeners.length; i < len; ++i) {
  459. l = unloadListeners[i];
  460. if (l) {
  461. var scope = window;
  462. if (l[EU.ADJ_SCOPE]) {
  463. if (l[EU.ADJ_SCOPE] === true) {
  464. scope = l[EU.OBJ];
  465. } else {
  466. scope = l[EU.ADJ_SCOPE];
  467. }
  468. }
  469. l[EU.FN].call(scope, EU.getEvent(e), l[EU.OBJ]);
  470. unloadListeners[i] = null;
  471. l = null;
  472. scope = null;
  473. }
  474. }
  475. unloadListeners = null;
  476. if (listeners && listeners.length > 0) {
  477. j = listeners.length;
  478. while (j) {
  479. index = j - 1;
  480. l = listeners[index];
  481. if (l) {
  482. EU.removeListener(l[EU.EL], l[EU.TYPE],
  483. l[EU.FN], index);
  484. }
  485. j = j - 1;
  486. }
  487. l = null;
  488. EU.clearCache();
  489. }
  490. EU.doRemove(window, "unload", EU._unload);
  491. },
  492. getScroll: function() {
  493. var dd = document.documentElement, db = document.body;
  494. if (dd && (dd.scrollTop || dd.scrollLeft)) {
  495. return [dd.scrollTop, dd.scrollLeft];
  496. } else if (db) {
  497. return [db.scrollTop, db.scrollLeft];
  498. } else {
  499. return [0, 0];
  500. }
  501. },
  502. doAdd: function () {
  503. if (window.addEventListener) {
  504. return function(el, eventName, fn, capture) {
  505. el.addEventListener(eventName, fn, (capture));
  506. };
  507. } else if (window.attachEvent) {
  508. return function(el, eventName, fn, capture) {
  509. el.attachEvent("on" + eventName, fn);
  510. };
  511. } else {
  512. return function() {
  513. };
  514. }
  515. }(),
  516. doRemove: function() {
  517. if (window.removeEventListener) {
  518. return function (el, eventName, fn, capture) {
  519. el.removeEventListener(eventName, fn, (capture));
  520. };
  521. } else if (window.detachEvent) {
  522. return function (el, eventName, fn) {
  523. el.detachEvent("on" + eventName, fn);
  524. };
  525. } else {
  526. return function() {
  527. };
  528. }
  529. }()
  530. };
  531. }();
  532. var E = Ext.lib.Event;
  533. E.on = E.addListener;
  534. E.un = E.removeListener;
  535. if(document && document.body) {
  536. E._load();
  537. } else {
  538. E.doAdd(window, "load", E._load);
  539. }
  540. E.doAdd(window, "unload", E._unload);
  541. E._tryPreloadAttach();
  542. Ext.lib.Ajax = {
  543. request : function(method, uri, cb, data, options) {
  544. if(options){
  545. var hs = options.headers;
  546. if(hs){
  547. for(var h in hs){
  548. if(hs.hasOwnProperty(h)){
  549. this.initHeader(h, hs[h], false);
  550. }
  551. }
  552. }
  553. if(options.xmlData){
  554. if (!hs || !hs['Content-Type']){
  555. this.initHeader('Content-Type', 'text/xml', false);
  556. }
  557. method = (method ? method : (options.method ? options.method : 'POST'));
  558. data = options.xmlData;
  559. }else if(options.jsonData){
  560. if (!hs || !hs['Content-Type']){
  561. this.initHeader('Content-Type', 'application/json', false);
  562. }
  563. method = (method ? method : (options.method ? options.method : 'POST'));
  564. data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
  565. }
  566. }
  567. return this.asyncRequest(method, uri, cb, data);
  568. },
  569. serializeForm : function(form) {
  570. if(typeof form == 'string') {
  571. form = (document.getElementById(form) || document.forms[form]);
  572. }
  573. var el, name, val, disabled, data = '', hasSubmit = false;
  574. for (var i = 0; i < form.elements.length; i++) {
  575. el = form.elements[i];
  576. disabled = form.elements[i].disabled;
  577. name = form.elements[i].name;
  578. val = form.elements[i].value;
  579. if (!disabled && name){
  580. switch (el.type)
  581. {
  582. case 'select-one':
  583. case 'select-multiple':
  584. for (var j = 0; j < el.options.length; j++) {
  585. if (el.options[j].selected) {
  586. if (Ext.isIE) {
  587. data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].attributes['value'].specified ? el.options[j].value : el.options[j].text) + '&';
  588. }
  589. else {
  590. data += encodeURIComponent(name) + '=' + encodeURIComponent(el.options[j].hasAttribute('value') ? el.options[j].value : el.options[j].text) + '&';
  591. }
  592. }
  593. }
  594. break;
  595. case 'radio':
  596. case 'checkbox':
  597. if (el.checked) {
  598. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  599. }
  600. break;
  601. case 'file':
  602. case undefined:
  603. case 'reset':
  604. case 'button':
  605. break;
  606. case 'submit':
  607. if(hasSubmit == false) {
  608. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  609. hasSubmit = true;
  610. }
  611. break;
  612. default:
  613. data += encodeURIComponent(name) + '=' + encodeURIComponent(val) + '&';
  614. break;
  615. }
  616. }
  617. }
  618. data = data.substr(0, data.length - 1);
  619. return data;
  620. },
  621. headers:{},
  622. hasHeaders:false,
  623. useDefaultHeader:true,
  624. defaultPostHeader:'application/x-www-form-urlencoded; charset=UTF-8',
  625. useDefaultXhrHeader:true,
  626. defaultXhrHeader:'XMLHttpRequest',
  627. hasDefaultHeaders:true,
  628. defaultHeaders:{},
  629. poll:{},
  630. timeout:{},
  631. pollInterval:50,
  632. transactionId:0,
  633. setProgId:function(id)
  634. {
  635. this.activeX.unshift(id);
  636. },
  637. setDefaultPostHeader:function(b)
  638. {
  639. this.useDefaultHeader = b;
  640. },
  641. setDefaultXhrHeader:function(b)
  642. {
  643. this.useDefaultXhrHeader = b;
  644. },
  645. setPollingInterval:function(i)
  646. {
  647. if (typeof i == 'number' && isFinite(i)) {
  648. this.pollInterval = i;
  649. }
  650. },
  651. createXhrObject:function(transactionId)
  652. {
  653. var obj,http;
  654. try
  655. {
  656. http = new XMLHttpRequest();
  657. obj = { conn:http, tId:transactionId };
  658. }
  659. catch(e)
  660. {
  661. for (var i = 0; i < this.activeX.length; ++i) {
  662. try
  663. {
  664. http = new ActiveXObject(this.activeX[i]);
  665. obj = { conn:http, tId:transactionId };
  666. break;
  667. }
  668. catch(e) {
  669. }
  670. }
  671. }
  672. finally
  673. {
  674. return obj;
  675. }
  676. },
  677. getConnectionObject:function()
  678. {
  679. var o;
  680. var tId = this.transactionId;
  681. try
  682. {
  683. o = this.createXhrObject(tId);
  684. if (o) {
  685. this.transactionId++;
  686. }
  687. }
  688. catch(e) {
  689. }
  690. finally
  691. {
  692. return o;
  693. }
  694. },
  695. asyncRequest:function(method, uri, callback, postData)
  696. {
  697. var o = this.getConnectionObject();
  698. if (!o) {
  699. return null;
  700. }
  701. else {
  702. o.conn.open(method, uri, true);
  703. if (this.useDefaultXhrHeader) {
  704. if (!this.defaultHeaders['X-Requested-With']) {
  705. this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
  706. }
  707. }
  708. if(postData && this.useDefaultHeader && (!this.hasHeaders || !this.headers['Content-Type'])){
  709. this.initHeader('Content-Type', this.defaultPostHeader);
  710. }
  711. if (this.hasDefaultHeaders || this.hasHeaders) {
  712. this.setHeader(o);
  713. }
  714. this.handleReadyState(o, callback);
  715. o.conn.send(postData || null);
  716. return o;
  717. }
  718. },
  719. handleReadyState:function(o, callback)
  720. {
  721. var oConn = this;
  722. if (callback && callback.timeout) {
  723. this.timeout[o.tId] = window.setTimeout(function() {
  724. oConn.abort(o, callback, true);
  725. }, callback.timeout);
  726. }
  727. this.poll[o.tId] = window.setInterval(
  728. function() {
  729. if (o.conn && o.conn.readyState == 4) {
  730. window.clearInterval(oConn.poll[o.tId]);
  731. delete oConn.poll[o.tId];
  732. if (callback && callback.timeout) {
  733. window.clearTimeout(oConn.timeout[o.tId]);
  734. delete oConn.timeout[o.tId];
  735. }
  736. oConn.handleTransactionResponse(o, callback);
  737. }
  738. }
  739. , this.pollInterval);
  740. },
  741. handleTransactionResponse:function(o, callback, isAbort)
  742. {
  743. if (!callback) {
  744. this.releaseObject(o);
  745. return;
  746. }
  747. var httpStatus, responseObject;
  748. try
  749. {
  750. if (o.conn.status !== undefined && o.conn.status != 0) {
  751. httpStatus = o.conn.status;
  752. }
  753. else {
  754. httpStatus = 13030;
  755. }
  756. }
  757. catch(e) {
  758. httpStatus = 13030;
  759. }
  760. if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
  761. responseObject = this.createResponseObject(o, callback.argument);
  762. if (callback.success) {
  763. if (!callback.scope) {
  764. callback.success(responseObject);
  765. }
  766. else {
  767. callback.success.apply(callback.scope, [responseObject]);
  768. }
  769. }
  770. }
  771. else {
  772. switch (httpStatus) {
  773. case 12002:
  774. case 12029:
  775. case 12030:
  776. case 12031:
  777. case 12152:
  778. case 13030:
  779. responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false));
  780. if (callback.failure) {
  781. if (!callback.scope) {
  782. callback.failure(responseObject);
  783. }
  784. else {
  785. callback.failure.apply(callback.scope, [responseObject]);
  786. }
  787. }
  788. break;
  789. default:
  790. responseObject = this.createResponseObject(o, callback.argument);
  791. if (callback.failure) {
  792. if (!callback.scope) {
  793. callback.failure(responseObject);
  794. }
  795. else {
  796. callback.failure.apply(callback.scope, [responseObject]);
  797. }
  798. }
  799. }
  800. }
  801. this.releaseObject(o);
  802. responseObject = null;
  803. },
  804. createResponseObject:function(o, callbackArg)
  805. {
  806. var obj = {};
  807. var headerObj = {};
  808. try
  809. {
  810. var headerStr = o.conn.getAllResponseHeaders();
  811. var header = headerStr.split('\n');
  812. for (var i = 0; i < header.length; i++) {
  813. var delimitPos = header[i].indexOf(':');
  814. if (delimitPos != -1) {
  815. headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
  816. }
  817. }
  818. }
  819. catch(e) {
  820. }
  821. obj.tId = o.tId;
  822. obj.status = o.conn.status;
  823. obj.statusText = o.conn.statusText;
  824. obj.getResponseHeader = headerObj;
  825. obj.getAllResponseHeaders = headerStr;
  826. obj.responseText = o.conn.responseText;
  827. obj.responseXML = o.conn.responseXML;
  828. if (typeof callbackArg !== undefined) {
  829. obj.argument = callbackArg;
  830. }
  831. return obj;
  832. },
  833. createExceptionObject:function(tId, callbackArg, isAbort)
  834. {
  835. var COMM_CODE = 0;
  836. var COMM_ERROR = 'communication failure';
  837. var ABORT_CODE = -1;
  838. var ABORT_ERROR = 'transaction aborted';
  839. var obj = {};
  840. obj.tId = tId;
  841. if (isAbort) {
  842. obj.status = ABORT_CODE;
  843. obj.statusText = ABORT_ERROR;
  844. }
  845. else {
  846. obj.status = COMM_CODE;
  847. obj.statusText = COMM_ERROR;
  848. }
  849. if (callbackArg) {
  850. obj.argument = callbackArg;
  851. }
  852. return obj;
  853. },
  854. initHeader:function(label, value, isDefault)
  855. {
  856. var headerObj = (isDefault) ? this.defaultHeaders : this.headers;
  857. if (headerObj[label] === undefined) {
  858. headerObj[label] = value;
  859. }
  860. else {
  861. headerObj[label] = value + "," + headerObj[label];
  862. }
  863. if (isDefault) {
  864. this.hasDefaultHeaders = true;
  865. }
  866. else {
  867. this.hasHeaders = true;
  868. }
  869. },
  870. setHeader:function(o)
  871. {
  872. if (this.hasDefaultHeaders) {
  873. for (var prop in this.defaultHeaders) {
  874. if (this.defaultHeaders.hasOwnProperty(prop)) {
  875. o.conn.setRequestHeader(prop, this.defaultHeaders[prop]);
  876. }
  877. }
  878. }
  879. if (this.hasHeaders) {
  880. for (var prop in this.headers) {
  881. if (this.headers.hasOwnProperty(prop)) {
  882. o.conn.setRequestHeader(prop, this.headers[prop]);
  883. }
  884. }
  885. this.headers = {};
  886. this.hasHeaders = false;
  887. }
  888. },
  889. resetDefaultHeaders:function() {
  890. delete this.defaultHeaders;
  891. this.defaultHeaders = {};
  892. this.hasDefaultHeaders = false;
  893. },
  894. abort:function(o, callback, isTimeout)
  895. {
  896. if (this.isCallInProgress(o)) {
  897. o.conn.abort();
  898. window.clearInterval(this.poll[o.tId]);
  899. delete this.poll[o.tId];
  900. if (isTimeout) {
  901. delete this.timeout[o.tId];
  902. }
  903. this.handleTransactionResponse(o, callback, true);
  904. return true;
  905. }
  906. else {
  907. return false;
  908. }
  909. },
  910. isCallInProgress:function(o)
  911. {
  912. if (o.conn) {
  913. return o.conn.readyState != 4 && o.conn.readyState != 0;
  914. }
  915. else {
  916. return false;
  917. }
  918. },
  919. releaseObject:function(o)
  920. {
  921. o.conn = null;
  922. o = null;
  923. },
  924. activeX:[
  925. 'MSXML2.XMLHTTP.3.0',
  926. 'MSXML2.XMLHTTP',
  927. 'Microsoft.XMLHTTP'
  928. ]
  929. };
  930. Ext.lib.Region = function(t, r, b, l) {
  931. this.top = t;
  932. this[1] = t;
  933. this.right = r;
  934. this.bottom = b;
  935. this.left = l;
  936. this[0] = l;
  937. };
  938. Ext.lib.Region.prototype = {
  939. contains : function(region) {
  940. return ( region.left >= this.left &&
  941. region.right <= this.right &&
  942. region.top >= this.top &&
  943. region.bottom <= this.bottom );
  944. },
  945. getArea : function() {
  946. return ( (this.bottom - this.top) * (this.right - this.left) );
  947. },
  948. intersect : function(region) {
  949. var t = Math.max(this.top, region.top);
  950. var r = Math.min(this.right, region.right);
  951. var b = Math.min(this.bottom, region.bottom);
  952. var l = Math.max(this.left, region.left);
  953. if (b >= t && r >= l) {
  954. return new Ext.lib.Region(t, r, b, l);
  955. } else {
  956. return null;
  957. }
  958. },
  959. union : function(region) {
  960. var t = Math.min(this.top, region.top);
  961. var r = Math.max(this.right, region.right);
  962. var b = Math.max(this.bottom, region.bottom);
  963. var l = Math.min(this.left, region.left);
  964. return new Ext.lib.Region(t, r, b, l);
  965. },
  966. constrainTo : function(r) {
  967. this.top = this.top.constrain(r.top, r.bottom);
  968. this.bottom = this.bottom.constrain(r.top, r.bottom);
  969. this.left = this.left.constrain(r.left, r.right);
  970. this.right = this.right.constrain(r.left, r.right);
  971. return this;
  972. },
  973. adjust : function(t, l, b, r) {
  974. this.top += t;
  975. this.left += l;
  976. this.right += r;
  977. this.bottom += b;
  978. return this;
  979. }
  980. };
  981. Ext.lib.Region.getRegion = function(el) {
  982. var p = Ext.lib.Dom.getXY(el);
  983. var t = p[1];
  984. var r = p[0] + el.offsetWidth;
  985. var b = p[1] + el.offsetHeight;
  986. var l = p[0];
  987. return new Ext.lib.Region(t, r, b, l);
  988. };
  989. Ext.lib.Point = function(x, y) {
  990. if (Ext.isArray(x)) {
  991. y = x[1];
  992. x = x[0];
  993. }
  994. this.x = this.right = this.left = this[0] = x;
  995. this.y = this.top = this.bottom = this[1] = y;
  996. };
  997. Ext.lib.Point.prototype = new Ext.lib.Region();
  998. Ext.lib.Anim = {
  999. scroll : function(el, args, duration, easing, cb, scope) {
  1000. return this.run(el, args, duration, easing, cb, scope, Ext.lib.Scroll);
  1001. },
  1002. motion : function(el, args, duration, easing, cb, scope) {
  1003. return this.run(el, args, duration, easing, cb, scope, Ext.lib.Motion);
  1004. },
  1005. color : function(el, args, duration, easing, cb, scope) {
  1006. return this.run(el, args, duration, easing, cb, scope, Ext.lib.ColorAnim);
  1007. },
  1008. run : function(el, args, duration, easing, cb, scope, type) {
  1009. type = type || Ext.lib.AnimBase;
  1010. if (typeof easing == "string") {
  1011. easing = Ext.lib.Easing[easing];
  1012. }
  1013. var anim = new type(el, args, duration, easing);
  1014. anim.animateX(function() {
  1015. Ext.callback(cb, scope);
  1016. });
  1017. return anim;
  1018. }
  1019. };
  1020. function fly(el) {
  1021. if (!libFlyweight) {
  1022. libFlyweight = new Ext.Element.Flyweight();
  1023. }
  1024. libFlyweight.dom = el;
  1025. return libFlyweight;
  1026. }
  1027. if(Ext.isIE) {
  1028. function fnCleanUp() {
  1029. var p = Function.prototype;
  1030. delete p.createSequence;
  1031. delete p.defer;
  1032. delete p.createDelegate;
  1033. delete p.createCallback;
  1034. delete p.createInterceptor;
  1035. window.detachEvent("onunload", fnCleanUp);
  1036. }
  1037. window.attachEvent("onunload", fnCleanUp);
  1038. }
  1039. Ext.lib.AnimBase = function(el, attributes, duration, method) {
  1040. if (el) {
  1041. this.init(el, attributes, duration, method);
  1042. }
  1043. };
  1044. Ext.lib.AnimBase.prototype = {
  1045. toString: function() {
  1046. var el = this.getEl();
  1047. var id = el.id || el.tagName;
  1048. return ("Anim " + id);
  1049. },
  1050. patterns: {
  1051. noNegatives: /width|height|opacity|padding/i,
  1052. offsetAttribute: /^((width|height)|(top|left))$/,
  1053. defaultUnit: /width|height|top$|bottom$|left$|right$/i,
  1054. offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i
  1055. },
  1056. doMethod: function(attr, start, end) {
  1057. return this.method(this.currentFrame, start, end - start, this.totalFrames);
  1058. },
  1059. setAttribute: function(attr, val, unit) {
  1060. if (this.patterns.noNegatives.test(attr)) {
  1061. val = (val > 0) ? val : 0;
  1062. }
  1063. Ext.fly(this.getEl(), '_anim').setStyle(attr, val + unit);
  1064. },
  1065. getAttribute: function(attr) {
  1066. var el = this.getEl();
  1067. var val = fly(el).getStyle(attr);
  1068. if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {
  1069. return parseFloat(val);
  1070. }
  1071. var a = this.patterns.offsetAttribute.exec(attr) || [];
  1072. var pos = !!( a[3] );
  1073. var box = !!( a[2] );
  1074. if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {
  1075. val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];
  1076. } else {
  1077. val = 0;
  1078. }
  1079. return val;
  1080. },
  1081. getDefaultUnit: function(attr) {
  1082. if (this.patterns.defaultUnit.test(attr)) {
  1083. return 'px';
  1084. }
  1085. return '';
  1086. },
  1087. animateX : function(callback, scope) {
  1088. var f = function() {
  1089. this.onComplete.removeListener(f);
  1090. if (typeof callback == "function") {
  1091. callback.call(scope || this, this);
  1092. }
  1093. };
  1094. this.onComplete.addListener(f, this);
  1095. this.animate();
  1096. },
  1097. setRuntimeAttribute: function(attr) {
  1098. var start;
  1099. var end;
  1100. var attributes = this.attributes;
  1101. this.runtimeAttributes[attr] = {};
  1102. var isset = function(prop) {
  1103. return (typeof prop !== 'undefined');
  1104. };
  1105. if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {
  1106. return false;
  1107. }
  1108. start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);
  1109. if (isset(attributes[attr]['to'])) {
  1110. end = attributes[attr]['to'];
  1111. } else if (isset(attributes[attr]['by'])) {
  1112. if (start.constructor == Array) {
  1113. end = [];
  1114. for (var i = 0, len = start.length; i < len; ++i) {
  1115. end[i] = start[i] + attributes[attr]['by'][i];
  1116. }
  1117. } else {
  1118. end = start + attributes[attr]['by'];
  1119. }
  1120. }
  1121. this.runtimeAttributes[attr].start = start;
  1122. this.runtimeAttributes[attr].end = end;
  1123. this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);
  1124. },
  1125. init: function(el, attributes, duration, method) {
  1126. var isAnimated = false;
  1127. var startTime = null;
  1128. var actualFrames = 0;
  1129. el = Ext.getDom(el);
  1130. this.attributes = attributes || {};
  1131. this.duration = duration || 1;
  1132. this.method = method || Ext.lib.Easing.easeNone;
  1133. this.useSeconds = true;
  1134. this.currentFrame = 0;
  1135. this.totalFrames = Ext.lib.AnimMgr.fps;
  1136. this.getEl = function() {
  1137. return el;
  1138. };
  1139. this.isAnimated = function() {
  1140. return isAnimated;
  1141. };
  1142. this.getStartTime = function() {
  1143. return startTime;
  1144. };
  1145. this.runtimeAttributes = {};
  1146. this.animate = function() {
  1147. if (this.isAnimated()) {
  1148. return false;
  1149. }
  1150. this.currentFrame = 0;
  1151. this.totalFrames = ( this.useSeconds ) ? Math.ceil(Ext.lib.AnimMgr.fps * this.duration) : this.duration;
  1152. Ext.lib.AnimMgr.registerElement(this);
  1153. };
  1154. this.stop = function(finish) {
  1155. if (finish) {
  1156. this.currentFrame = this.totalFrames;
  1157. this._onTween.fire();
  1158. }
  1159. Ext.lib.AnimMgr.stop(this);
  1160. };
  1161. var onStart = function() {
  1162. this.onStart.fire();
  1163. this.runtimeAttributes = {};
  1164. for (var attr in this.attributes) {
  1165. this.setRuntimeAttribute(attr);
  1166. }
  1167. isAnimated = true;
  1168. actualFrames = 0;
  1169. startTime = new Date();
  1170. };
  1171. var onTween = function() {
  1172. var data = {
  1173. duration: new Date() - this.getStartTime(),
  1174. currentFrame: this.currentFrame
  1175. };
  1176. data.toString = function() {
  1177. return (
  1178. 'duration: ' + data.duration +
  1179. ', currentFrame: ' + data.currentFrame
  1180. );
  1181. };
  1182. this.onTween.fire(data);
  1183. var runtimeAttributes = this.runtimeAttributes;
  1184. for (var attr in runtimeAttributes) {
  1185. this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);
  1186. }
  1187. actualFrames += 1;
  1188. };
  1189. var onComplete = function() {
  1190. var actual_duration = (new Date() - startTime) / 1000 ;
  1191. var data = {
  1192. duration: actual_duration,
  1193. frames: actualFrames,
  1194. fps: actualFrames / actual_duration
  1195. };
  1196. data.toString = function() {
  1197. return (
  1198. 'duration: ' + data.duration +
  1199. ', frames: ' + data.frames +
  1200. ', fps: ' + data.fps
  1201. );
  1202. };
  1203. isAnimated = false;
  1204. actualFrames = 0;
  1205. this.onComplete.fire(data);
  1206. };
  1207. this._onStart = new Ext.util.Event(this);
  1208. this.onStart = new Ext.util.Event(this);
  1209. this.onTween = new Ext.util.Event(this);
  1210. this._onTween = new Ext.util.Event(this);
  1211. this.onComplete = new Ext.util.Event(this);
  1212. this._onComplete = new Ext.util.Event(this);
  1213. this._onStart.addListener(onStart);
  1214. this._onTween.addListener(onTween);
  1215. this._onComplete.addListener(onComplete);
  1216. }
  1217. };
  1218. Ext.lib.AnimMgr = new function() {
  1219. var thread = null;
  1220. var queue = [];
  1221. var tweenCount = 0;
  1222. this.fps = 1000;
  1223. this.delay = 1;
  1224. this.registerElement = function(tween) {
  1225. queue[queue.length] = tween;
  1226. tweenCount += 1;
  1227. tween._onStart.fire();
  1228. this.start();
  1229. };
  1230. this.unRegister = function(tween, index) {
  1231. tween._onComplete.fire();
  1232. index = index || getIndex(tween);
  1233. if (index != -1) {
  1234. queue.splice(index, 1);
  1235. }
  1236. tweenCount -= 1;
  1237. if (tweenCount <= 0) {
  1238. this.stop();
  1239. }
  1240. };
  1241. this.start = function() {
  1242. if (thread === null) {
  1243. thread = setInterval(this.run, this.delay);
  1244. }
  1245. };
  1246. this.stop = function(tween) {
  1247. if (!tween) {
  1248. clearInterval(thread);
  1249. for (var i = 0, len = queue.length; i < len; ++i) {
  1250. if (queue[0].isAnimated()) {
  1251. this.unRegister(queue[0], 0);
  1252. }
  1253. }
  1254. queue = [];
  1255. thread = null;
  1256. tweenCount = 0;
  1257. }
  1258. else {
  1259. this.unRegister(tween);
  1260. }
  1261. };
  1262. this.run = function() {
  1263. for (var i = 0, len = queue.length; i < len; ++i) {
  1264. var tween = queue[i];
  1265. if (!tween || !tween.isAnimated()) {
  1266. continue;
  1267. }
  1268. if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)
  1269. {
  1270. tween.currentFrame += 1;
  1271. if (tween.useSeconds) {
  1272. correctFrame(tween);
  1273. }
  1274. tween._onTween.fire();
  1275. }
  1276. else {
  1277. Ext.lib.AnimMgr.stop(tween, i);
  1278. }
  1279. }
  1280. };
  1281. var getIndex = function(anim) {
  1282. for (var i = 0, len = queue.length; i < len; ++i) {
  1283. if (queue[i] == anim) {
  1284. return i;
  1285. }
  1286. }
  1287. return -1;
  1288. };
  1289. var correctFrame = function(tween) {
  1290. var frames = tween.totalFrames;
  1291. var frame = tween.currentFrame;
  1292. var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);
  1293. var elapsed = (new Date() - tween.getStartTime());
  1294. var tweak = 0;
  1295. if (elapsed < tween.duration * 1000) {
  1296. tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);
  1297. } else {
  1298. tweak = frames - (frame + 1);
  1299. }
  1300. if (tweak > 0 && isFinite(tweak)) {
  1301. if (tween.currentFrame + tweak >= frames) {
  1302. tweak = frames - (frame + 1);
  1303. }
  1304. tween.currentFrame += tweak;
  1305. }
  1306. };
  1307. };
  1308. Ext.lib.Bezier = new function() {
  1309. this.getPosition = function(points, t) {
  1310. var n = points.length;
  1311. var tmp = [];
  1312. for (var i = 0; i < n; ++i) {
  1313. tmp[i] = [points[i][0], points[i][1]];
  1314. }
  1315. for (var j = 1; j < n; ++j) {
  1316. for (i = 0; i < n - j; ++i) {
  1317. tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
  1318. tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
  1319. }
  1320. }
  1321. return [ tmp[0][0], tmp[0][1] ];
  1322. };
  1323. };
  1324. (function() {
  1325. Ext.lib.ColorAnim = function(el, attributes, duration, method) {
  1326. Ext.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
  1327. };
  1328. Ext.extend(Ext.lib.ColorAnim, Ext.lib.AnimBase);
  1329. var Y = Ext.lib;
  1330. var superclass = Y.ColorAnim.superclass;
  1331. var proto = Y.ColorAnim.prototype;
  1332. proto.toString = function() {
  1333. var el = this.getEl();
  1334. var id = el.id || el.tagName;
  1335. return ("ColorAnim " + id);
  1336. };
  1337. proto.patterns.color = /color$/i;
  1338. proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
  1339. proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
  1340. proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
  1341. proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
  1342. proto.parseColor = function(s) {
  1343. if (s.length == 3) {
  1344. return s;
  1345. }
  1346. var c = this.patterns.hex.exec(s);
  1347. if (c && c.length == 4) {
  1348. return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
  1349. }
  1350. c = this.patterns.rgb.exec(s);
  1351. if (c && c.length == 4) {
  1352. return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
  1353. }
  1354. c = this.patterns.hex3.exec(s);
  1355. if (c && c.length == 4) {
  1356. return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
  1357. }
  1358. return null;
  1359. };
  1360. proto.getAttribute = function(attr) {
  1361. var el = this.getEl();
  1362. if (this.patterns.color.test(attr)) {
  1363. var val = fly(el).getStyle(attr);
  1364. if (this.patterns.transparent.test(val)) {
  1365. var parent = el.parentNode;
  1366. val = fly(parent).getStyle(attr);
  1367. while (parent && this.patterns.transparent.test(val)) {
  1368. parent = parent.parentNode;
  1369. val = fly(parent).getStyle(attr);
  1370. if (parent.tagName.toUpperCase() == 'HTML') {
  1371. val = '#fff';
  1372. }
  1373. }
  1374. }
  1375. } else {
  1376. val = superclass.getAttribute.call(this, attr);
  1377. }
  1378. return val;
  1379. };
  1380. proto.doMethod = function(attr, start, end) {
  1381. var val;
  1382. if (this.patterns.color.test(attr)) {
  1383. val = [];
  1384. for (var i = 0, len = start.length; i < len; ++i) {
  1385. val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
  1386. }
  1387. val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
  1388. }
  1389. else {
  1390. val = superclass.doMethod.call(this, attr, start, end);
  1391. }
  1392. return val;
  1393. };
  1394. proto.setRuntimeAttribute = function(attr) {
  1395. superclass.setRuntimeAttribute.call(this, attr);
  1396. if (this.patterns.color.test(attr)) {
  1397. var attributes = this.attributes;
  1398. var start = this.parseColor(this.runtimeAttributes[attr].start);
  1399. var end = this.parseColor(this.runtimeAttributes[attr].end);
  1400. if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
  1401. end = this.parseColor(attributes[attr].by);
  1402. for (var i = 0, len = start.length; i < len; ++i) {
  1403. end[i] = start[i] + end[i];
  1404. }
  1405. }
  1406. this.runtimeAttributes[attr].start = start;
  1407. this.runtimeAttributes[attr].end = end;
  1408. }
  1409. };
  1410. })();
  1411. Ext.lib.Easing = {
  1412. easeNone: function (t, b, c, d) {
  1413. return c * t / d + b;
  1414. },
  1415. easeIn: function (t, b, c, d) {
  1416. return c * (t /= d) * t + b;
  1417. },
  1418. easeOut: function (t, b, c, d) {
  1419. return -c * (t /= d) * (t - 2) + b;
  1420. },
  1421. easeBoth: function (t, b, c, d) {
  1422. if ((t /= d / 2) < 1) {
  1423. return c / 2 * t * t + b;
  1424. }
  1425. return -c / 2 * ((--t) * (t - 2) - 1) + b;
  1426. },
  1427. easeInStrong: function (t, b, c, d) {
  1428. return c * (t /= d) * t * t * t + b;
  1429. },
  1430. easeOutStrong: function (t, b, c, d) {
  1431. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  1432. },
  1433. easeBothStrong: function (t, b, c, d) {
  1434. if ((t /= d / 2) < 1) {
  1435. return c / 2 * t * t * t * t + b;
  1436. }
  1437. return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
  1438. },
  1439. elasticIn: function (t, b, c, d, a, p) {
  1440. if (t == 0) {
  1441. return b;
  1442. }
  1443. if ((t /= d) == 1) {
  1444. return b + c;
  1445. }
  1446. if (!p) {
  1447. p = d * .3;
  1448. }
  1449. if (!a || a < Math.abs(c)) {
  1450. a = c;
  1451. var s = p / 4;
  1452. }
  1453. else {
  1454. var s = p / (2 * Math.PI) * Math.asin(c / a);
  1455. }
  1456. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  1457. },
  1458. elasticOut: function (t, b, c, d, a, p) {
  1459. if (t == 0) {
  1460. return b;
  1461. }
  1462. if ((t /= d) == 1) {
  1463. return b + c;
  1464. }
  1465. if (!p) {
  1466. p = d * .3;
  1467. }
  1468. if (!a || a < Math.abs(c)) {
  1469. a = c;
  1470. var s = p / 4;
  1471. }
  1472. else {
  1473. var s = p / (2 * Math.PI) * Math.asin(c / a);
  1474. }
  1475. return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
  1476. },
  1477. elasticBoth: function (t, b, c, d, a, p) {
  1478. if (t == 0) {
  1479. return b;
  1480. }
  1481. if ((t /= d / 2) == 2) {
  1482. return b + c;
  1483. }
  1484. if (!p) {
  1485. p = d * (.3 * 1.5);
  1486. }
  1487. if (!a || a < Math.abs(c)) {
  1488. a = c;
  1489. var s = p / 4;
  1490. }
  1491. else {
  1492. var s = p / (2 * Math.PI) * Math.asin(c / a);
  1493. }
  1494. if (t < 1) {
  1495. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) *
  1496. Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  1497. }
  1498. return a * Math.pow(2, -10 * (t -= 1)) *
  1499. Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
  1500. },
  1501. backIn: function (t, b, c, d, s) {
  1502. if (typeof s == 'undefined') {
  1503. s = 1.70158;
  1504. }
  1505. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  1506. },
  1507. backOut: function (t, b, c, d, s) {
  1508. if (typeof s == 'undefined') {
  1509. s = 1.70158;
  1510. }
  1511. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  1512. },
  1513. backBoth: function (t, b, c, d, s) {
  1514. if (typeof s == 'undefined') {
  1515. s = 1.70158;
  1516. }
  1517. if ((t /= d / 2 ) < 1) {
  1518. return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  1519. }
  1520. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  1521. },
  1522. bounceIn: function (t, b, c, d) {
  1523. return c - Ext.lib.Easing.bounceOut(d - t, 0, c, d) + b;
  1524. },
  1525. bounceOut: function (t, b, c, d) {
  1526. if ((t /= d) < (1 / 2.75)) {
  1527. return c * (7.5625 * t * t) + b;
  1528. } else if (t < (2 / 2.75)) {
  1529. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  1530. } else if (t < (2.5 / 2.75)) {
  1531. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  1532. }
  1533. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  1534. },
  1535. bounceBoth: function (t, b, c, d) {
  1536. if (t < d / 2) {
  1537. return Ext.lib.Easing.bounceIn(t * 2, 0, c, d) * .5 + b;
  1538. }
  1539. return Ext.lib.Easing.bounceOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  1540. }
  1541. };
  1542. (function() {
  1543. Ext.lib.Motion = function(el, attributes, duration, method) {
  1544. if (el) {
  1545. Ext.lib.Motion.superclass.constructor.call(this, el, attributes, duration, method);
  1546. }
  1547. };
  1548. Ext.extend(Ext.lib.Motion, Ext.lib.ColorAnim);
  1549. var Y = Ext.lib;
  1550. var superclass = Y.Motion.superclass;
  1551. var proto = Y.Motion.prototype;
  1552. proto.toString = function() {
  1553. var el = this.getEl();
  1554. var id = el.id || el.tagName;
  1555. return ("Motion " + id);
  1556. };
  1557. proto.patterns.points = /^points$/i;
  1558. proto.setAttribute = function(attr, val, unit) {
  1559. if (this.patterns.points.test(attr)) {
  1560. unit = unit || 'px';
  1561. superclass.setAttribute.call(this, 'left', val[0], unit);
  1562. superclass.setAttribute.call(this, 'top', val[1], unit);
  1563. } else {
  1564. superclass.setAttribute.call(this, attr, val, unit);
  1565. }
  1566. };
  1567. proto.getAttribute = function(attr) {
  1568. if (this.patterns.points.test(attr)) {
  1569. var val = [
  1570. superclass.getAttribute.call(this, 'left'),
  1571. superclass.getAttribute.call(this, 'top')
  1572. ];
  1573. } else {
  1574. val = superclass.getAttribute.call(this, attr);
  1575. }
  1576. return val;
  1577. };
  1578. proto.doMethod = function(attr, start, end) {
  1579. var val = null;
  1580. if (this.patterns.points.test(attr)) {
  1581. var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100;
  1582. val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t);
  1583. } else {
  1584. val = superclass.doMethod.call(this, attr, start, end);
  1585. }
  1586. return val;
  1587. };
  1588. proto.setRuntimeAttribute = function(attr) {
  1589. if (this.patterns.points.test(attr)) {
  1590. var el = this.getEl();
  1591. var attributes = this.attributes;
  1592. var start;
  1593. var control = attributes['points']['control'] || [];
  1594. var end;
  1595. var i, len;
  1596. if (control.length > 0 && !Ext.isArray(control[0])) {
  1597. control = [control];
  1598. } else {
  1599. var tmp = [];
  1600. for (i = 0,len = control.length; i < len; ++i) {
  1601. tmp[i] = control[i];
  1602. }
  1603. control = tmp;
  1604. }
  1605. Ext.fly(el, '_anim').position();
  1606. if (isset(attributes['points']['from'])) {
  1607. Ext.lib.Dom.setXY(el, attributes['points']['from']);
  1608. }
  1609. else {
  1610. Ext.lib.Dom.setXY(el, Ext.lib.Dom.getXY(el));
  1611. }
  1612. start = this.getAttribute('points');
  1613. if (isset(attributes['points']['to'])) {
  1614. end = translateValues.call(this, attributes['points']['to'], start);
  1615. var pageXY = Ext.lib.Dom.getXY(this.getEl());
  1616. for (i = 0,len = control.length; i < len; ++i) {
  1617. control[i] = translateValues.call(this, control[i], start);
  1618. }
  1619. } else if (isset(attributes['points']['by'])) {
  1620. end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ];
  1621. for (i = 0,len = control.length; i < len; ++i) {
  1622. control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ];
  1623. }
  1624. }
  1625. this.runtimeAttributes[attr] = [start];
  1626. if (control.length > 0) {
  1627. this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control);
  1628. }
  1629. this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end;
  1630. }
  1631. else {
  1632. superclass.setRuntimeAttribute.call(this, attr);
  1633. }
  1634. };
  1635. var translateValues = function(val, start) {
  1636. var pageXY = Ext.lib.Dom.getXY(this.getEl());
  1637. val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ];
  1638. return val;
  1639. };
  1640. var isset = function(prop) {
  1641. return (typeof prop !== 'undefined');
  1642. };
  1643. })();
  1644. (function() {
  1645. Ext.lib.Scroll = function(el, attributes, duration, method) {
  1646. if (el) {
  1647. Ext.lib.Scroll.superclass.constructor.call(this, el, attributes, duration, method);
  1648. }
  1649. };
  1650. Ext.extend(Ext.lib.Scroll, Ext.lib.Color