yui-bridge.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 YAHOO == "undefined") {
  7. throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found.";
  8. }
  9. (function() {
  10. var E = YAHOO.util.Event;
  11. var D = YAHOO.util.Dom;
  12. var CN = YAHOO.util.Connect;
  13. var ES = YAHOO.util.Easing;
  14. var A = YAHOO.util.Anim;
  15. var libFlyweight;
  16. Ext.lib.Dom = {
  17. getViewWidth : function(full) {
  18. return full ? D.getDocumentWidth() : D.getViewportWidth();
  19. },
  20. getViewHeight : function(full) {
  21. return full ? D.getDocumentHeight() : D.getViewportHeight();
  22. },
  23. isAncestor : function(haystack, needle) {
  24. return D.isAncestor(haystack, needle);
  25. },
  26. getRegion : function(el) {
  27. return D.getRegion(el);
  28. },
  29. getY : function(el) {
  30. return this.getXY(el)[1];
  31. },
  32. getX : function(el) {
  33. return this.getXY(el)[0];
  34. },
  35. // original version based on YahooUI getXY
  36. // this version fixes several issues in Safari and FF
  37. // and boosts performance by removing the batch overhead, repetitive dom
  38. // lookups and array index calls
  39. getXY : function(el) {
  40. var p, pe, b, scroll, bd = (document.body || document.documentElement);
  41. el = Ext.getDom(el);
  42. if (el == bd) {
  43. return [0, 0];
  44. }
  45. if (el.getBoundingClientRect) {
  46. b = el.getBoundingClientRect();
  47. scroll = fly(document).getScroll();
  48. return [b.left + scroll.left, b.top + scroll.top];
  49. }
  50. var x = 0, y = 0;
  51. p = el;
  52. var hasAbsolute = fly(el).getStyle("position") == "absolute";
  53. while (p) {
  54. x += p.offsetLeft;
  55. y += p.offsetTop;
  56. if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
  57. hasAbsolute = true;
  58. }
  59. if (Ext.isGecko) {
  60. pe = fly(p);
  61. var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
  62. var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
  63. x += bl;
  64. y += bt;
  65. if (p != el && pe.getStyle('overflow') != 'visible') {
  66. x += bl;
  67. y += bt;
  68. }
  69. }
  70. p = p.offsetParent;
  71. }
  72. if (Ext.isSafari && hasAbsolute) {
  73. x -= bd.offsetLeft;
  74. y -= bd.offsetTop;
  75. }
  76. if (Ext.isGecko && !hasAbsolute) {
  77. var dbd = fly(bd);
  78. x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
  79. y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
  80. }
  81. p = el.parentNode;
  82. while (p && p != bd) {
  83. if (!Ext.isOpera
  84. || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
  85. x -= p.scrollLeft;
  86. y -= p.scrollTop;
  87. }
  88. p = p.parentNode;
  89. }
  90. return [x, y];
  91. },
  92. setXY : function(el, xy) {
  93. el = Ext.fly(el, '_setXY');
  94. el.position();
  95. var pts = el.translatePoints(xy);
  96. if (xy[0] !== false) {
  97. el.dom.style.left = pts.left + "px";
  98. }
  99. if (xy[1] !== false) {
  100. el.dom.style.top = pts.top + "px";
  101. }
  102. },
  103. setX : function(el, x) {
  104. this.setXY(el, [x, false]);
  105. },
  106. setY : function(el, y) {
  107. this.setXY(el, [false, y]);
  108. }
  109. };
  110. Ext.lib.Event = {
  111. getPageX : function(e) {
  112. return E.getPageX(e.browserEvent || e);
  113. },
  114. getPageY : function(e) {
  115. return E.getPageY(e.browserEvent || e);
  116. },
  117. getXY : function(e) {
  118. return E.getXY(e.browserEvent || e);
  119. },
  120. getTarget : function(e) {
  121. return E.getTarget(e.browserEvent || e);
  122. },
  123. getRelatedTarget : function(e) {
  124. return E.getRelatedTarget(e.browserEvent || e);
  125. },
  126. on : function(el, eventName, fn, scope, override) {
  127. E.on(el, eventName, fn, scope, override);
  128. },
  129. un : function(el, eventName, fn) {
  130. E.removeListener(el, eventName, fn);
  131. },
  132. purgeElement : function(el) {
  133. E.purgeElement(el);
  134. },
  135. preventDefault : function(e) {
  136. E.preventDefault(e.browserEvent || e);
  137. },
  138. stopPropagation : function(e) {
  139. E.stopPropagation(e.browserEvent || e);
  140. },
  141. stopEvent : function(e) {
  142. E.stopEvent(e.browserEvent || e);
  143. },
  144. onAvailable : function(el, fn, scope, override) {
  145. return E.onAvailable(el, fn, scope, override);
  146. }
  147. };
  148. Ext.lib.Ajax = {
  149. request : function(method, uri, cb, data, options) {
  150. if (options) {
  151. var hs = options.headers;
  152. if (hs) {
  153. for (var h in hs) {
  154. if (hs.hasOwnProperty(h)) {
  155. CN.initHeader(h, hs[h], false);
  156. }
  157. }
  158. }
  159. if (options.xmlData) {
  160. CN.initHeader('Content-Type', 'text/xml', false);
  161. method = 'POST';
  162. data = options.xmlData;
  163. } else if (options.jsonData) {
  164. CN.initHeader('Content-Type', 'text/javascript', false);
  165. method = 'POST';
  166. data = typeof options.jsonData == 'object' ? Ext
  167. .encode(options.jsonData) : options.jsonData;
  168. }
  169. }
  170. return CN.asyncRequest(method, uri, cb, data);
  171. },
  172. formRequest : function(form, uri, cb, data, isUpload, sslUri) {
  173. CN.setForm(form, isUpload, sslUri);
  174. return CN.asyncRequest(Ext.getDom(form).method || 'POST', uri, cb,
  175. data);
  176. },
  177. isCallInProgress : function(trans) {
  178. return CN.isCallInProgress(trans);
  179. },
  180. abort : function(trans) {
  181. return CN.abort(trans);
  182. },
  183. serializeForm : function(form) {
  184. var d = CN.setForm(form.dom || form);
  185. CN.resetFormState();
  186. return d;
  187. }
  188. };
  189. Ext.lib.Region = YAHOO.util.Region;
  190. Ext.lib.Point = YAHOO.util.Point;
  191. Ext.lib.Anim = {
  192. scroll : function(el, args, duration, easing, cb, scope) {
  193. this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
  194. },
  195. motion : function(el, args, duration, easing, cb, scope) {
  196. this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
  197. },
  198. color : function(el, args, duration, easing, cb, scope) {
  199. this.run(el, args, duration, easing, cb, scope,
  200. YAHOO.util.ColorAnim);
  201. },
  202. run : function(el, args, duration, easing, cb, scope, type) {
  203. type = type || YAHOO.util.Anim;
  204. if (typeof easing == "string") {
  205. easing = YAHOO.util.Easing[easing];
  206. }
  207. var anim = new type(el, args, duration, easing);
  208. anim.animateX(function() {
  209. Ext.callback(cb, scope);
  210. });
  211. return anim;
  212. }
  213. };
  214. // all lib flyweight calls use their own flyweight to prevent collisions
  215. // with developer flyweights
  216. function fly(el) {
  217. if (!libFlyweight) {
  218. libFlyweight = new Ext.Element.Flyweight();
  219. }
  220. libFlyweight.dom = el;
  221. return libFlyweight;
  222. }
  223. // prevent IE leaks
  224. if (Ext.isIE) {
  225. function fnCleanUp() {
  226. var p = Function.prototype;
  227. delete p.createSequence;
  228. delete p.defer;
  229. delete p.createDelegate;
  230. delete p.createCallback;
  231. delete p.createInterceptor;
  232. window.detachEvent("onunload", fnCleanUp);
  233. }
  234. window.attachEvent("onunload", fnCleanUp);
  235. }
  236. // various overrides
  237. // add ability for callbacks with animations
  238. if (YAHOO.util.Anim) {
  239. YAHOO.util.Anim.prototype.animateX = function(callback, scope) {
  240. var f = function() {
  241. this.onComplete.unsubscribe(f);
  242. if (typeof callback == "function") {
  243. callback.call(scope || this, this);
  244. }
  245. };
  246. this.onComplete.subscribe(f, this, true);
  247. this.animate();
  248. };
  249. }
  250. if (YAHOO.util.DragDrop && Ext.dd.DragDrop) {
  251. YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
  252. YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
  253. }
  254. YAHOO.util.Dom.getXY = function(el) {
  255. var f = function(el) {
  256. return Ext.lib.Dom.getXY(el);
  257. };
  258. return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
  259. };
  260. // workaround for Safari anim duration speed problems
  261. if (YAHOO.util.AnimMgr) {
  262. YAHOO.util.AnimMgr.fps = 1000;
  263. }
  264. YAHOO.util.Region.prototype.adjust = function(t, l, b, r) {
  265. this.top += t;
  266. this.left += l;
  267. this.right += r;
  268. this.bottom += b;
  269. return this;
  270. };
  271. YAHOO.util.Region.prototype.constrainTo = function(r) {
  272. this.top = this.top.constrain(r.top, r.bottom);
  273. this.bottom = this.bottom.constrain(r.top, r.bottom);
  274. this.left = this.left.constrain(r.left, r.right);
  275. this.right = this.right.constrain(r.left, r.right);
  276. return this;
  277. };
  278. })();