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){return headerObj[header.toLowerCase()];},
296 getAllResponseHeaders : function(){return headerStr}
300 request : function(method, uri, cb, data, options){
306 complete: createComplete(cb)
310 var hs = options.headers;
312 o.data = options.xmlData;
313 o.processData = false;
314 o.type = (method ? method : (options.method ? options.method : 'POST'));
315 if (!hs || !hs['Content-Type']){
316 o.contentType = 'text/xml';
318 }else if(options.jsonData){
319 o.data = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
320 o.processData = false;
321 o.type = (method ? method : (options.method ? options.method : 'POST'));
322 if (!hs || !hs['Content-Type']){
323 o.contentType = 'application/json';
327 o.beforeSend = function(xhr){
329 if(hs.hasOwnProperty(h)){
330 xhr.setRequestHeader(h, hs[h]);
339 formRequest : function(form, uri, cb, data, isUpload, sslUri){
341 type: Ext.getDom(form).method ||'POST',
343 data: jQuery(form).serialize()+(data?'&'+data:''),
345 complete: createComplete(cb)
349 isCallInProgress : function(trans){
353 abort : function(trans){
357 serializeForm : function(form){
358 return jQuery(form.dom||form).serialize();
363 Ext.lib.Anim = function(){
364 var createAnim = function(cb, scope){
367 stop : function(skipToLast){
371 isAnimated : function(){
375 proxyCallback : function(){
377 Ext.callback(cb, scope);
382 scroll : function(el, args, duration, easing, cb, scope){
383 // scroll anim not supported so just scroll immediately
384 var anim = createAnim(cb, scope);
386 if(typeof args.scroll.to[0] == 'number'){
387 el.scrollLeft = args.scroll.to[0];
389 if(typeof args.scroll.to[1] == 'number'){
390 el.scrollTop = args.scroll.to[1];
392 anim.proxyCallback();
396 motion : function(el, args, duration, easing, cb, scope){
397 return this.run(el, args, duration, easing, cb, scope);
400 color : function(el, args, duration, easing, cb, scope){
401 // color anim not supported, so execute callback immediately
402 var anim = createAnim(cb, scope);
403 anim.proxyCallback();
407 run : function(el, args, duration, easing, cb, scope, type){
408 var anim = createAnim(cb, scope), e = Ext.fly(el, '_animrun');
411 switch(k){ // jquery doesn't support, so convert
415 if(by = args.points.by){
417 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
419 pts = e.translatePoints(args.points.to);
423 if(!parseInt(e.getStyle('left'), 10)){ // auto bug
426 if(!parseInt(e.getStyle('top'), 10)){
429 if(args.points.from){
430 e.setXY(args.points.from);
434 o.width = args.width.to;
436 e.setWidth(args.width.from);
439 o.height = args.height.to;
440 if (args.height.from)
441 e.setHeight(args.height.from);
444 o.opacity = args.opacity.to;
445 if (args.opacity.from)
446 e.setOpacity(args.opacity.from);
449 o.left = args.left.to;
451 e.setLeft(args.left.from);
456 e.setTop(args.top.from);
458 // jQuery can't handle callback, scope, and xy arguments, so break here
467 e.setStyle(k, args[k].from);
471 // TODO: find out about easing plug in?
472 jQuery(el).animate(o, duration*1000, undefined, anim.proxyCallback);
479 Ext.lib.Region = function(t, r, b, l) {
488 Ext.lib.Region.prototype = {
489 contains : function(region) {
490 return ( region.left >= this.left &&
491 region.right <= this.right &&
492 region.top >= this.top &&
493 region.bottom <= this.bottom );
497 getArea : function() {
498 return ( (this.bottom - this.top) * (this.right - this.left) );
501 intersect : function(region) {
502 var t = Math.max( this.top, region.top );
503 var r = Math.min( this.right, region.right );
504 var b = Math.min( this.bottom, region.bottom );
505 var l = Math.max( this.left, region.left );
507 if (b >= t && r >= l) {
508 return new Ext.lib.Region(t, r, b, l);
513 union : function(region) {
514 var t = Math.min( this.top, region.top );
515 var r = Math.max( this.right, region.right );
516 var b = Math.max( this.bottom, region.bottom );
517 var l = Math.min( this.left, region.left );
519 return new Ext.lib.Region(t, r, b, l);
522 constrainTo : function(r) {
523 this.top = this.top.constrain(r.top, r.bottom);
524 this.bottom = this.bottom.constrain(r.top, r.bottom);
525 this.left = this.left.constrain(r.left, r.right);
526 this.right = this.right.constrain(r.left, r.right);
530 adjust : function(t, l, b, r){
539 Ext.lib.Region.getRegion = function(el) {
540 var p = Ext.lib.Dom.getXY(el);
543 var r = p[0] + el.offsetWidth;
544 var b = p[1] + el.offsetHeight;
547 return new Ext.lib.Region(t, r, b, l);
550 Ext.lib.Point = function(x, y) {
551 if (Ext.isArray(x)) {
555 this.x = this.right = this.left = this[0] = x;
556 this.y = this.top = this.bottom = this[1] = y;
559 Ext.lib.Point.prototype = new Ext.lib.Region();
563 function fnCleanUp() {
564 var p = Function.prototype;
565 delete p.createSequence;
567 delete p.createDelegate;
568 delete p.createCallback;
569 delete p.createInterceptor;
571 window.detachEvent("onunload", fnCleanUp);
573 window.attachEvent("onunload", fnCleanUp);