2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
14 getViewWidth : function(full){
\r
15 return full ? this.getDocumentWidth() : this.getViewportWidth();
\r
18 getViewHeight : function(full){
\r
19 return full ? this.getDocumentHeight() : this.getViewportHeight();
\r
22 getDocumentHeight: function() { // missing from prototype?
\r
23 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
\r
24 return Math.max(scrollHeight, this.getViewportHeight());
\r
27 getDocumentWidth: function() { // missing from prototype?
\r
28 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
\r
29 return Math.max(scrollWidth, this.getViewportWidth());
\r
32 getViewportHeight: function() { // missing from prototype?
\r
33 var height = self.innerHeight;
\r
34 var mode = document.compatMode;
\r
36 if ( (mode || Ext.isIE) && !Ext.isOpera ) {
\r
37 height = (mode == "CSS1Compat") ?
\r
38 document.documentElement.clientHeight : // Standards
\r
39 document.body.clientHeight; // Quirks
\r
45 getViewportWidth: function() { // missing from prototype?
\r
46 var width = self.innerWidth; // Safari
\r
47 var mode = document.compatMode;
\r
49 if (mode || Ext.isIE) { // IE, Gecko, Opera
\r
50 width = (mode == "CSS1Compat") ?
\r
51 document.documentElement.clientWidth : // Standards
\r
52 document.body.clientWidth; // Quirks
\r
57 isAncestor : function(p, c){ // missing from prototype?
\r
60 if (!p || !c) {return false;}
\r
62 if(p.contains && !Ext.isSafari) {
\r
63 return p.contains(c);
\r
64 }else if(p.compareDocumentPosition) {
\r
65 return !!(p.compareDocumentPosition(c) & 16);
\r
67 var parent = c.parentNode;
\r
72 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
\r
75 parent = parent.parentNode;
\r
81 getRegion : function(el){
\r
82 return Ext.lib.Region.getRegion(el);
\r
85 getY : function(el){
\r
86 return this.getXY(el)[1];
\r
89 getX : function(el){
\r
90 return this.getXY(el)[0];
\r
93 getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
\r
94 var p, pe, b, scroll, bd = (document.body || document.documentElement);
\r
95 el = Ext.getDom(el);
\r
101 if (el.getBoundingClientRect) {
\r
102 b = el.getBoundingClientRect();
\r
103 scroll = fly(document).getScroll();
\r
104 return [b.left + scroll.left, b.top + scroll.top];
\r
110 var hasAbsolute = fly(el).getStyle("position") == "absolute";
\r
117 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
\r
118 hasAbsolute = true;
\r
124 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
\r
125 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
\r
132 if (p != el && pe.getStyle('overflow') != 'visible') {
\r
137 p = p.offsetParent;
\r
140 if (Ext.isSafari && hasAbsolute) {
\r
141 x -= bd.offsetLeft;
\r
145 if (Ext.isGecko && !hasAbsolute) {
\r
147 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
\r
148 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
\r
152 while (p && p != bd) {
\r
153 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
\r
162 setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
\r
163 el = Ext.fly(el, '_setXY');
\r
165 var pts = el.translatePoints(xy);
\r
166 if(xy[0] !== false){
\r
167 el.dom.style.left = pts.left + "px";
\r
169 if(xy[1] !== false){
\r
170 el.dom.style.top = pts.top + "px";
\r
174 setX : function(el, x){
\r
175 this.setXY(el, [x, false]);
\r
178 setY : function(el, y){
\r
179 this.setXY(el, [false, y]);
\r
184 getPageX : function(e){
\r
185 return Event.pointerX(e.browserEvent || e);
\r
188 getPageY : function(e){
\r
189 return Event.pointerY(e.browserEvent || e);
\r
192 getXY : function(e){
\r
193 e = e.browserEvent || e;
\r
194 return [Event.pointerX(e), Event.pointerY(e)];
\r
197 getTarget : function(e){
\r
198 return Event.element(e.browserEvent || e);
\r
201 resolveTextNode: function(node) {
\r
202 if (node && 3 == node.nodeType) {
\r
203 return node.parentNode;
\r
209 getRelatedTarget: function(ev) { // missing from prototype?
\r
210 ev = ev.browserEvent || ev;
\r
211 var t = ev.relatedTarget;
\r
213 if (ev.type == "mouseout") {
\r
215 } else if (ev.type == "mouseover") {
\r
216 t = ev.fromElement;
\r
220 return this.resolveTextNode(t);
\r
223 on : function(el, eventName, fn){
\r
224 Event.observe(el, eventName, fn, false);
\r
227 un : function(el, eventName, fn){
\r
228 Event.stopObserving(el, eventName, fn, false);
\r
231 purgeElement : function(el){
\r
235 preventDefault : function(e){ // missing from prototype?
\r
236 e = e.browserEvent || e;
\r
237 if(e.preventDefault) {
\r
238 e.preventDefault();
\r
240 e.returnValue = false;
\r
244 stopPropagation : function(e){ // missing from prototype?
\r
245 e = e.browserEvent || e;
\r
246 if(e.stopPropagation) {
\r
247 e.stopPropagation();
\r
249 e.cancelBubble = true;
\r
253 stopEvent : function(e){
\r
254 Event.stop(e.browserEvent || e);
\r
257 onAvailable : function(id, fn, scope){ // no equiv
\r
258 var start = new Date(), iid;
\r
259 var f = function(){
\r
260 if(start.getElapsed() > 10000){
\r
261 clearInterval(iid);
\r
263 var el = document.getElementById(id);
\r
265 clearInterval(iid);
\r
266 fn.call(scope||window, el);
\r
269 iid = setInterval(f, 50);
\r
273 Ext.lib.Ajax = function(){
\r
274 var createSuccess = function(cb){
\r
275 return cb.success ? function(xhr){
\r
276 cb.success.call(cb.scope||window, {
\r
277 responseText: xhr.responseText,
\r
278 responseXML : xhr.responseXML,
\r
279 argument: cb.argument
\r
283 var createFailure = function(cb){
\r
284 return cb.failure ? function(xhr){
\r
285 cb.failure.call(cb.scope||window, {
\r
286 responseText: xhr.responseText,
\r
287 responseXML : xhr.responseXML,
\r
288 argument: cb.argument
\r
293 request : function(method, uri, cb, data, options){
\r
296 parameters: data || '',
\r
297 timeout: cb.timeout,
\r
298 onSuccess: createSuccess(cb),
\r
299 onFailure: createFailure(cb)
\r
302 var hs = options.headers;
\r
304 o.requestHeaders = hs;
\r
306 if(options.xmlData){
\r
307 method = (method ? method : (options.method ? options.method : 'POST'));
\r
308 if (!hs || !hs['Content-Type']){
\r
309 o.contentType = 'text/xml';
\r
311 o.postBody = options.xmlData;
\r
312 delete o.parameters;
\r
314 if(options.jsonData){
\r
315 method = (method ? method : (options.method ? options.method : 'POST'));
\r
316 if (!hs || !hs['Content-Type']){
\r
317 o.contentType = 'application/json';
\r
319 o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
\r
320 delete o.parameters;
\r
323 new Ajax.Request(uri, o);
\r
326 formRequest : function(form, uri, cb, data, isUpload, sslUri){
\r
327 new Ajax.Request(uri, {
\r
328 method: Ext.getDom(form).method ||'POST',
\r
329 parameters: Form.serialize(form)+(data?'&'+data:''),
\r
330 timeout: cb.timeout,
\r
331 onSuccess: createSuccess(cb),
\r
332 onFailure: createFailure(cb)
\r
336 isCallInProgress : function(trans){
\r
340 abort : function(trans){
\r
344 serializeForm : function(form){
\r
345 return Form.serialize(form.dom||form);
\r
351 Ext.lib.Anim = function(){
\r
354 easeOut: function(pos) {
\r
355 return 1-Math.pow(1-pos,2);
\r
357 easeIn: function(pos) {
\r
358 return 1-Math.pow(1-pos,2);
\r
361 var createAnim = function(cb, scope){
\r
363 stop : function(skipToLast){
\r
364 this.effect.cancel();
\r
367 isAnimated : function(){
\r
368 return this.effect.state == 'running';
\r
371 proxyCallback : function(){
\r
372 Ext.callback(cb, scope);
\r
377 scroll : function(el, args, duration, easing, cb, scope){
\r
378 // not supported so scroll immediately?
\r
379 var anim = createAnim(cb, scope);
\r
380 el = Ext.getDom(el);
\r
381 if(typeof args.scroll.to[0] == 'number'){
\r
382 el.scrollLeft = args.scroll.to[0];
\r
384 if(typeof args.scroll.to[1] == 'number'){
\r
385 el.scrollTop = args.scroll.to[1];
\r
387 anim.proxyCallback();
\r
391 motion : function(el, args, duration, easing, cb, scope){
\r
392 return this.run(el, args, duration, easing, cb, scope);
\r
395 color : function(el, args, duration, easing, cb, scope){
\r
396 return this.run(el, args, duration, easing, cb, scope);
\r
399 run : function(el, args, duration, easing, cb, scope, type){
\r
401 for(var k in args){
\r
402 switch(k){ // scriptaculous doesn't support, so convert these
\r
404 var by, pts, e = Ext.fly(el, '_animrun');
\r
406 if(by = args.points.by){
\r
407 var xy = e.getXY();
\r
408 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
\r
410 pts = e.translatePoints(args.points.to);
\r
412 o.left = pts.left+'px';
\r
413 o.top = pts.top+'px';
\r
416 o.width = args.width.to+'px';
\r
419 o.height = args.height.to+'px';
\r
422 o.opacity = String(args.opacity.to);
\r
425 o[k] = String(args[k].to);
\r
429 var anim = createAnim(cb, scope);
\r
430 anim.effect = new Effect.Morph(Ext.id(el), {
\r
431 duration: duration,
\r
432 afterFinish: anim.proxyCallback,
\r
433 transition: easings[easing] || Effect.Transitions.linear,
\r
442 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
\r
445 libFlyweight = new Ext.Element.Flyweight();
\r
447 libFlyweight.dom = el;
\r
448 return libFlyweight;
\r
451 Ext.lib.Region = function(t, r, b, l) {
\r
460 Ext.lib.Region.prototype = {
\r
461 contains : function(region) {
\r
462 return ( region.left >= this.left &&
\r
463 region.right <= this.right &&
\r
464 region.top >= this.top &&
\r
465 region.bottom <= this.bottom );
\r
469 getArea : function() {
\r
470 return ( (this.bottom - this.top) * (this.right - this.left) );
\r
473 intersect : function(region) {
\r
474 var t = Math.max( this.top, region.top );
\r
475 var r = Math.min( this.right, region.right );
\r
476 var b = Math.min( this.bottom, region.bottom );
\r
477 var l = Math.max( this.left, region.left );
\r
479 if (b >= t && r >= l) {
\r
480 return new Ext.lib.Region(t, r, b, l);
\r
485 union : function(region) {
\r
486 var t = Math.min( this.top, region.top );
\r
487 var r = Math.max( this.right, region.right );
\r
488 var b = Math.max( this.bottom, region.bottom );
\r
489 var l = Math.min( this.left, region.left );
\r
491 return new Ext.lib.Region(t, r, b, l);
\r
494 constrainTo : function(r) {
\r
495 this.top = this.top.constrain(r.top, r.bottom);
\r
496 this.bottom = this.bottom.constrain(r.top, r.bottom);
\r
497 this.left = this.left.constrain(r.left, r.right);
\r
498 this.right = this.right.constrain(r.left, r.right);
\r
502 adjust : function(t, l, b, r){
\r
511 Ext.lib.Region.getRegion = function(el) {
\r
512 var p = Ext.lib.Dom.getXY(el);
\r
515 var r = p[0] + el.offsetWidth;
\r
516 var b = p[1] + el.offsetHeight;
\r
519 return new Ext.lib.Region(t, r, b, l);
\r
522 Ext.lib.Point = function(x, y) {
\r
523 if (Ext.isArray(x)) {
\r
527 this.x = this.right = this.left = this[0] = x;
\r
528 this.y = this.top = this.bottom = this[1] = y;
\r
531 Ext.lib.Point.prototype = new Ext.lib.Region();
\r
534 // prevent IE leaks
\r
536 function fnCleanUp() {
\r
537 var p = Function.prototype;
\r
538 delete p.createSequence;
\r
540 delete p.createDelegate;
\r
541 delete p.createCallback;
\r
542 delete p.createInterceptor;
\r
544 window.detachEvent("onunload", fnCleanUp);
\r
546 window.attachEvent("onunload", fnCleanUp);
\r