3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 if(typeof jQuery == "undefined"){
8 throw "Unable to load Ext, jQuery not found.";
15 getViewWidth : function(full){
16 // jQuery doesn't report full window size on document query, so max both
17 return full ? Math.max(jQuery(document).width(),jQuery(window).width()) : jQuery(window).width();
20 getViewHeight : function(full){
21 // jQuery doesn't report full window size on document query, so max both
22 return full ? Math.max(jQuery(document).height(),jQuery(window).height()) : jQuery(window).height();
25 isAncestor : function(p, c){
28 if (!p || !c) {return false;}
30 if(p.contains && !Ext.isSafari) {
32 }else if(p.compareDocumentPosition) {
33 return !!(p.compareDocumentPosition(c) & 16);
35 var parent = c.parentNode;
40 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
43 parent = parent.parentNode;
49 getRegion : function(el){
50 return Ext.lib.Region.getRegion(el);
53 //////////////////////////////////////////////////////////////////////////////////////
54 // Use of jQuery.offset() removed to promote consistent behavior across libs.
56 //////////////////////////////////////////////////////////////////////////////////////
59 return this.getXY(el)[1];
63 return this.getXY(el)[0];
66 getXY : function(el) {
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]);
156 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
159 libFlyweight = new Ext.Element.Flyweight();
161 libFlyweight.dom = el;
165 getPageX : function(e){
166 e = e.browserEvent || e;
170 getPageY : function(e){
171 e = e.browserEvent || e;
176 e = e.browserEvent || e;
177 return [e.pageX, e.pageY];
180 getTarget : function(e){
184 // all Ext events will go through event manager which provides scoping
185 on : function(el, eventName, fn, scope, override){
186 jQuery(el).bind(eventName, fn);
189 un : function(el, eventName, fn){
190 jQuery(el).unbind(eventName, fn);
193 purgeElement : function(el){
197 preventDefault : function(e){
198 e = e.browserEvent || e;
199 if(e.preventDefault){
202 e.returnValue = false;
206 stopPropagation : function(e){
207 e = e.browserEvent || e;
208 if(e.stopPropagation){
211 e.cancelBubble = true;
215 stopEvent : function(e){
216 this.preventDefault(e);
217 this.stopPropagation(e);
220 onAvailable : function(id, fn, scope){
221 var start = new Date();
223 if(start.getElapsed() > 10000){
226 var el = document.getElementById(id);
229 fn.call(scope||window, el);
232 var iid = setInterval(f, 50);
235 resolveTextNode: function(node) {
236 if (node && 3 == node.nodeType) {
237 return node.parentNode;
243 getRelatedTarget: function(ev) {
244 ev = ev.browserEvent || ev;
245 var t = ev.relatedTarget;
247 if (ev.type == "mouseout") {
249 } else if (ev.type == "mouseover") {
254 return this.resolveTextNode(t);
258 Ext.lib.Ajax = function(){
259 var createComplete = function(cb){
260 return function(xhr, status){
261 if((status == 'error' || status == 'timeout') && cb.failure){
262 cb.failure.call(cb.scope||window, {
263 responseText: xhr.responseText,
264 responseXML : xhr.responseXML,
265 argument: cb.argument
267 }else if(cb.success){
268 cb.success.call(cb.scope||window, {
269 responseText: xhr.responseText,
270 responseXML : xhr.responseXML,
271 argument: cb.argument
277 request : function(method, uri, cb, data, options){
283 complete: createComplete(cb)
287 var hs = options.headers;
289 o.data = options.xmlData;
290 o.processData = false;
291 o.type = (method ? method : (options.method ? options.method : 'POST'));
292 if (!hs || !hs['Content-Type']){
293 o.contentType = 'text/xml';
295 }else if(options.jsonData){
296 o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
297 o.processData = false;
298 o.type = (method ? method : (options.method ? options.method : 'POST'));
299 if (!hs || !hs['Content-Type']){
300 o.contentType = 'application/json';
304 o.beforeSend = function(xhr){
306 if(hs.hasOwnProperty(h)){
307 xhr.setRequestHeader(h, hs[h]);
316 formRequest : function(form, uri, cb, data, isUpload, sslUri){
318 type: Ext.getDom(form).method ||'POST',
320 data: jQuery(form).serialize()+(data?'&'+data:''),
322 complete: createComplete(cb)
326 isCallInProgress : function(trans){
330 abort : function(trans){
334 serializeForm : function(form){
335 return jQuery(form.dom||form).serialize();
340 Ext.lib.Anim = function(){
341 var createAnim = function(cb, scope){
344 stop : function(skipToLast){
348 isAnimated : function(){
352 proxyCallback : function(){
354 Ext.callback(cb, scope);
359 scroll : function(el, args, duration, easing, cb, scope){
360 // scroll anim not supported so just scroll immediately
361 var anim = createAnim(cb, scope);
363 if(typeof args.scroll.to[0] == 'number'){
364 el.scrollLeft = args.scroll.to[0];
366 if(typeof args.scroll.to[1] == 'number'){
367 el.scrollTop = args.scroll.to[1];
369 anim.proxyCallback();
373 motion : function(el, args, duration, easing, cb, scope){
374 return this.run(el, args, duration, easing, cb, scope);
377 color : function(el, args, duration, easing, cb, scope){
378 // color anim not supported, so execute callback immediately
379 var anim = createAnim(cb, scope);
380 anim.proxyCallback();
384 run : function(el, args, duration, easing, cb, scope, type){
385 var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun');
388 switch(k){ // jquery doesn't support, so convert
392 if(by = args.points.by){
394 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
396 pts = e.translatePoints(args.points.to);
400 if(!parseInt(e.getStyle('left'), 10)){ // auto bug
403 if(!parseInt(e.getStyle('top'), 10)){
406 if(args.points.from){
407 e.setXY(args.points.from);
411 o.width = args.width.to;
413 e.setWidth(args.width.from);
416 o.height = args.height.to;
417 if (args.height.from)
418 e.setHeight(args.height.from);
421 o.opacity = args.opacity.to;
422 if (args.opacity.from)
423 e.setOpacity(args.opacity.from);
426 o.left = args.left.to;
428 e.setLeft(args.left.from);
433 e.setTop(args.top.from);
438 e.setStyle(k, args[k].from);
442 // TODO: find out about easing plug in?
443 jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback);
450 Ext.lib.Region = function(t, r, b, l) {
459 Ext.lib.Region.prototype = {
460 contains : function(region) {
461 return ( region.left >= this.left &&
462 region.right <= this.right &&
463 region.top >= this.top &&
464 region.bottom <= this.bottom );
468 getArea : function() {
469 return ( (this.bottom - this.top) * (this.right - this.left) );
472 intersect : function(region) {
473 var t = Math.max( this.top, region.top );
474 var r = Math.min( this.right, region.right );
475 var b = Math.min( this.bottom, region.bottom );
476 var l = Math.max( this.left, region.left );
478 if (b >= t && r >= l) {
479 return new Ext.lib.Region(t, r, b, l);
484 union : function(region) {
485 var t = Math.min( this.top, region.top );
486 var r = Math.max( this.right, region.right );
487 var b = Math.max( this.bottom, region.bottom );
488 var l = Math.min( this.left, region.left );
490 return new Ext.lib.Region(t, r, b, l);
493 constrainTo : function(r) {
494 this.top = this.top.constrain(r.top, r.bottom);
495 this.bottom = this.bottom.constrain(r.top, r.bottom);
496 this.left = this.left.constrain(r.left, r.right);
497 this.right = this.right.constrain(r.left, r.right);
501 adjust : function(t, l, b, r){
510 Ext.lib.Region.getRegion = function(el) {
511 var p = Ext.lib.Dom.getXY(el);
514 var r = p[0] + el.offsetWidth;
515 var b = p[1] + el.offsetHeight;
518 return new Ext.lib.Region(t, r, b, l);
521 Ext.lib.Point = function(x, y) {
522 if (Ext.isArray(x)) {
526 this.x = this.right = this.left = this[0] = x;
527 this.y = this.top = this.bottom = this[1] = y;
530 Ext.lib.Point.prototype = new Ext.lib.Region();
534 function fnCleanUp() {
535 var p = Function.prototype;
536 delete p.createSequence;
538 delete p.createDelegate;
539 delete p.createCallback;
540 delete p.createInterceptor;
542 window.detachEvent("onunload", fnCleanUp);
544 window.attachEvent("onunload", fnCleanUp);