3 * Copyright(c) 2006-2010 Ext JS, Inc.
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){
33 } else if (p.compareDocumentPosition) {
34 return !!(p.compareDocumentPosition(c) & 16);
36 while (c = c.parentNode) {
44 getRegion : function(el){
45 return Ext.lib.Region.getRegion(el);
48 //////////////////////////////////////////////////////////////////////////////////////
49 // Use of jQuery.offset() removed to promote consistent behavior across libs.
51 //////////////////////////////////////////////////////////////////////////////////////
54 return this.getXY(el)[1];
58 return this.getXY(el)[0];
61 getXY : function(el) {
62 var p, pe, b, scroll, bd = (document.body || document.documentElement);
69 if (el.getBoundingClientRect) {
70 b = el.getBoundingClientRect();
71 scroll = fly(document).getScroll();
72 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
78 var hasAbsolute = fly(el).getStyle("position") == "absolute";
85 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
92 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
93 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
100 if (p != el && pe.getStyle('overflow') != 'visible') {
108 if (Ext.isSafari && hasAbsolute) {
113 if (Ext.isGecko && !hasAbsolute) {
115 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
116 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
120 while (p && p != bd) {
121 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
130 setXY : function(el, xy){
131 el = Ext.fly(el, '_setXY');
133 var pts = el.translatePoints(xy);
135 el.dom.style.left = pts.left + "px";
138 el.dom.style.top = pts.top + "px";
142 setX : function(el, x){
143 this.setXY(el, [x, false]);
146 setY : function(el, y){
147 this.setXY(el, [false, y]);
151 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
154 libFlyweight = new Ext.Element.Flyweight();
156 libFlyweight.dom = el;
160 getPageX : function(e){
161 e = e.browserEvent || e;
165 getPageY : function(e){
166 e = e.browserEvent || e;
171 e = e.browserEvent || e;
172 return [e.pageX, e.pageY];
175 getTarget : function(e){
179 // all Ext events will go through event manager which provides scoping
180 on : function(el, eventName, fn, scope, override){
181 jQuery(el).bind(eventName, fn);
184 un : function(el, eventName, fn){
185 jQuery(el).unbind(eventName, fn);
188 purgeElement : function(el){
192 preventDefault : function(e){
193 e = e.browserEvent || e;
194 if(e.preventDefault){
197 e.returnValue = false;
201 stopPropagation : function(e){
202 e = e.browserEvent || e;
203 if(e.stopPropagation){
206 e.cancelBubble = true;
210 stopEvent : function(e){
211 this.preventDefault(e);
212 this.stopPropagation(e);
215 onAvailable : function(id, fn, scope){
216 var start = new Date();
218 if(start.getElapsed() > 10000){
221 var el = document.getElementById(id);
224 fn.call(scope||window, el);
227 var iid = setInterval(f, 50);
230 resolveTextNode: Ext.isGecko ? function(node){
234 var s = HTMLElement.prototype.toString.call(node);
235 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
238 return node.nodeType == 3 ? node.parentNode : node;
240 return node && node.nodeType == 3 ? node.parentNode : node;
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, createResponse(cb, xhr));
263 }else if(cb.success){
264 cb.success.call(cb.scope||window, createResponse(cb, xhr));
269 var createResponse = function(cb, xhr){
276 headerStr = xhr.getAllResponseHeaders();
277 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
280 s = v.substr(0, t).toLowerCase();
281 if(v.charAt(t + 1) == ' '){
284 headerObj[s] = v.substr(t + 1);
290 responseText: xhr.responseText,
291 responseXML : xhr.responseXML,
292 argument: cb.argument,
294 statusText: xhr.statusText,
295 getResponseHeader : function(header){
296 return headerObj[header.toLowerCase()];
298 getAllResponseHeaders : function(){
304 request : function(method, uri, cb, data, options){
310 complete: createComplete(cb)
314 var hs = options.headers;
316 o.data = options.xmlData;
317 o.processData = false;
318 o.type = (method ? method : (options.method ? options.method : 'POST'));
319 if (!hs || !hs['Content-Type']){
320 o.contentType = 'text/xml';
322 }else if(options.jsonData){
323 o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
324 o.processData = false;
325 o.type = (method ? method : (options.method ? options.method : 'POST'));
326 if (!hs || !hs['Content-Type']){
327 o.contentType = 'application/json';
331 o.beforeSend = function(xhr){
333 if (hs.hasOwnProperty(h)) {
334 xhr.setRequestHeader(h, hs[h]);
343 formRequest : function(form, uri, cb, data, isUpload, sslUri){
345 type: Ext.getDom(form).method ||'POST',
347 data: jQuery(form).serialize()+(data?'&'+data:''),
349 complete: createComplete(cb)
353 isCallInProgress : function(trans){
357 abort : function(trans){
361 serializeForm : function(form){
362 return jQuery(form.dom||form).serialize();
367 Ext.lib.Anim = function(){
368 var createAnim = function(cb, scope){
371 stop : function(skipToLast){
375 isAnimated : function(){
379 proxyCallback : function(){
381 Ext.callback(cb, scope);
386 scroll : function(el, args, duration, easing, cb, scope){
387 // scroll anim not supported so just scroll immediately
388 var anim = createAnim(cb, scope);
390 if(typeof args.scroll.to[0] == 'number'){
391 el.scrollLeft = args.scroll.to[0];
393 if(typeof args.scroll.to[1] == 'number'){
394 el.scrollTop = args.scroll.to[1];
396 anim.proxyCallback();
400 motion : function(el, args, duration, easing, cb, scope){
401 return this.run(el, args, duration, easing, cb, scope);
404 color : function(el, args, duration, easing, cb, scope){
405 // color anim not supported, so execute callback immediately
406 var anim = createAnim(cb, scope);
407 anim.proxyCallback();
411 run : function(el, args, duration, easing, cb, scope, type){
412 var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun');
415 switch(k){ // jquery doesn't support, so convert
419 if(by = args.points.by){
421 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
423 pts = e.translatePoints(args.points.to);
427 if(!parseInt(e.getStyle('left'), 10)){ // auto bug
430 if(!parseInt(e.getStyle('top'), 10)){
433 if(args.points.from){
434 e.setXY(args.points.from);
438 o.width = args.width.to;
440 e.setWidth(args.width.from);
443 o.height = args.height.to;
444 if (args.height.from)
445 e.setHeight(args.height.from);
448 o.opacity = args.opacity.to;
449 if (args.opacity.from)
450 e.setOpacity(args.opacity.from);
453 o.left = args.left.to;
455 e.setLeft(args.left.from);
460 e.setTop(args.top.from);
462 // jQuery can't handle callback, scope, and xy arguments, so break here
471 e.setStyle(k, args[k].from);
475 // TODO: find out about easing plug in?
476 jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback);
483 Ext.lib.Region = function(t, r, b, l) {
492 Ext.lib.Region.prototype = {
493 contains : function(region) {
494 return ( region.left >= this.left &&
495 region.right <= this.right &&
496 region.top >= this.top &&
497 region.bottom <= this.bottom );
501 getArea : function() {
502 return ( (this.bottom - this.top) * (this.right - this.left) );
505 intersect : function(region) {
506 var t = Math.max( this.top, region.top );
507 var r = Math.min( this.right, region.right );
508 var b = Math.min( this.bottom, region.bottom );
509 var l = Math.max( this.left, region.left );
511 if (b >= t && r >= l) {
512 return new Ext.lib.Region(t, r, b, l);
517 union : function(region) {
518 var t = Math.min( this.top, region.top );
519 var r = Math.max( this.right, region.right );
520 var b = Math.max( this.bottom, region.bottom );
521 var l = Math.min( this.left, region.left );
523 return new Ext.lib.Region(t, r, b, l);
526 constrainTo : function(r) {
527 this.top = this.top.constrain(r.top, r.bottom);
528 this.bottom = this.bottom.constrain(r.top, r.bottom);
529 this.left = this.left.constrain(r.left, r.right);
530 this.right = this.right.constrain(r.left, r.right);
534 adjust : function(t, l, b, r){
543 Ext.lib.Region.getRegion = function(el) {
544 var p = Ext.lib.Dom.getXY(el);
547 var r = p[0] + el.offsetWidth;
548 var b = p[1] + el.offsetHeight;
551 return new Ext.lib.Region(t, r, b, l);
554 Ext.lib.Point = function(x, y) {
555 if (Ext.isArray(x)) {
559 this.x = this.right = this.left = this[0] = x;
560 this.y = this.top = this.bottom = this[1] = y;
563 Ext.lib.Point.prototype = new Ext.lib.Region();
567 function fnCleanUp() {
568 var p = Function.prototype;
569 delete p.createSequence;
571 delete p.createDelegate;
572 delete p.createCallback;
573 delete p.createInterceptor;
575 window.detachEvent("onunload", fnCleanUp);
577 window.attachEvent("onunload", fnCleanUp);