jquery-bridge.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. if (typeof jQuery == "undefined") {
  7. throw "Unable to load Ext, jQuery not found.";
  8. }
  9. (function() {
  10. var libFlyweight;
  11. Ext.lib.Dom = {
  12. getViewWidth : function(full) {
  13. // jQuery doesn't report full window size on document query, so max
  14. // both
  15. return full ? Math.max(jQuery(document).width(), jQuery(window)
  16. .width()) : jQuery(window).width();
  17. },
  18. getViewHeight : function(full) {
  19. // jQuery doesn't report full window size on document query, so max
  20. // both
  21. return full ? Math.max(jQuery(document).height(), jQuery(window)
  22. .height()) : jQuery(window).height();
  23. },
  24. isAncestor : function(p, c) {
  25. p = Ext.getDom(p);
  26. c = Ext.getDom(c);
  27. if (!p || !c) {
  28. return false;
  29. }
  30. if (p.contains && !Ext.isSafari) {
  31. return p.contains(c);
  32. } else if (p.compareDocumentPosition) {
  33. return !!(p.compareDocumentPosition(c) & 16);
  34. } else {
  35. var parent = c.parentNode;
  36. while (parent) {
  37. if (parent == p) {
  38. return true;
  39. } else if (!parent.tagName
  40. || parent.tagName.toUpperCase() == "HTML") {
  41. return false;
  42. }
  43. parent = parent.parentNode;
  44. }
  45. return false;
  46. }
  47. },
  48. getRegion : function(el) {
  49. return Ext.lib.Region.getRegion(el);
  50. },
  51. // ////////////////////////////////////////////////////////////////////////////////////
  52. // Use of jQuery.offset() removed to promote consistent behavior across
  53. // libs.
  54. // JVS 05/23/07
  55. // ////////////////////////////////////////////////////////////////////////////////////
  56. getY : function(el) {
  57. return this.getXY(el)[1];
  58. },
  59. getX : function(el) {
  60. return this.getXY(el)[0];
  61. },
  62. getXY : function(el) {
  63. var p, pe, b, scroll, bd = (document.body || document.documentElement);
  64. el = Ext.getDom(el);
  65. if (el == bd) {
  66. return [0, 0];
  67. }
  68. if (el.getBoundingClientRect) {
  69. b = el.getBoundingClientRect();
  70. scroll = fly(document).getScroll();
  71. return [b.left + scroll.left, b.top + scroll.top];
  72. }
  73. var x = 0, y = 0;
  74. p = el;
  75. var hasAbsolute = fly(el).getStyle("position") == "absolute";
  76. while (p) {
  77. x += p.offsetLeft;
  78. y += p.offsetTop;
  79. if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
  80. hasAbsolute = true;
  81. }
  82. if (Ext.isGecko) {
  83. pe = fly(p);
  84. var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
  85. var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
  86. x += bl;
  87. y += bt;
  88. if (p != el && pe.getStyle('overflow') != 'visible') {
  89. x += bl;
  90. y += bt;
  91. }
  92. }
  93. p = p.offsetParent;
  94. }
  95. if (Ext.isSafari && hasAbsolute) {
  96. x -= bd.offsetLeft;
  97. y -= bd.offsetTop;
  98. }
  99. if (Ext.isGecko && !hasAbsolute) {
  100. var dbd = fly(bd);
  101. x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
  102. y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
  103. }
  104. p = el.parentNode;
  105. while (p && p != bd) {
  106. if (!Ext.isOpera
  107. || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
  108. x -= p.scrollLeft;
  109. y -= p.scrollTop;
  110. }
  111. p = p.parentNode;
  112. }
  113. return [x, y];
  114. },
  115. setXY : function(el, xy) {
  116. el = Ext.fly(el, '_setXY');
  117. el.position();
  118. var pts = el.translatePoints(xy);
  119. if (xy[0] !== false) {
  120. el.dom.style.left = pts.left + "px";
  121. }
  122. if (xy[1] !== false) {
  123. el.dom.style.top = pts.top + "px";
  124. }
  125. },
  126. setX : function(el, x) {
  127. this.setXY(el, [x, false]);
  128. },
  129. setY : function(el, y) {
  130. this.setXY(el, [false, y]);
  131. }
  132. };
  133. // all lib flyweight calls use their own flyweight to prevent collisions
  134. // with developer flyweights
  135. function fly(el) {
  136. if (!libFlyweight) {
  137. libFlyweight = new Ext.Element.Flyweight();
  138. }
  139. libFlyweight.dom = el;
  140. return libFlyweight;
  141. }
  142. Ext.lib.Event = {
  143. getPageX : function(e) {
  144. e = e.browserEvent || e;
  145. return e.pageX;
  146. },
  147. getPageY : function(e) {
  148. e = e.browserEvent || e;
  149. return e.pageY;
  150. },
  151. getXY : function(e) {
  152. e = e.browserEvent || e;
  153. return [e.pageX, e.pageY];
  154. },
  155. getTarget : function(e) {
  156. return e.target;
  157. },
  158. // all Ext events will go through event manager which provides scoping
  159. on : function(el, eventName, fn, scope, override) {
  160. jQuery(el).bind(eventName, fn);
  161. },
  162. un : function(el, eventName, fn) {
  163. jQuery(el).unbind(eventName, fn);
  164. },
  165. purgeElement : function(el) {
  166. jQuery(el).unbind();
  167. },
  168. preventDefault : function(e) {
  169. e = e.browserEvent || e;
  170. if (e.preventDefault) {
  171. e.preventDefault();
  172. } else {
  173. e.returnValue = false;
  174. }
  175. },
  176. stopPropagation : function(e) {
  177. e = e.browserEvent || e;
  178. if (e.stopPropagation) {
  179. e.stopPropagation();
  180. } else {
  181. e.cancelBubble = true;
  182. }
  183. },
  184. stopEvent : function(e) {
  185. this.preventDefault(e);
  186. this.stopPropagation(e);
  187. },
  188. onAvailable : function(id, fn, scope) {
  189. var start = allGetServerTime();
  190. var f = function() {
  191. if (start.getElapsed() > 10000) {
  192. clearInterval(iid);
  193. }
  194. var el = document.getElementById(id);
  195. if (el) {
  196. clearInterval(iid);
  197. fn.call(scope || window, el);
  198. }
  199. };
  200. var iid = setInterval(f, 50);
  201. },
  202. resolveTextNode : function(node) {
  203. if (node && 3 == node.nodeType) {
  204. return node.parentNode;
  205. } else {
  206. return node;
  207. }
  208. },
  209. getRelatedTarget : function(ev) {
  210. ev = ev.browserEvent || ev;
  211. var t = ev.relatedTarget;
  212. if (!t) {
  213. if (ev.type == "mouseout") {
  214. t = ev.toElement;
  215. } else if (ev.type == "mouseover") {
  216. t = ev.fromElement;
  217. }
  218. }
  219. return this.resolveTextNode(t);
  220. }
  221. };
  222. Ext.lib.Ajax = function() {
  223. var createComplete = function(cb) {
  224. return function(xhr, status) {
  225. if ((status == 'error' || status == 'timeout') && cb.failure) {
  226. cb.failure.call(cb.scope || window, {
  227. responseText : xhr.responseText,
  228. responseXML : xhr.responseXML,
  229. argument : cb.argument
  230. });
  231. } else if (cb.success) {
  232. cb.success.call(cb.scope || window, {
  233. responseText : xhr.responseText,
  234. responseXML : xhr.responseXML,
  235. argument : cb.argument
  236. });
  237. }
  238. };
  239. };
  240. return {
  241. request : function(method, uri, cb, data, options) {
  242. var o = {
  243. type : method,
  244. url : uri,
  245. data : data,
  246. timeout : cb.timeout,
  247. complete : createComplete(cb)
  248. };
  249. if (options) {
  250. if (options.xmlData) {
  251. o.data = options.xmlData;
  252. o.processData = false;
  253. o.type = 'POST';
  254. o.contentType = 'text/xml';
  255. } else if (options.jsonData) {
  256. o.data = typeof options.jsonData == 'object' ? Ext
  257. .encode(options.jsonData) : options.jsonData;
  258. o.processData = false;
  259. o.type = 'POST';
  260. o.contentType = 'text/javascript';
  261. }
  262. if (options.headers) {
  263. o.beforeSend = function(xhr) {
  264. var hs = options.headers;
  265. for (var h in hs) {
  266. if (hs.hasOwnProperty(h)) {
  267. xhr.setRequestHeader(h, hs[h]);
  268. }
  269. }
  270. }
  271. }
  272. }
  273. jQuery.ajax(o);
  274. },
  275. formRequest : function(form, uri, cb, data, isUpload, sslUri) {
  276. jQuery.ajax({
  277. type : Ext.getDom(form).method || 'POST',
  278. url : uri,
  279. data : jQuery(form).formSerialize()
  280. + (data ? '&' + data : ''),
  281. timeout : cb.timeout,
  282. complete : createComplete(cb)
  283. });
  284. },
  285. isCallInProgress : function(trans) {
  286. return false;
  287. },
  288. abort : function(trans) {
  289. return false;
  290. },
  291. serializeForm : function(form) {
  292. return jQuery(form.dom || form).formSerialize();
  293. }
  294. };
  295. }();
  296. Ext.lib.Anim = function() {
  297. var createAnim = function(cb, scope) {
  298. var animated = true;
  299. return {
  300. stop : function(skipToLast) {
  301. // do nothing
  302. },
  303. isAnimated : function() {
  304. return animated;
  305. },
  306. proxyCallback : function() {
  307. animated = false;
  308. Ext.callback(cb, scope);
  309. }
  310. };
  311. };
  312. return {
  313. scroll : function(el, args, duration, easing, cb, scope) {
  314. // scroll anim not supported so just scroll immediately
  315. var anim = createAnim(cb, scope);
  316. el = Ext.getDom(el);
  317. if (typeof args.scroll.to[0] == 'number') {
  318. el.scrollLeft = args.scroll.to[0];
  319. }
  320. if (typeof args.scroll.to[1] == 'number') {
  321. el.scrollTop = args.scroll.to[1];
  322. }
  323. anim.proxyCallback();
  324. return anim;
  325. },
  326. motion : function(el, args, duration, easing, cb, scope) {
  327. return this.run(el, args, duration, easing, cb, scope);
  328. },
  329. color : function(el, args, duration, easing, cb, scope) {
  330. // color anim not supported, so execute callback immediately
  331. var anim = createAnim(cb, scope);
  332. anim.proxyCallback();
  333. return anim;
  334. },
  335. run : function(el, args, duration, easing, cb, scope, type) {
  336. var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun');
  337. var o = {};
  338. for (var k in args) {
  339. if (args[k].from) {
  340. if (k != 'points') {
  341. e.setStyle(k, args[k].from);
  342. }
  343. }
  344. switch (k) { // jquery doesn't support, so convert
  345. case 'points' :
  346. var by, pts;
  347. e.position();
  348. if (by = args.points.by) {
  349. var xy = e.getXY();
  350. pts = e.translatePoints([xy[0] + by[0],
  351. xy[1] + by[1]]);
  352. } else {
  353. pts = e.translatePoints(args.points.to);
  354. }
  355. o.left = pts.left;
  356. o.top = pts.top;
  357. if (!parseInt(e.getStyle('left'), 10)) { // auto
  358. // bug
  359. e.setLeft(0);
  360. }
  361. if (!parseInt(e.getStyle('top'), 10)) {
  362. e.setTop(0);
  363. }
  364. if (args.points.from) {
  365. e.setXY(args.points.from);
  366. }
  367. break;
  368. case 'width' :
  369. o.width = args.width.to;
  370. break;
  371. case 'height' :
  372. o.height = args.height.to;
  373. break;
  374. case 'opacity' :
  375. o.opacity = args.opacity.to;
  376. break;
  377. case 'left' :
  378. o.left = args.left.to;
  379. break;
  380. case 'top' :
  381. o.top = args.top.to;
  382. break;
  383. default :
  384. o[k] = args[k].to;
  385. break;
  386. }
  387. }
  388. // TODO: find out about easing plug in?
  389. jQuery(el).animate(o, duration * 1000, undefined,
  390. anim.proxyCallback);
  391. return anim;
  392. }
  393. };
  394. }();
  395. Ext.lib.Region = function(t, r, b, l) {
  396. this.top = t;
  397. this[1] = t;
  398. this.right = r;
  399. this.bottom = b;
  400. this.left = l;
  401. this[0] = l;
  402. };
  403. Ext.lib.Region.prototype = {
  404. contains : function(region) {
  405. return (region.left >= this.left && region.right <= this.right
  406. && region.top >= this.top && region.bottom <= this.bottom);
  407. },
  408. getArea : function() {
  409. return ((this.bottom - this.top) * (this.right - this.left));
  410. },
  411. intersect : function(region) {
  412. var t = Math.max(this.top, region.top);
  413. var r = Math.min(this.right, region.right);
  414. var b = Math.min(this.bottom, region.bottom);
  415. var l = Math.max(this.left, region.left);
  416. if (b >= t && r >= l) {
  417. return new Ext.lib.Region(t, r, b, l);
  418. } else {
  419. return null;
  420. }
  421. },
  422. union : function(region) {
  423. var t = Math.min(this.top, region.top);
  424. var r = Math.max(this.right, region.right);
  425. var b = Math.max(this.bottom, region.bottom);
  426. var l = Math.min(this.left, region.left);
  427. return new Ext.lib.Region(t, r, b, l);
  428. },
  429. constrainTo : function(r) {
  430. this.top = this.top.constrain(r.top, r.bottom);
  431. this.bottom = this.bottom.constrain(r.top, r.bottom);
  432. this.left = this.left.constrain(r.left, r.right);
  433. this.right = this.right.constrain(r.left, r.right);
  434. return this;
  435. },
  436. adjust : function(t, l, b, r) {
  437. this.top += t;
  438. this.left += l;
  439. this.right += r;
  440. this.bottom += b;
  441. return this;
  442. }
  443. };
  444. Ext.lib.Region.getRegion = function(el) {
  445. var p = Ext.lib.Dom.getXY(el);
  446. var t = p[1];
  447. var r = p[0] + el.offsetWidth;
  448. var b = p[1] + el.offsetHeight;
  449. var l = p[0];
  450. return new Ext.lib.Region(t, r, b, l);
  451. };
  452. Ext.lib.Point = function(x, y) {
  453. if (x instanceof Array) {
  454. y = x[1];
  455. x = x[0];
  456. }
  457. this.x = this.right = this.left = this[0] = x;
  458. this.y = this.top = this.bottom = this[1] = y;
  459. };
  460. Ext.lib.Point.prototype = new Ext.lib.Region();
  461. // prevent IE leaks
  462. if (Ext.isIE) {
  463. function fnCleanUp() {
  464. var p = Function.prototype;
  465. delete p.createSequence;
  466. delete p.defer;
  467. delete p.createDelegate;
  468. delete p.createCallback;
  469. delete p.createInterceptor;
  470. window.detachEvent("onunload", fnCleanUp);
  471. }
  472. window.attachEvent("onunload", fnCleanUp);
  473. }
  474. })();