3 * Copyright(c) 2006-2009 Ext JS, LLC
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 isXUL = Ext.isGecko ? function(node){
22 return Object.prototype.toString.call(node) == '[object XULElement]';
24 }, isTextNode = Ext.isGecko ? function(node){
26 return node.nodeType == 3;
31 return node.nodeType == 3;
32 }, elContains = function(parent, child){
33 if(parent && parent.firstChild){
39 child = child.parentNode;
43 if(child && (child.nodeType != 1)){
49 }, checkRelatedTarget = function(e){
50 var related = Ext.lib.Event.getRelatedTarget(e);
51 return !(isXUL(related) || elContains(e.currentTarget, related));
55 getViewWidth : function(full){
56 return full ? D.getDocumentWidth() : D.getViewportWidth();
59 getViewHeight : function(full){
60 return full ? D.getDocumentHeight() : D.getViewportHeight();
63 isAncestor : function(haystack, needle){
64 return D.isAncestor(haystack, needle);
67 getRegion : function(el){
68 return D.getRegion(el);
72 return this.getXY(el)[1];
76 return this.getXY(el)[0];
79 // original version based on YahooUI getXY
80 // this version fixes several issues in Safari and FF
81 // and boosts performance by removing the batch overhead, repetitive dom lookups and array index calls
83 var p, pe, b, scroll, bd = (document.body || document.documentElement);
90 if (el.getBoundingClientRect) {
91 b = el.getBoundingClientRect();
92 scroll = fly(document).getScroll();
93 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
99 var hasAbsolute = fly(el).getStyle("position") == "absolute";
106 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
113 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
114 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
121 if (p != el && pe.getStyle('overflow') != 'visible') {
129 if (Ext.isSafari && hasAbsolute) {
134 if (Ext.isGecko && !hasAbsolute) {
136 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
137 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
141 while (p && p != bd) {
142 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
151 setXY : function(el, xy){
152 el = Ext.fly(el, '_setXY');
154 var pts = el.translatePoints(xy);
156 el.dom.style.left = pts.left + "px";
159 el.dom.style.top = pts.top + "px";
163 setX : function(el, x){
164 this.setXY(el, [x, false]);
167 setY : function(el, y){
168 this.setXY(el, [false, y]);
173 getPageX : function(e){
174 return E.getPageX(e.browserEvent || e);
177 getPageY : function(e){
178 return E.getPageY(e.browserEvent || e);
182 return E.getXY(e.browserEvent || e);
185 getTarget : function(e){
186 return E.getTarget(e.browserEvent || e);
189 getRelatedTarget : function(e){
190 return E.getRelatedTarget(e.browserEvent || e);
193 on : function(el, eventName, fn, scope, override){
194 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
195 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
196 item[eventName] = fn;
197 fn = fn.createInterceptor(checkRelatedTarget);
198 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
200 E.on(el, eventName, fn, scope, override);
203 un : function(el, eventName, fn){
204 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
205 var item = mouseCache[el.id],
206 ev = item && item[eventName];
210 delete item[eventName];
211 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
214 E.removeListener(el, eventName, fn);;
217 purgeElement : function(el){
221 preventDefault : function(e){
222 E.preventDefault(e.browserEvent || e);
225 stopPropagation : function(e){
226 E.stopPropagation(e.browserEvent || e);
229 stopEvent : function(e){
230 E.stopEvent(e.browserEvent || e);
233 onAvailable : function(el, fn, scope, override){
234 return E.onAvailable(el, fn, scope, override);
239 request : function(method, uri, cb, data, options){
241 var hs = options.headers;
244 if(hs.hasOwnProperty(h)){
245 CN.initHeader(h, hs[h], false);
250 if (!hs || !hs['Content-Type']){
251 CN.initHeader('Content-Type', 'text/xml', false);
253 method = (method ? method : (options.method ? options.method : 'POST'));
254 data = options.xmlData;
255 }else if(options.jsonData){
256 if (!hs || !hs['Content-Type']){
257 CN.initHeader('Content-Type', 'application/json', false);
259 method = (method ? method : (options.method ? options.method : 'POST'));
260 data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
263 return CN.asyncRequest(method, uri, cb, data);
266 formRequest : function(form, uri, cb, data, isUpload, sslUri){
267 CN.setForm(form, isUpload, sslUri);
268 return CN.asyncRequest(Ext.getDom(form).method ||'POST', uri, cb, data);
271 isCallInProgress : function(trans){
272 return CN.isCallInProgress(trans);
275 abort : function(trans){
276 return CN.abort(trans);
279 serializeForm : function(form){
280 var d = CN.setForm(form.dom || form);
286 Ext.lib.Region = YAHOO.util.Region;
287 Ext.lib.Point = YAHOO.util.Point;
291 scroll : function(el, args, duration, easing, cb, scope){
292 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Scroll);
295 motion : function(el, args, duration, easing, cb, scope){
296 this.run(el, args, duration, easing, cb, scope, YAHOO.util.Motion);
299 color : function(el, args, duration, easing, cb, scope){
300 this.run(el, args, duration, easing, cb, scope, YAHOO.util.ColorAnim);
303 run : function(el, args, duration, easing, cb, scope, type){
304 type = type || YAHOO.util.Anim;
305 if(typeof easing == "string"){
306 easing = YAHOO.util.Easing[easing];
308 var anim = new type(el, args, duration, easing);
309 anim.animateX(function(){
310 Ext.callback(cb, scope);
316 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
319 libFlyweight = new Ext.Element.Flyweight();
321 libFlyweight.dom = el;
327 function fnCleanUp() {
328 var p = Function.prototype;
329 delete p.createSequence;
331 delete p.createDelegate;
332 delete p.createCallback;
333 delete p.createInterceptor;
335 window.detachEvent("onunload", fnCleanUp);
337 window.attachEvent("onunload", fnCleanUp);
341 // add ability for callbacks with animations
343 YAHOO.util.Anim.prototype.animateX = function(callback, scope){
345 this.onComplete.unsubscribe(f);
346 if(typeof callback == "function"){
347 callback.call(scope || this, this);
350 this.onComplete.subscribe(f, this, true);
355 if(YAHOO.util.DragDrop && Ext.dd.DragDrop){
356 YAHOO.util.DragDrop.defaultPadding = Ext.dd.DragDrop.defaultPadding;
357 YAHOO.util.DragDrop.constrainTo = Ext.dd.DragDrop.constrainTo;
360 YAHOO.util.Dom.getXY = function(el) {
361 var f = function(el) {
362 return Ext.lib.Dom.getXY(el);
364 return YAHOO.util.Dom.batch(el, f, YAHOO.util.Dom, true);
368 // workaround for Safari anim duration speed problems
369 if(YAHOO.util.AnimMgr){
370 YAHOO.util.AnimMgr.fps = 1000;
373 YAHOO.util.Region.prototype.adjust = function(t, l, b, r){
381 YAHOO.util.Region.prototype.constrainTo = function(r) {
382 this.top = this.top.constrain(r.top, r.bottom);
383 this.bottom = this.bottom.constrain(r.top, r.bottom);
384 this.left = this.left.constrain(r.left, r.right);
385 this.right = this.right.constrain(r.left, r.right);