3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 if(typeof YAHOO == "undefined"){
8 throw "Unable to load Ext, core YUI utilities (yahoo, dom, event) not found.";
12 var E = YAHOO.util.Event,
14 CN = YAHOO.util.Connect,
15 ES = YAHOO.util.Easing,
18 version = YAHOO.env.getVersion('yahoo').version.split('.'),
19 mouseEnterSupported = parseInt(version[0]) >= 3,
21 elContains = function(parent, child){
22 if(parent && parent.firstChild){
27 child = child.parentNode;
28 if(child && (child.nodeType != 1)){
34 }, checkRelatedTarget = function(e){
35 return !elContains(e.currentTarget, Ext.lib.Event.getRelatedTarget(e));
39 getViewWidth : function(full){
40 return full ? D.getDocumentWidth() : D.getViewportWidth();
43 getViewHeight : function(full){
44 return full ? D.getDocumentHeight() : D.getViewportHeight();
47 isAncestor : function(haystack, needle){
48 return D.isAncestor(haystack, needle);
51 getRegion : function(el){
52 return D.getRegion(el);
56 return this.getXY(el)[1];
60 return this.getXY(el)[0];
63 // original version based on YahooUI getXY
64 // this version fixes several issues in Safari and FF
65 // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls
67 var p, pe, b, scroll, bd = (document.body || document.documentElement);
74 if (el.getBoundingClientRect) {
75 b = el.getBoundingClientRect();
76 scroll = fly(document).getScroll();
77 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
83 var hasAbsolute = fly(el).getStyle("position") == "absolute";
90 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
97 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
98 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
105 if (p != el && pe.getStyle('overflow') != 'visible') {
113 if (Ext.isSafari && hasAbsolute) {
118 if (Ext.isGecko && !hasAbsolute) {
120 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
121 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
125 while (p && p != bd) {
126 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
135 setXY : function(el, xy){
136 el = Ext.fly(el, '_setXY');
138 var pts = el.translatePoints(xy);
140 el.dom.style.left = pts.left + "px";
143 el.dom.style.top = pts.top + "px";
147 setX : function(el, x){
148 this.setXY(el, [x, false]);
151 setY : function(el, y){
152 this.setXY(el, [false, y]);
157 getPageX : function(e){
158 return E.getPageX(e.browserEvent || e);
161 getPageY : function(e){
162 return E.getPageY(e.browserEvent || e);
166 return E.getXY(e.browserEvent || e);
169 getTarget : function(e){
170 return E.getTarget(e.browserEvent || e);
173 getRelatedTarget : function(e){
174 return E.getRelatedTarget(e.browserEvent || e);
177 on : function(el, eventName, fn, scope, override){
178 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
179 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
180 item[eventName] = fn;
181 fn = fn.createInterceptor(checkRelatedTarget);
182 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
184 E.on(el, eventName, fn, scope, override);
187 un : function(el, eventName, fn){
188 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
189 var item = mouseCache[el.id],
190 ev = item && item[eventName];
194 delete item[eventName];
195 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
198 E.removeListener(el, eventName, fn);;
201 purgeElement : function(el){
205 preventDefault : function(e){
206 E.preventDefault(e.browserEvent || e);
209 stopPropagation : function(e){
210 E.stopPropagation(e.browserEvent || e);
213 stopEvent : function(e){
214 E.stopEvent(e.browserEvent || e);
217 onAvailable : function(el, fn, scope, override){
218 return E.onAvailable(el, fn, scope, override);
223 request : function(method, uri, cb, data, options){
225 var hs = options.headers;
228 if(hs.hasOwnProperty(h)){
229 CN.initHeader(h, hs[h], false);
234 if (!hs || !hs['Content-Type']){
235 CN.initHeader('Content-Type', 'text/xml', false);
237 method = (method ? method : (options.method ? options.method : 'POST'));
238 data = options.xmlData;
239 }else if(options.jsonData){
240 if (!hs || !hs['Content-Type']){
241 CN.initHeader('Content-Type', 'application/json', false);
243 method = (method ? method : (options.method ? options.method : 'POST'));
244 data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
247 return CN.asyncRequest(method, uri, cb, data);
250 formRequest : function(form, uri, cb, data, isUpload, sslUri){
251 CN.setForm(form, isUpload, sslUri);
252 return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data);
255 isCallInProgress : function(trans){
256 return CN.isCallInProgress(trans);
259 abort : function(trans){
260 return CN.abort(trans);
263 serializeForm : function(form){
264 var d = CN.setForm(form.dom || form);
270 Ext.lib.Region = YAHOO.util.Region;
271 Ext.lib.Point = YAHOO.util.Point;
275 scroll : function(el, args, duration, easing, cb, scope){
276 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
279 motion : function(el, args, duration, easing, cb, scope){
280 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
283 color : function(el, args, duration, easing, cb, scope){
284 this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim);
287 run : function(el, args, duration, easing, cb, scope, type){
288 type = type || YAHOO.util.Anim;
289 if(typeof easing == "string"){
290 easing = YAHOO.util.Easing[easing];
292 var anim = new type(el, args, duration, easing);
293 anim.animateX(function(){
294 Ext.callback(cb, scope);
300 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
303 libFlyweight = new Ext.Element.Flyweight();
305 libFlyweight.dom = el;
311 function fnCleanUp() {
312 var p = Function.prototype;
313 delete p.createSequence;
315 delete p.createDelegate;
316 delete p.createCallback;
317 delete p.createInterceptor;
319 window.detachEvent("onunload", fnCleanUp);
321 window.attachEvent("onunload", fnCleanUp);
325 // add ability for callbacks with animations
327 YAHOO.util.Anim.prototype.animateX = function(callback, scope){
329 this.onComplete.unsubscribe(f);
330 if(typeof callback == "function"){
331 callback.call(scope || this, this);
334 this.onComplete.subscribe(f, this, true);
339 if(YAHOO.util.DragDrop && Ext.dd.DragDrop){
340 YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
341 YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
344 YAHOO.util.Dom.getXY = function(el) {
345 var f = function(el) {
346 return Ext.lib.Dom.getXY(el);
348 return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
352 // workaround for Safari anim duration speed problems
353 if(YAHOO.util.AnimMgr){
354 YAHOO.util.AnimMgr.fps = 1000;
357 YAHOO.util.Region.prototype.adjust = function(t, l, b, r){
365 YAHOO.util.Region.prototype.constrainTo = function(r) {
366 this.top = this.top.constrain(r.top, r.bottom);
367 this.bottom = this.bottom.constrain(r.top, r.bottom);
368 this.left = this.left.constrain(r.left, r.right);
369 this.right = this.right.constrain(r.left, r.right);