3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 version = Prototype.Version.split('.'),
11 mouseEnterSupported = (parseInt(version[0]) >= 2) || (parseInt(version[1]) >= 7) || (parseInt(version[2]) >= 1),
13 isXUL = Ext.isGecko ? function(node){
14 return Object.prototype.toString.call(node) == '[object XULElement]';
16 isTextNode = Ext.isGecko ? function(node){
18 return node.nodeType == 3;
24 return node.nodeType == 3;
26 elContains = function(parent, child) {
27 if(parent && parent.firstChild){
29 if(child === parent) {
33 child = child.parentNode;
35 // In FF if you mouseout an text input element
36 // thats inside a div sometimes it randomly throws
37 // Permission denied to get property HTMLDivElement.parentNode
38 // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
41 if(child && (child.nodeType != 1)) {
48 checkRelatedTarget = function(e) {
49 var related = Ext.lib.Event.getRelatedTarget(e);
50 return !(isXUL(related) || elContains(e.currentTarget,related));
54 getViewWidth : function(full){
55 return full ? this.getDocumentWidth() : this.getViewportWidth();
58 getViewHeight : function(full){
59 return full ? this.getDocumentHeight() : this.getViewportHeight();
62 getDocumentHeight: function() { // missing from prototype?
63 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
64 return Math.max(scrollHeight, this.getViewportHeight());
67 getDocumentWidth: function() { // missing from prototype?
68 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
69 return Math.max(scrollWidth, this.getViewportWidth());
72 getViewportHeight: function() { // missing from prototype?
73 var height = self.innerHeight;
74 var mode = document.compatMode;
76 if ( (mode || Ext.isIE) && !Ext.isOpera ) {
77 height = (mode == "CSS1Compat") ?
78 document.documentElement.clientHeight : // Standards
79 document.body.clientHeight; // Quirks
85 getViewportWidth: function() { // missing from prototype?
86 var width = self.innerWidth; // Safari
87 var mode = document.compatMode;
89 if (mode || Ext.isIE) { // IE, Gecko, Opera
90 width = (mode == "CSS1Compat") ?
91 document.documentElement.clientWidth : // Standards
92 document.body.clientWidth; // Quirks
97 isAncestor : function(p, c){ // missing from prototype?
100 if (!p || !c) {return false;}
102 if(p.contains && !Ext.isSafari) {
103 return p.contains(c);
104 }else if(p.compareDocumentPosition) {
105 return !!(p.compareDocumentPosition(c) & 16);
107 var parent = c.parentNode;
112 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
115 parent = parent.parentNode;
121 getRegion : function(el){
122 return Ext.lib.Region.getRegion(el);
126 return this.getXY(el)[1];
130 return this.getXY(el)[0];
133 getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
134 var p, pe, b, scroll, bd = (document.body || document.documentElement);
141 if (el.getBoundingClientRect) {
142 b = el.getBoundingClientRect();
143 scroll = fly(document).getScroll();
144 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
150 var hasAbsolute = fly(el).getStyle("position") == "absolute";
157 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
164 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
165 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
172 if (p != el && pe.getStyle('overflow') != 'visible') {
180 if (Ext.isSafari && hasAbsolute) {
185 if (Ext.isGecko && !hasAbsolute) {
187 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
188 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
192 while (p && p != bd) {
193 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
202 setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
203 el = Ext.fly(el, '_setXY');
205 var pts = el.translatePoints(xy);
207 el.dom.style.left = pts.left + "px";
210 el.dom.style.top = pts.top + "px";
214 setX : function(el, x){
215 this.setXY(el, [x, false]);
218 setY : function(el, y){
219 this.setXY(el, [false, y]);
224 getPageX : function(e){
225 return Event.pointerX(e.browserEvent || e);
228 getPageY : function(e){
229 return Event.pointerY(e.browserEvent || e);
233 e = e.browserEvent || e;
234 return [Event.pointerX(e), Event.pointerY(e)];
237 getTarget : function(e){
238 return Event.element(e.browserEvent || e);
241 resolveTextNode: function(node) {
242 return node && !isXUL(node) && isTextNode(node) ? node.parentNode : node;
245 getRelatedTarget: function(ev) { // missing from prototype?
246 ev = ev.browserEvent || ev;
247 var t = ev.relatedTarget;
249 if (ev.type == "mouseout") {
251 } else if (ev.type == "mouseover") {
256 return this.resolveTextNode(t);
259 on : function(el, eventName, fn){
260 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
261 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
262 item[eventName] = fn;
263 fn = fn.createInterceptor(checkRelatedTarget);
264 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
266 Event.observe(el, eventName, fn, false);
269 un : function(el, eventName, fn){
270 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
271 var item = mouseCache[el.id],
272 ev = item && item[eventName];
276 delete item[eventName];
277 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
280 Event.stopObserving(el, eventName, fn, false);
283 purgeElement : function(el){
287 preventDefault : function(e){ // missing from prototype?
288 e = e.browserEvent || e;
289 if(e.preventDefault) {
292 e.returnValue = false;
296 stopPropagation : function(e){ // missing from prototype?
297 e = e.browserEvent || e;
298 if(e.stopPropagation) {
301 e.cancelBubble = true;
305 stopEvent : function(e){
306 Event.stop(e.browserEvent || e);
309 onAvailable : function(id, fn, scope){ // no equiv
310 var start = new Date(), iid;
312 if(start.getElapsed() > 10000){
315 var el = document.getElementById(id);
318 fn.call(scope||window, el);
321 iid = setInterval(f, 50);
325 Ext.lib.Ajax = function(){
326 var createSuccess = function(cb){
327 return cb.success ? function(xhr){
328 cb.success.call(cb.scope||window, {
329 responseText: xhr.responseText,
330 responseXML : xhr.responseXML,
331 argument: cb.argument
335 var createFailure = function(cb){
336 return cb.failure ? function(xhr){
337 cb.failure.call(cb.scope||window, {
338 responseText: xhr.responseText,
339 responseXML : xhr.responseXML,
340 argument: cb.argument
345 request : function(method, uri, cb, data, options){
348 parameters: data || '',
350 onSuccess: createSuccess(cb),
351 onFailure: createFailure(cb)
354 var hs = options.headers;
356 o.requestHeaders = hs;
359 method = (method ? method : (options.method ? options.method : 'POST'));
360 if (!hs || !hs['Content-Type']){
361 o.contentType = 'text/xml';
363 o.postBody = options.xmlData;
366 if(options.jsonData){
367 method = (method ? method : (options.method ? options.method : 'POST'));
368 if (!hs || !hs['Content-Type']){
369 o.contentType = 'application/json';
371 o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
375 new Ajax.Request(uri, o);
378 formRequest : function(form, uri, cb, data, isUpload, sslUri){
379 new Ajax.Request(uri, {
380 method: Ext.getDom(form).method ||'POST',
381 parameters: Form.serialize(form)+(data?'&'+data:''),
383 onSuccess: createSuccess(cb),
384 onFailure: createFailure(cb)
388 isCallInProgress : function(trans){
392 abort : function(trans){
396 serializeForm : function(form){
397 return Form.serialize(form.dom||form);
403 Ext.lib.Anim = function(){
406 easeOut: function(pos) {
407 return 1-Math.pow(1-pos,2);
409 easeIn: function(pos) {
410 return 1-Math.pow(1-pos,2);
413 var createAnim = function(cb, scope){
415 stop : function(skipToLast){
416 this.effect.cancel();
419 isAnimated : function(){
420 return this.effect.state == 'running';
423 proxyCallback : function(){
424 Ext.callback(cb, scope);
429 scroll : function(el, args, duration, easing, cb, scope){
430 // not supported so scroll immediately?
431 var anim = createAnim(cb, scope);
433 if(typeof args.scroll.to[0] == 'number'){
434 el.scrollLeft = args.scroll.to[0];
436 if(typeof args.scroll.to[1] == 'number'){
437 el.scrollTop = args.scroll.to[1];
439 anim.proxyCallback();
443 motion : function(el, args, duration, easing, cb, scope){
444 return this.run(el, args, duration, easing, cb, scope);
447 color : function(el, args, duration, easing, cb, scope){
448 return this.run(el, args, duration, easing, cb, scope);
451 run : function(el, args, duration, easing, cb, scope, type){
454 switch(k){ // scriptaculous doesn't support, so convert these
456 var by, pts, e = Ext.fly(el, '_animrun');
458 if(by = args.points.by){
460 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
462 pts = e.translatePoints(args.points.to);
464 o.left = pts.left+'px';
465 o.top = pts.top+'px';
468 o.width = args.width.to+'px';
471 o.height = args.height.to+'px';
474 o.opacity = String(args.opacity.to);
477 o[k] = String(args[k].to);
481 var anim = createAnim(cb, scope);
482 anim.effect = new Effect.Morph(Ext.id(el), {
484 afterFinish: anim.proxyCallback,
485 transition: easings[easing] || Effect.Transitions.linear,
494 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
497 libFlyweight = new Ext.Element.Flyweight();
499 libFlyweight.dom = el;
503 Ext.lib.Region = function(t, r, b, l) {
512 Ext.lib.Region.prototype = {
513 contains : function(region) {
514 return ( region.left >= this.left &&
515 region.right <= this.right &&
516 region.top >= this.top &&
517 region.bottom <= this.bottom );
521 getArea : function() {
522 return ( (this.bottom - this.top) * (this.right - this.left) );
525 intersect : function(region) {
526 var t = Math.max( this.top, region.top );
527 var r = Math.min( this.right, region.right );
528 var b = Math.min( this.bottom, region.bottom );
529 var l = Math.max( this.left, region.left );
531 if (b >= t && r >= l) {
532 return new Ext.lib.Region(t, r, b, l);
537 union : function(region) {
538 var t = Math.min( this.top, region.top );
539 var r = Math.max( this.right, region.right );
540 var b = Math.max( this.bottom, region.bottom );
541 var l = Math.min( this.left, region.left );
543 return new Ext.lib.Region(t, r, b, l);
546 constrainTo : function(r) {
547 this.top = this.top.constrain(r.top, r.bottom);
548 this.bottom = this.bottom.constrain(r.top, r.bottom);
549 this.left = this.left.constrain(r.left, r.right);
550 this.right = this.right.constrain(r.left, r.right);
554 adjust : function(t, l, b, r){
563 Ext.lib.Region.getRegion = function(el) {
564 var p = Ext.lib.Dom.getXY(el);
567 var r = p[0] + el.offsetWidth;
568 var b = p[1] + el.offsetHeight;
571 return new Ext.lib.Region(t, r, b, l);
574 Ext.lib.Point = function(x, y) {
575 if (Ext.isArray(x)) {
579 this.x = this.right = this.left = this[0] = x;
580 this.y = this.top = this.bottom = this[1] = y;
583 Ext.lib.Point.prototype = new Ext.lib.Region();
588 function fnCleanUp() {
589 var p = Function.prototype;
590 delete p.createSequence;
592 delete p.createDelegate;
593 delete p.createCallback;
594 delete p.createInterceptor;
596 window.detachEvent("onunload", fnCleanUp);
598 window.attachEvent("onunload", fnCleanUp);