Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / yui-bridge.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 if(typeof YAHOO == "undefined"){
15     throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found.";
16 }
17
18 (function(){
19     var E = YAHOO.util.Event,
20         D = YAHOO.util.Dom,
21         CN = YAHOO.util.Connect,
22         ES = YAHOO.util.Easing,
23         A = YAHOO.util.Anim,
24         libFlyweight,
25         version = YAHOO.env.getVersion('yahoo').version.split('.'),
26         mouseEnterSupported = parseInt(version[0]) >= 3,
27         mouseCache = {},
28         elContains = function(parent, child){
29             if(parent && parent.firstChild){
30                 while(child){
31                     if(child === parent){
32                         return true;
33                     }
34                     child = child.parentNode;
35                     if(child && (child.nodeType != 1)){
36                         child = null;
37                     }
38                 }
39             }
40             return false;
41         }, checkRelatedTarget = function(e){
42             return !elContains(e.currentTarget, Ext.lib.Event.getRelatedTarget(e));
43         };
44
45 Ext.lib.Dom = {
46     getViewWidth : function(full){
47         return full ? D.getDocumentWidth() : D.getViewportWidth();
48     },
49
50     getViewHeight : function(full){
51         return full ? D.getDocumentHeight() : D.getViewportHeight();
52     },
53
54     isAncestor : function(haystack, needle){
55         return D.isAncestor(haystack, needle);
56     },
57
58     getRegion : function(el){
59         return D.getRegion(el);
60     },
61
62     getY : function(el){
63         return this.getXY(el)[1];
64     },
65
66     getX : function(el){
67         return this.getXY(el)[0];
68     },
69
70     // original version based on YahooUI getXY
71     // this version fixes several issues in Safari and FF
72     // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls
73     getXY : function(el){
74         var p, pe, b, scroll, bd = (document.body || document.documentElement);
75         el = Ext.getDom(el);
76
77         if(el == bd){
78             return [0, 0];
79         }
80
81         if (el.getBoundingClientRect) {
82             b = el.getBoundingClientRect();
83             scroll = fly(document).getScroll();
84             return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
85         }
86         var x = 0, y = 0;
87
88         p = el;
89
90         var hasAbsolute = fly(el).getStyle("position") == "absolute";
91
92         while (p) {
93
94             x += p.offsetLeft;
95             y += p.offsetTop;
96
97             if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
98                 hasAbsolute = true;
99             }
100
101             if (Ext.isGecko) {
102                 pe = fly(p);
103
104                 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
105                 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
106
107
108                 x += bl;
109                 y += bt;
110
111
112                 if (p != el && pe.getStyle('overflow') != 'visible') {
113                     x += bl;
114                     y += bt;
115                 }
116             }
117             p = p.offsetParent;
118         }
119
120         if (Ext.isSafari && hasAbsolute) {
121             x -= bd.offsetLeft;
122             y -= bd.offsetTop;
123         }
124
125         if (Ext.isGecko && !hasAbsolute) {
126             var dbd = fly(bd);
127             x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
128             y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
129         }
130
131         p = el.parentNode;
132         while (p && p != bd) {
133             if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
134                 x -= p.scrollLeft;
135                 y -= p.scrollTop;
136             }
137             p = p.parentNode;
138         }
139         return [x, y];
140     },
141
142     setXY : function(el, xy){
143         el = Ext.fly(el, '_setXY');
144         el.position();
145         var pts = el.translatePoints(xy);
146         if(xy[0] !== false){
147             el.dom.style.left = pts.left + "px";
148         }
149         if(xy[1] !== false){
150             el.dom.style.top = pts.top + "px";
151         }
152     },
153
154     setX : function(el, x){
155         this.setXY(el, [x, false]);
156     },
157
158     setY : function(el, y){
159         this.setXY(el, [false, y]);
160     }
161 };
162
163 Ext.lib.Event = {
164     getPageX : function(e){
165         return E.getPageX(e.browserEvent || e);
166     },
167
168     getPageY : function(e){
169         return E.getPageY(e.browserEvent || e);
170     },
171
172     getXY : function(e){
173         return E.getXY(e.browserEvent || e);
174     },
175
176     getTarget : function(e){
177         return E.getTarget(e.browserEvent || e);
178     },
179
180     getRelatedTarget : function(e){
181         return E.getRelatedTarget(e.browserEvent || e);
182     },
183
184     on : function(el, eventName, fn, scope, override){
185         if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
186             var item = mouseCache[el.id] || (mouseCache[el.id] = {});
187             item[eventName] = fn;
188             fn = fn.createInterceptor(checkRelatedTarget);
189             eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
190         }
191         E.on(el, eventName, fn, scope, override);
192     },
193
194     un : function(el, eventName, fn){
195         if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
196             var item = mouseCache[el.id], 
197                 ev = item && item[eventName];
198
199             if(ev){
200                 fn = ev.fn;
201                 delete item[eventName];
202                 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
203             }
204         }
205         E.removeListener(el, eventName, fn);;
206     },
207
208     purgeElement : function(el){
209         E.purgeElement(el);
210     },
211
212     preventDefault : function(e){
213         E.preventDefault(e.browserEvent || e);
214     },
215
216     stopPropagation : function(e){
217         E.stopPropagation(e.browserEvent || e);
218     },
219
220     stopEvent : function(e){
221         E.stopEvent(e.browserEvent || e);
222     },
223
224     onAvailable : function(el, fn, scope, override){
225         return E.onAvailable(el, fn, scope, override);
226     }
227 };
228
229 Ext.lib.Ajax = {
230     request : function(method, uri, cb, data, options){
231         if(options){
232             var hs = options.headers;
233             if(hs){
234                 for(var h in hs){
235                     if(hs.hasOwnProperty(h)){
236                         CN.initHeader(h, hs[h], false);
237                     }
238                 }
239             }
240             if(options.xmlData){
241                 if (!hs || !hs['Content-Type']){
242                     CN.initHeader('Content-Type', 'text/xml', false);
243                 }
244                 method = (method ? method : (options.method ? options.method : 'POST'));
245                 data = options.xmlData;
246             }else if(options.jsonData){
247                 if (!hs || !hs['Content-Type']){
248                     CN.initHeader('Content-Type', 'application/json', false);
249                 }
250                 method = (method ? method : (options.method ? options.method : 'POST'));
251                 data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
252             }
253         }
254         return CN.asyncRequest(method, uri, cb, data);
255     },
256
257     formRequest : function(form, uri, cb, data, isUpload, sslUri){
258         CN.setForm(form, isUpload, sslUri);
259         return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data);
260     },
261
262     isCallInProgress : function(trans){
263         return CN.isCallInProgress(trans);
264     },
265
266     abort : function(trans){
267         return CN.abort(trans);
268     },
269
270     serializeForm : function(form){
271         var d = CN.setForm(form.dom || form);
272         CN.resetFormState();
273         return d;
274     }
275 };
276
277 Ext.lib.Region = YAHOO.util.Region;
278 Ext.lib.Point = YAHOO.util.Point;
279
280
281 Ext.lib.Anim = {
282     scroll : function(el, args, duration, easing, cb, scope){
283         this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
284     },
285
286     motion : function(el, args, duration, easing, cb, scope){
287         this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
288     },
289
290     color : function(el, args, duration, easing, cb, scope){
291         this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim);
292     },
293
294     run : function(el, args, duration, easing, cb, scope, type){
295         type = type || YAHOO.util.Anim;
296         if(typeof easing == "string"){
297             easing = YAHOO.util.Easing[easing];
298         }
299         var anim = new type(el, args, duration, easing);
300         anim.animateX(function(){
301             Ext.callback(cb, scope);
302         });
303         return anim;
304     }
305 };
306
307 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
308 function fly(el){
309     if(!libFlyweight){
310         libFlyweight = new Ext.Element.Flyweight();
311     }
312     libFlyweight.dom = el;
313     return libFlyweight;
314 }
315
316 // prevent IE leaks
317 if(Ext.isIE) {
318     function fnCleanUp() {
319         var p = Function.prototype;
320         delete p.createSequence;
321         delete p.defer;
322         delete p.createDelegate;
323         delete p.createCallback;
324         delete p.createInterceptor;
325
326         window.detachEvent("onunload", fnCleanUp);
327     }
328     window.attachEvent("onunload", fnCleanUp);
329 }
330 // various overrides
331
332 // add ability for callbacks with animations
333 if(YAHOO.util.Anim){
334     YAHOO.util.Anim.prototype.animateX = function(callback, scope){
335         var f = function(){
336             this.onComplete.unsubscribe(f);
337             if(typeof callback == "function"){
338                 callback.call(scope || this, this);
339             }
340         };
341         this.onComplete.subscribe(f, this, true);
342         this.animate();
343     };
344 }
345
346 if(YAHOO.util.DragDrop && Ext.dd.DragDrop){
347     YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
348     YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
349 }
350
351 YAHOO.util.Dom.getXY = function(el) {
352     var f = function(el) {
353         return Ext.lib.Dom.getXY(el);
354     };
355     return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
356 };
357
358
359 // workaround for Safari anim duration speed problems
360 if(YAHOO.util.AnimMgr){
361     YAHOO.util.AnimMgr.fps = 1000;
362 }
363
364 YAHOO.util.Region.prototype.adjust = function(t, l, b, r){
365     this.top += t;
366     this.left += l;
367     this.right += r;
368     this.bottom += b;
369     return this;
370 };
371     
372 YAHOO.util.Region.prototype.constrainTo = function(r) {
373     this.top = this.top.constrain(r.top, r.bottom);
374     this.bottom = this.bottom.constrain(r.top, r.bottom);
375     this.left = this.left.constrain(r.left, r.right);
376     this.right = this.right.constrain(r.left, r.right);
377     return this;
378 };
379
380
381 })();</pre>
382 </body>
383 </html>