3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">(function(){
11 version = Prototype.Version.split('.'),
12 mouseEnterSupported = (parseInt(version[0]) >= 2) || (parseInt(version[1]) >= 7) || (parseInt(version[2]) >= 1),
14 isXUL = Ext.isGecko ? function(node){
15 return Object.prototype.toString.call(node) == '[object XULElement]';
17 isTextNode = Ext.isGecko ? function(node){
19 return node.nodeType == 3;
25 return node.nodeType == 3;
27 elContains = function(parent, child) {
28 if(parent && parent.firstChild){
30 if(child === parent) {
34 child = child.parentNode;
36 // In FF if you mouseout an text input element
37 // thats inside a div sometimes it randomly throws
38 // Permission denied to get property HTMLDivElement.parentNode
39 // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
42 if(child && (child.nodeType != 1)) {
49 checkRelatedTarget = function(e) {
50 var related = Ext.lib.Event.getRelatedTarget(e);
51 return !(isXUL(related) || elContains(e.currentTarget,related));
55 getViewWidth : function(full){
56 return full ? this.getDocumentWidth() : this.getViewportWidth();
59 getViewHeight : function(full){
60 return full ? this.getDocumentHeight() : this.getViewportHeight();
63 getDocumentHeight: function() { // missing from prototype?
64 var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
65 return Math.max(scrollHeight, this.getViewportHeight());
68 getDocumentWidth: function() { // missing from prototype?
69 var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
70 return Math.max(scrollWidth, this.getViewportWidth());
73 getViewportHeight: function() { // missing from prototype?
74 var height = self.innerHeight;
75 var mode = document.compatMode;
77 if ( (mode || Ext.isIE) && !Ext.isOpera ) {
78 height = (mode == "CSS1Compat") ?
79 document.documentElement.clientHeight : // Standards
80 document.body.clientHeight; // Quirks
86 getViewportWidth: function() { // missing from prototype?
87 var width = self.innerWidth; // Safari
88 var mode = document.compatMode;
90 if (mode || Ext.isIE) { // IE, Gecko, Opera
91 width = (mode == "CSS1Compat") ?
92 document.documentElement.clientWidth : // Standards
93 document.body.clientWidth; // Quirks
98 isAncestor : function(p, c){ // missing from prototype?
101 if (!p || !c) {return false;}
103 if(p.contains && !Ext.isSafari) {
104 return p.contains(c);
105 }else if(p.compareDocumentPosition) {
106 return !!(p.compareDocumentPosition(c) & 16);
108 var parent = c.parentNode;
113 else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
116 parent = parent.parentNode;
122 getRegion : function(el){
123 return Ext.lib.Region.getRegion(el);
127 return this.getXY(el)[1];
131 return this.getXY(el)[0];
134 getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
135 var p, pe, b, scroll, bd = (document.body || document.documentElement);
142 if (el.getBoundingClientRect) {
143 b = el.getBoundingClientRect();
144 scroll = fly(document).getScroll();
145 return [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];
151 var hasAbsolute = fly(el).getStyle("position") == "absolute";
158 if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
165 var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
166 var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
173 if (p != el && pe.getStyle('overflow') != 'visible') {
181 if (Ext.isSafari && hasAbsolute) {
186 if (Ext.isGecko && !hasAbsolute) {
188 x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
189 y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
193 while (p && p != bd) {
194 if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
203 setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
204 el = Ext.fly(el, '_setXY');
206 var pts = el.translatePoints(xy);
208 el.dom.style.left = pts.left + "px";
211 el.dom.style.top = pts.top + "px";
215 setX : function(el, x){
216 this.setXY(el, [x, false]);
219 setY : function(el, y){
220 this.setXY(el, [false, y]);
225 getPageX : function(e){
226 return Event.pointerX(e.browserEvent || e);
229 getPageY : function(e){
230 return Event.pointerY(e.browserEvent || e);
234 e = e.browserEvent || e;
235 return [Event.pointerX(e), Event.pointerY(e)];
238 getTarget : function(e){
239 return Event.element(e.browserEvent || e);
242 resolveTextNode: function(node) {
243 return node && !isXUL(node) && isTextNode(node) ? node.parentNode : node;
246 getRelatedTarget: function(ev) { // missing from prototype?
247 ev = ev.browserEvent || ev;
248 var t = ev.relatedTarget;
250 if (ev.type == "mouseout") {
252 } else if (ev.type == "mouseover") {
257 return this.resolveTextNode(t);
260 on : function(el, eventName, fn){
261 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
262 var item = mouseCache[el.id] || (mouseCache[el.id] = {});
263 item[eventName] = fn;
264 fn = fn.createInterceptor(checkRelatedTarget);
265 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
267 Event.observe(el, eventName, fn, false);
270 un : function(el, eventName, fn){
271 if((eventName == 'mouseenter' || eventName == 'mouseleave') && !mouseEnterSupported){
272 var item = mouseCache[el.id],
273 ev = item && item[eventName];
277 delete item[eventName];
278 eventName = (eventName == 'mouseenter') ? 'mouseover' : 'mouseout';
281 Event.stopObserving(el, eventName, fn, false);
284 purgeElement : function(el){
288 preventDefault : function(e){ // missing from prototype?
289 e = e.browserEvent || e;
290 if(e.preventDefault) {
293 e.returnValue = false;
297 stopPropagation : function(e){ // missing from prototype?
298 e = e.browserEvent || e;
299 if(e.stopPropagation) {
302 e.cancelBubble = true;
306 stopEvent : function(e){
307 Event.stop(e.browserEvent || e);
310 onAvailable : function(id, fn, scope){ // no equiv
311 var start = new Date(), iid;
313 if(start.getElapsed() > 10000){
316 var el = document.getElementById(id);
319 fn.call(scope||window, el);
322 iid = setInterval(f, 50);
326 Ext.lib.Ajax = function(){
327 var createSuccess = function(cb){
328 return cb.success ? function(xhr){
329 cb.success.call(cb.scope||window, {
330 responseText: xhr.responseText,
331 responseXML : xhr.responseXML,
332 argument: cb.argument
336 var createFailure = function(cb){
337 return cb.failure ? function(xhr){
338 cb.failure.call(cb.scope||window, {
339 responseText: xhr.responseText,
340 responseXML : xhr.responseXML,
341 argument: cb.argument
346 request : function(method, uri, cb, data, options){
349 parameters: data || '',
351 onSuccess: createSuccess(cb),
352 onFailure: createFailure(cb)
355 var hs = options.headers;
357 o.requestHeaders = hs;
360 method = (method ? method : (options.method ? options.method : 'POST'));
361 if (!hs || !hs['Content-Type']){
362 o.contentType = 'text/xml';
364 o.postBody = options.xmlData;
367 if(options.jsonData){
368 method = (method ? method : (options.method ? options.method : 'POST'));
369 if (!hs || !hs['Content-Type']){
370 o.contentType = 'application/json';
372 o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
376 new Ajax.Request(uri, o);
379 formRequest : function(form, uri, cb, data, isUpload, sslUri){
380 new Ajax.Request(uri, {
381 method: Ext.getDom(form).method ||'POST',
382 parameters: Form.serialize(form)+(data?'&'+data:''),
384 onSuccess: createSuccess(cb),
385 onFailure: createFailure(cb)
389 isCallInProgress : function(trans){
393 abort : function(trans){
397 serializeForm : function(form){
398 return Form.serialize(form.dom||form);
404 Ext.lib.Anim = function(){
407 easeOut: function(pos) {
408 return 1-Math.pow(1-pos,2);
410 easeIn: function(pos) {
411 return 1-Math.pow(1-pos,2);
414 var createAnim = function(cb, scope){
416 stop : function(skipToLast){
417 this.effect.cancel();
420 isAnimated : function(){
421 return this.effect.state == 'running';
424 proxyCallback : function(){
425 Ext.callback(cb, scope);
430 scroll : function(el, args, duration, easing, cb, scope){
431 // not supported so scroll immediately?
432 var anim = createAnim(cb, scope);
434 if(typeof args.scroll.to[0] == 'number'){
435 el.scrollLeft = args.scroll.to[0];
437 if(typeof args.scroll.to[1] == 'number'){
438 el.scrollTop = args.scroll.to[1];
440 anim.proxyCallback();
444 motion : function(el, args, duration, easing, cb, scope){
445 return this.run(el, args, duration, easing, cb, scope);
448 color : function(el, args, duration, easing, cb, scope){
449 return this.run(el, args, duration, easing, cb, scope);
452 run : function(el, args, duration, easing, cb, scope, type){
455 switch(k){ // scriptaculous doesn't support, so convert these
457 var by, pts, e = Ext.fly(el, '_animrun');
459 if(by = args.points.by){
461 pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
463 pts = e.translatePoints(args.points.to);
465 o.left = pts.left+'px';
466 o.top = pts.top+'px';
469 o.width = args.width.to+'px';
472 o.height = args.height.to+'px';
475 o.opacity = String(args.opacity.to);
478 o[k] = String(args[k].to);
482 var anim = createAnim(cb, scope);
483 anim.effect = new Effect.Morph(Ext.id(el), {
485 afterFinish: anim.proxyCallback,
486 transition: easings[easing] || Effect.Transitions.linear,
495 // all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
498 libFlyweight = new Ext.Element.Flyweight();
500 libFlyweight.dom = el;
504 Ext.lib.Region = function(t, r, b, l) {
513 Ext.lib.Region.prototype = {
514 contains : function(region) {
515 return ( region.left >= this.left &&
516 region.right <= this.right &&
517 region.top >= this.top &&
518 region.bottom <= this.bottom );
522 getArea : function() {
523 return ( (this.bottom - this.top) * (this.right - this.left) );
526 intersect : function(region) {
527 var t = Math.max( this.top, region.top );
528 var r = Math.min( this.right, region.right );
529 var b = Math.min( this.bottom, region.bottom );
530 var l = Math.max( this.left, region.left );
532 if (b >= t && r >= l) {
533 return new Ext.lib.Region(t, r, b, l);
538 union : function(region) {
539 var t = Math.min( this.top, region.top );
540 var r = Math.max( this.right, region.right );
541 var b = Math.max( this.bottom, region.bottom );
542 var l = Math.min( this.left, region.left );
544 return new Ext.lib.Region(t, r, b, l);
547 constrainTo : function(r) {
548 this.top = this.top.constrain(r.top, r.bottom);
549 this.bottom = this.bottom.constrain(r.top, r.bottom);
550 this.left = this.left.constrain(r.left, r.right);
551 this.right = this.right.constrain(r.left, r.right);
555 adjust : function(t, l, b, r){
564 Ext.lib.Region.getRegion = function(el) {
565 var p = Ext.lib.Dom.getXY(el);
568 var r = p[0] + el.offsetWidth;
569 var b = p[1] + el.offsetHeight;
572 return new Ext.lib.Region(t, r, b, l);
575 Ext.lib.Point = function(x, y) {
576 if (Ext.isArray(x)) {
580 this.x = this.right = this.left = this[0] = x;
581 this.y = this.top = this.bottom = this[1] = y;
584 Ext.lib.Point.prototype = new Ext.lib.Region();
589 function fnCleanUp() {
590 var p = Function.prototype;
591 delete p.createSequence;
593 delete p.createDelegate;
594 delete p.createCallback;
595 delete p.createInterceptor;
597 window.detachEvent("onunload", fnCleanUp);
599 window.attachEvent("onunload", fnCleanUp);