3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
17 version = Prototype.Version.split('.'),
18 mouseEnterSupported = (parseInt(version[0]) >= 2) || (parseInt(version[1]) >= 7) || (parseInt(version[2]) >= 1),
20 elContains = function(parent, child) {
21 if(parent && parent.firstChild){
23 if(child === parent) {
26 child = child.parentNode;
27 if(child && (child.nodeType != 1)) {
34 checkRelatedTarget = function(e) {
35 return !elContains(e.currentTarget, pub.getRelatedTarget(e));
39 getViewWidth : function(full){
40 return full ? this.getDocumentWidth() : this.getViewportWidth();
43 getViewHeight : function(full){
44 return full ? this.getDocumentHeight() : this.getViewportHeight();
47 getDocumentHeight: function() { // missing from prototype?
48 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
49 return Math.max(scrollHeight, this.getViewportHeight());
52 getDocumentWidth: function() { // missing from prototype?
53 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
54 return Math.max(scrollWidth, this.getViewportWidth());
57 getViewportHeight: function() { // missing from prototype?
58 var height = self.innerHeight;
59 var mode = document.compatMode;
61 if ( (mode || Ext.isIE) && !Ext.isOpera ) {
62 height = (mode == "CSS1Compat") ?
63 document.documentElement.clientHeight : // Standards
64 document.body.clientHeight; // Quirks
70 getViewportWidth: function() { // missing from prototype?
71 var width = self.innerWidth; // Safari
72 var mode = document.compatMode;
74 if (mode || Ext.isIE) { // IE, Gecko, Opera
75 width = (mode == "CSS1Compat") ?
76 document.documentElement.clientWidth : // Standards
77 document.body.clientWidth; // Quirks
82 isAncestor : function(p, c){ // missing from prototype?
90 } else if (p.compareDocumentPosition) {
91 return !!(p.compareDocumentPosition(c) & 16);
93 while (c = c.parentNode) {
101 getRegion : function(el){
102 return Ext.lib.Region.getRegion(el);
106 return this.getXY(el)[1];
110 return this.getXY(el)[0];
113 getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
114 var p, pe, b, scroll, bd = (document.body || document.documentElement);
121 if (el.getBoundingClientRect) {
122 b = el.getBoundingClientRect();
123 scroll = fly(document).getScroll();
124 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
130 var hasAbsolute = fly(el).getStyle("position") == "absolute";
137 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
144 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
145 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
152 if (p != el && pe.getStyle('overflow') != 'visible') {
160 if (Ext.isSafari && hasAbsolute) {
165 if (Ext.isGecko && !hasAbsolute) {
167 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
168 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
172 while (p && p != bd) {
173 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
182 setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
183 el = Ext.fly(el, '_setXY');
185 var pts = el.translatePoints(xy);
187 el.dom.style.left = pts.left + "px";
190 el.dom.style.top = pts.top + "px";
194 setX : function(el, x){
195 this.setXY(el, [x, false]);
198 setY : function(el, y){
199 this.setXY(el, [false, y]);
204 getPageX : function(e){
205 return Event.pointerX(e.browserEvent || e);
208 getPageY : function(e){
209 return Event.pointerY(e.browserEvent || e);
213 e = e.browserEvent || e;
214 return [Event.pointerX(e), Event.pointerY(e)];
217 getTarget : function(e){
218 return Event.element(e.browserEvent || e);
221 resolveTextNode: Ext.isGecko ? function(node){
225 var s = HTMLElement.prototype.toString.call(node);
226 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
229 return node.nodeType == 3 ? node.parentNode : node;
231 return node && node.nodeType == 3 ? node.parentNode : node;
234 getRelatedTarget: function(ev) { // missing from prototype?
235 ev = ev.browserEvent || ev;
236 var t = ev.relatedTarget;
238 if (ev.type == "mouseout") {
240 } else if (ev.type == "mouseover") {
245 return this.resolveTextNode(t);
248 on : function(el, eventName, fn){
249 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
250 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
251 item[eventName] = fn;
252 fn = fn.createInterceptor(checkRelatedTarget);
253 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
255 Event.observe(el, eventName, fn, false);
258 un : function(el, eventName, fn){
259 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
260 var item = mouseCache[el.id],
261 ev = item && item[eventName];
265 delete item[eventName];
266 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
269 Event.stopObserving(el, eventName, fn, false);
272 purgeElement : function(el){
276 preventDefault : function(e){ // missing from prototype?
277 e = e.browserEvent || e;
278 if(e.preventDefault) {
281 e.returnValue = false;
285 stopPropagation : function(e){ // missing from prototype?
286 e = e.browserEvent || e;
287 if(e.stopPropagation) {
290 e.cancelBubble = true;
294 stopEvent : function(e){
295 Event.stop(e.browserEvent || e);
298 onAvailable : function(id, fn, scope){ // no equiv
299 var start = new Date(), iid;
301 if(start.getElapsed() > 10000){
304 var el = document.getElementById(id);
307 fn.call(scope||window, el);
310 iid = setInterval(f, 50);
314 Ext.lib.Ajax = function(){
315 var createSuccess = function(cb){
316 return cb.success ? function(xhr){
317 cb.success.call(cb.scope||window, createResponse(cb, xhr));
320 var createFailure = function(cb){
321 return cb.failure ? function(xhr){
322 cb.failure.call(cb.scope||window, createResponse(cb, xhr));
325 var createResponse = function(cb, xhr){
332 headerStr = xhr.getAllResponseHeaders();
333 Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
336 s = v.substr(0, t).toLowerCase();
337 if(v.charAt(t + 1) == ' '){
340 headerObj[s] = v.substr(t + 1);
346 responseText: xhr.responseText,
347 responseXML : xhr.responseXML,
348 argument: cb.argument,
350 statusText: xhr.statusText,
351 getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
352 getAllResponseHeaders : function(){return headerStr}
356 request : function(method, uri, cb, data, options){
359 parameters: data || '',
361 onSuccess: createSuccess(cb),
362 onFailure: createFailure(cb)
365 var hs = options.headers;
367 o.requestHeaders = hs;
370 method = (method ? method : (options.method ? options.method : 'POST'));
371 if (!hs || !hs['Content-Type']){
372 o.contentType = 'text/xml';
374 o.postBody = options.xmlData;
377 if(options.jsonData){
378 method = (method ? method : (options.method ? options.method : 'POST'));
379 if (!hs || !hs['Content-Type']){
380 o.contentType = 'application/json';
382 o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
386 new Ajax.Request(uri, o);
389 formRequest : function(form, uri, cb, data, isUpload, sslUri){
390 new Ajax.Request(uri, {
391 method: Ext.getDom(form).method ||'POST',
392 parameters: Form.serialize(form)+(data?'&'+data:''),
394 onSuccess: createSuccess(cb),
395 onFailure: createFailure(cb)
399 isCallInProgress : function(trans){
403 abort : function(trans){
407 serializeForm : function(form){
408 return Form.serialize(form.dom||form);
414 Ext.lib.Anim = function(){
417 easeOut: function(pos) {
418 return 1-Math.pow(1-pos,2);
420 easeIn: function(pos) {
421 return 1-Math.pow(1-pos,2);
424 var createAnim = function(cb, scope){
426 stop : function(skipToLast){
427 this.effect.cancel();
430 isAnimated : function(){
431 return this.effect.state == 'running';
434 proxyCallback : function(){
435 Ext.callback(cb, scope);
440 scroll : function(el, args, duration, easing, cb, scope){
441 // not supported so scroll immediately?
442 var anim = createAnim(cb, scope);
444 if(typeof args.scroll.to[0] == 'number'){
445 el.scrollLeft = args.scroll.to[0];
447 if(typeof args.scroll.to[1] == 'number'){
448 el.scrollTop = args.scroll.to[1];
450 anim.proxyCallback();
454 motion : function(el, args, duration, easing, cb, scope){
455 return this.run(el, args, duration, easing, cb, scope);
458 color : function(el, args, duration, easing, cb, scope){
459 return this.run(el, args, duration, easing, cb, scope);
462 run : function(el, args, duration, easing, cb, scope, type){
465 switch(k){ // scriptaculous doesn't support, so convert these
467 var by, pts, e = Ext.fly(el, '_animrun');
469 if(by = args.points.by){
471 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
473 pts = e.translatePoints(args.points.to);
475 o.left = pts.left+'px';
476 o.top = pts.top+'px';
479 o.width = args.width.to+'px';
482 o.height = args.height.to+'px';
485 o.opacity = String(args.opacity.to);
488 o[k] = String(args[k].to);
492 var anim = createAnim(cb, scope);
493 anim.effect = new Effect.Morph(Ext.id(el), {
495 afterFinish: anim.proxyCallback,
496 transition: easings[easing] || Effect.Transitions.linear,
505 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
508 libFlyweight = new Ext.Element.Flyweight();
510 libFlyweight.dom = el;
514 Ext.lib.Region = function(t, r, b, l) {
523 Ext.lib.Region.prototype = {
524 contains : function(region) {
525 return ( region.left >= this.left &&
526 region.right <= this.right &&
527 region.top >= this.top &&
528 region.bottom <= this.bottom );
532 getArea : function() {
533 return ( (this.bottom - this.top) * (this.right - this.left) );
536 intersect : function(region) {
537 var t = Math.max( this.top, region.top );
538 var r = Math.min( this.right, region.right );
539 var b = Math.min( this.bottom, region.bottom );
540 var l = Math.max( this.left, region.left );
542 if (b >= t && r >= l) {
543 return new Ext.lib.Region(t, r, b, l);
548 union : function(region) {
549 var t = Math.min( this.top, region.top );
550 var r = Math.max( this.right, region.right );
551 var b = Math.max( this.bottom, region.bottom );
552 var l = Math.min( this.left, region.left );
554 return new Ext.lib.Region(t, r, b, l);
557 constrainTo : function(r) {
558 this.top = this.top.constrain(r.top, r.bottom);
559 this.bottom = this.bottom.constrain(r.top, r.bottom);
560 this.left = this.left.constrain(r.left, r.right);
561 this.right = this.right.constrain(r.left, r.right);
565 adjust : function(t, l, b, r){
574 Ext.lib.Region.getRegion = function(el) {
575 var p = Ext.lib.Dom.getXY(el);
578 var r = p[0] + el.offsetWidth;
579 var b = p[1] + el.offsetHeight;
582 return new Ext.lib.Region(t, r, b, l);
585 Ext.lib.Point = function(x, y) {
586 if (Ext.isArray(x)) {
590 this.x = this.right = this.left = this[0] = x;
591 this.y = this.top = this.bottom = this[1] = y;
594 Ext.lib.Point.prototype = new Ext.lib.Region();
599 function fnCleanUp() {
600 var p = Function.prototype;
601 delete p.createSequence;
603 delete p.createDelegate;
604 delete p.createCallback;
605 delete p.createInterceptor;
607 window.detachEvent("onunload", fnCleanUp);
609 window.attachEvent("onunload", fnCleanUp);