source: trunk/web/addons/job_monarch/lib/extjs/source/adapter/prototype-bridge.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 16.1 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9(function(){
10
11var libFlyweight;
12
13Ext.lib.Dom = {
14    getViewWidth : function(full){
15        return full ? this.getDocumentWidth() : this.getViewportWidth();
16    },
17
18    getViewHeight : function(full){
19        return full ? this.getDocumentHeight() : this.getViewportHeight();
20    },
21
22    getDocumentHeight: function() { // missing from prototype?
23        var scrollHeight = (document.compatMode != "CSS1Compat") ? document.body.scrollHeight : document.documentElement.scrollHeight;
24        return Math.max(scrollHeight, this.getViewportHeight());
25    },
26
27    getDocumentWidth: function() { // missing from prototype?
28        var scrollWidth = (document.compatMode != "CSS1Compat") ? document.body.scrollWidth : document.documentElement.scrollWidth;
29        return Math.max(scrollWidth, this.getViewportWidth());
30    },
31
32    getViewportHeight: function() { // missing from prototype?
33        var height = self.innerHeight;
34        var mode = document.compatMode;
35
36        if ( (mode || Ext.isIE) && !Ext.isOpera ) {
37            height = (mode == "CSS1Compat") ?
38                    document.documentElement.clientHeight : // Standards
39                    document.body.clientHeight; // Quirks
40        }
41
42        return height;
43    },
44
45    getViewportWidth: function() { // missing from prototype?
46        var width = self.innerWidth;  // Safari
47        var mode = document.compatMode;
48
49        if (mode || Ext.isIE) { // IE, Gecko, Opera
50            width = (mode == "CSS1Compat") ?
51                    document.documentElement.clientWidth : // Standards
52                    document.body.clientWidth; // Quirks
53        }
54        return width;
55    },
56
57    isAncestor : function(p, c){ // missing from prototype?
58        p = Ext.getDom(p);
59        c = Ext.getDom(c);
60        if (!p || !c) {return false;}
61
62        if(p.contains && !Ext.isSafari) {
63            return p.contains(c);
64        }else if(p.compareDocumentPosition) {
65            return !!(p.compareDocumentPosition(c) & 16);
66        }else{
67            var parent = c.parentNode;
68            while (parent) {
69                if (parent == p) {
70                    return true;
71                }
72                else if (!parent.tagName || parent.tagName.toUpperCase() == "HTML") {
73                    return false;
74                }
75                parent = parent.parentNode;
76            }
77            return false;
78        }
79    },
80
81    getRegion : function(el){
82        return Ext.lib.Region.getRegion(el);
83    },
84
85    getY : function(el){
86        return this.getXY(el)[1];
87    },
88
89    getX : function(el){
90        return this.getXY(el)[0];
91    },
92
93    getXY : function(el){ // this initially used Position.cumulativeOffset but it is not accurate enough
94        var p, pe, b, scroll, bd = (document.body || document.documentElement);
95        el = Ext.getDom(el);
96
97        if(el == bd){
98            return [0, 0];
99        }
100
101        if (el.getBoundingClientRect) {
102            b = el.getBoundingClientRect();
103            scroll = fly(document).getScroll();
104            return [b.left + scroll.left, b.top + scroll.top];
105        }
106        var x = 0, y = 0;
107
108        p = el;
109
110        var hasAbsolute = fly(el).getStyle("position") == "absolute";
111
112        while (p) {
113
114            x += p.offsetLeft;
115            y += p.offsetTop;
116
117            if (!hasAbsolute && fly(p).getStyle("position") == "absolute") {
118                hasAbsolute = true;
119            }
120
121            if (Ext.isGecko) {
122                pe = fly(p);
123
124                var bt = parseInt(pe.getStyle("borderTopWidth"), 10) || 0;
125                var bl = parseInt(pe.getStyle("borderLeftWidth"), 10) || 0;
126
127
128                x += bl;
129                y += bt;
130
131
132                if (p != el && pe.getStyle('overflow') != 'visible') {
133                    x += bl;
134                    y += bt;
135                }
136            }
137            p = p.offsetParent;
138        }
139
140        if (Ext.isSafari && hasAbsolute) {
141            x -= bd.offsetLeft;
142            y -= bd.offsetTop;
143        }
144
145        if (Ext.isGecko && !hasAbsolute) {
146            var dbd = fly(bd);
147            x += parseInt(dbd.getStyle("borderLeftWidth"), 10) || 0;
148            y += parseInt(dbd.getStyle("borderTopWidth"), 10) || 0;
149        }
150
151        p = el.parentNode;
152        while (p && p != bd) {
153            if (!Ext.isOpera || (p.tagName != 'TR' && fly(p).getStyle("display") != "inline")) {
154                x -= p.scrollLeft;
155                y -= p.scrollTop;
156            }
157            p = p.parentNode;
158        }
159        return [x, y];
160    },
161
162    setXY : function(el, xy){ // this initially used Position.cumulativeOffset but it is not accurate enough
163        el = Ext.fly(el, '_setXY');
164        el.position();
165        var pts = el.translatePoints(xy);
166        if(xy[0] !== false){
167            el.dom.style.left = pts.left + "px";
168        }
169        if(xy[1] !== false){
170            el.dom.style.top = pts.top + "px";
171        }
172    },
173
174    setX : function(el, x){
175        this.setXY(el, [x, false]);
176    },
177
178    setY : function(el, y){
179        this.setXY(el, [false, y]);
180    }
181};
182
183Ext.lib.Event = {
184    getPageX : function(e){
185        return Event.pointerX(e.browserEvent || e);
186    },
187
188    getPageY : function(e){
189        return Event.pointerY(e.browserEvent || e);
190    },
191
192    getXY : function(e){
193        e = e.browserEvent || e;
194        return [Event.pointerX(e), Event.pointerY(e)];
195    },
196
197    getTarget : function(e){
198        return Event.element(e.browserEvent || e);
199    },
200
201    resolveTextNode: function(node) {
202        if (node && 3 == node.nodeType) {
203            return node.parentNode;
204        } else {
205            return node;
206        }
207    },
208
209    getRelatedTarget: function(ev) { // missing from prototype?
210        ev = ev.browserEvent || ev;
211        var t = ev.relatedTarget;
212        if (!t) {
213            if (ev.type == "mouseout") {
214                t = ev.toElement;
215            } else if (ev.type == "mouseover") {
216                t = ev.fromElement;
217            }
218        }
219
220        return this.resolveTextNode(t);
221    },
222
223    on : function(el, eventName, fn){
224        Event.observe(el, eventName, fn, false);
225    },
226
227    un : function(el, eventName, fn){
228        Event.stopObserving(el, eventName, fn, false);
229    },
230
231    purgeElement : function(el){
232        // no equiv?
233    },
234
235    preventDefault : function(e){   // missing from prototype?
236        e = e.browserEvent || e;
237        if(e.preventDefault) {
238            e.preventDefault();
239        } else {
240            e.returnValue = false;
241        }
242    },
243
244    stopPropagation : function(e){   // missing from prototype?
245        e = e.browserEvent || e;
246        if(e.stopPropagation) {
247            e.stopPropagation();
248        } else {
249            e.cancelBubble = true;
250        }
251    },
252
253    stopEvent : function(e){
254        Event.stop(e.browserEvent || e);
255    },
256
257    onAvailable : function(id, fn, scope){  // no equiv
258        var start = new Date(), iid;
259        var f = function(){
260            if(start.getElapsed() > 10000){
261                clearInterval(iid);
262            }
263            var el = document.getElementById(id);
264            if(el){
265                clearInterval(iid);
266                fn.call(scope||window, el);
267            }
268        };
269        iid = setInterval(f, 50);
270    }
271};
272
273Ext.lib.Ajax = function(){
274    var createSuccess = function(cb){
275         return cb.success ? function(xhr){
276            cb.success.call(cb.scope||window, {
277                responseText: xhr.responseText,
278                responseXML : xhr.responseXML,
279                argument: cb.argument
280            });
281         } : Ext.emptyFn;
282    };
283    var createFailure = function(cb){
284         return cb.failure ? function(xhr){
285            cb.failure.call(cb.scope||window, {
286                responseText: xhr.responseText,
287                responseXML : xhr.responseXML,
288                argument: cb.argument
289            });
290         } : Ext.emptyFn;
291    };
292    return {
293        request : function(method, uri, cb, data, options){
294            var o = {
295                method: method,
296                parameters: data || '',
297                timeout: cb.timeout,
298                onSuccess: createSuccess(cb),
299                onFailure: createFailure(cb)
300            };
301            if(options){
302                var hs = options.headers;
303                if(hs){
304                    o.requestHeaders = hs;
305                }
306                if(options.xmlData){
307                    method = (method ? method : (options.method ? options.method : 'POST'));
308                    if (!hs || !hs['Content-Type']){
309                        o.contentType = 'text/xml';
310                    }
311                    o.postBody = options.xmlData;
312                    delete o.parameters;
313                }
314                if(options.jsonData){
315                    method = (method ? method : (options.method ? options.method : 'POST'));
316                    if (!hs || !hs['Content-Type']){
317                        o.contentType = 'application/json';
318                    }
319                    o.postBody = typeof options.jsonData == 'object' ? Ext.encode(options.jsonData) : options.jsonData;
320                    delete o.parameters;
321                }
322            }
323            new Ajax.Request(uri, o);
324        },
325
326        formRequest : function(form, uri, cb, data, isUpload, sslUri){
327            new Ajax.Request(uri, {
328                method: Ext.getDom(form).method ||'POST',
329                parameters: Form.serialize(form)+(data?'&'+data:''),
330                timeout: cb.timeout,
331                onSuccess: createSuccess(cb),
332                onFailure: createFailure(cb)
333            });
334        },
335
336        isCallInProgress : function(trans){
337            return false;
338        },
339
340        abort : function(trans){
341            return false;
342        },
343       
344        serializeForm : function(form){
345            return Form.serialize(form.dom||form);
346        }
347    };
348}();
349
350
351Ext.lib.Anim = function(){
352   
353    var easings = {
354        easeOut: function(pos) {
355            return 1-Math.pow(1-pos,2);
356        },
357        easeIn: function(pos) {
358            return 1-Math.pow(1-pos,2);
359        }
360    };
361    var createAnim = function(cb, scope){
362        return {
363            stop : function(skipToLast){
364                this.effect.cancel();
365            },
366
367            isAnimated : function(){
368                return this.effect.state == 'running';
369            },
370
371            proxyCallback : function(){
372                Ext.callback(cb, scope);
373            }
374        };
375    };
376    return {
377        scroll : function(el, args, duration, easing, cb, scope){
378            // not supported so scroll immediately?
379            var anim = createAnim(cb, scope);
380            el = Ext.getDom(el);
381            if(typeof args.scroll.to[0] == 'number'){
382                el.scrollLeft = args.scroll.to[0];
383            }
384            if(typeof args.scroll.to[1] == 'number'){
385                el.scrollTop = args.scroll.to[1];
386            }
387            anim.proxyCallback();
388            return anim;
389        },
390
391        motion : function(el, args, duration, easing, cb, scope){
392            return this.run(el, args, duration, easing, cb, scope);
393        },
394
395        color : function(el, args, duration, easing, cb, scope){
396            return this.run(el, args, duration, easing, cb, scope);
397        },
398
399        run : function(el, args, duration, easing, cb, scope, type){
400            var o = {};
401            for(var k in args){
402                switch(k){   // scriptaculous doesn't support, so convert these
403                    case 'points':
404                        var by, pts, e = Ext.fly(el, '_animrun');
405                        e.position();
406                        if(by = args.points.by){
407                            var xy = e.getXY();
408                            pts = e.translatePoints([xy[0]+by[0], xy[1]+by[1]]);
409                        }else{
410                            pts = e.translatePoints(args.points.to);
411                        }
412                        o.left = pts.left+'px';
413                        o.top = pts.top+'px';
414                    break;
415                    case 'width':
416                        o.width = args.width.to+'px';
417                    break;
418                    case 'height':
419                        o.height = args.height.to+'px';
420                    break;
421                    case 'opacity':
422                        o.opacity = String(args.opacity.to);
423                    break;
424                    default:
425                        o[k] = String(args[k].to);
426                    break;
427                }
428            }
429            var anim = createAnim(cb, scope);
430            anim.effect = new Effect.Morph(Ext.id(el), {
431                duration: duration,
432                afterFinish: anim.proxyCallback,
433                transition: easings[easing] || Effect.Transitions.linear,
434                style: o
435            });
436            return anim;
437        }
438    };
439}();
440
441
442// all lib flyweight calls use their own flyweight to prevent collisions with developer flyweights
443function fly(el){
444    if(!libFlyweight){
445        libFlyweight = new Ext.Element.Flyweight();
446    }
447    libFlyweight.dom = el;
448    return libFlyweight;
449}
450   
451Ext.lib.Region = function(t, r, b, l) {
452    this.top = t;
453    this[1] = t;
454    this.right = r;
455    this.bottom = b;
456    this.left = l;
457    this[0] = l;
458};
459
460Ext.lib.Region.prototype = {
461    contains : function(region) {
462        return ( region.left   >= this.left   &&
463                 region.right  <= this.right  &&
464                 region.top    >= this.top    &&
465                 region.bottom <= this.bottom    );
466
467    },
468
469    getArea : function() {
470        return ( (this.bottom - this.top) * (this.right - this.left) );
471    },
472
473    intersect : function(region) {
474        var t = Math.max( this.top,    region.top    );
475        var r = Math.min( this.right,  region.right  );
476        var b = Math.min( this.bottom, region.bottom );
477        var l = Math.max( this.left,   region.left   );
478
479        if (b >= t && r >= l) {
480            return new Ext.lib.Region(t, r, b, l);
481        } else {
482            return null;
483        }
484    },
485    union : function(region) {
486        var t = Math.min( this.top,    region.top    );
487        var r = Math.max( this.right,  region.right  );
488        var b = Math.max( this.bottom, region.bottom );
489        var l = Math.min( this.left,   region.left   );
490
491        return new Ext.lib.Region(t, r, b, l);
492    },
493
494    constrainTo : function(r) {
495            this.top = this.top.constrain(r.top, r.bottom);
496            this.bottom = this.bottom.constrain(r.top, r.bottom);
497            this.left = this.left.constrain(r.left, r.right);
498            this.right = this.right.constrain(r.left, r.right);
499            return this;
500    },
501
502    adjust : function(t, l, b, r){
503        this.top += t;
504        this.left += l;
505        this.right += r;
506        this.bottom += b;
507        return this;
508    }
509};
510
511Ext.lib.Region.getRegion = function(el) {
512    var p = Ext.lib.Dom.getXY(el);
513
514    var t = p[1];
515    var r = p[0] + el.offsetWidth;
516    var b = p[1] + el.offsetHeight;
517    var l = p[0];
518
519    return new Ext.lib.Region(t, r, b, l);
520};
521
522Ext.lib.Point = function(x, y) {
523   if (Ext.isArray(x)) {
524      y = x[1];
525      x = x[0];
526   }
527    this.x = this.right = this.left = this[0] = x;
528    this.y = this.top = this.bottom = this[1] = y;
529};
530
531Ext.lib.Point.prototype = new Ext.lib.Region();
532
533
534// prevent IE leaks
535if(Ext.isIE) {
536    function fnCleanUp() {
537        var p = Function.prototype;
538        delete p.createSequence;
539        delete p.defer;
540        delete p.createDelegate;
541        delete p.createCallback;
542        delete p.createInterceptor;
543
544        window.detachEvent("onunload", fnCleanUp);
545    }
546    window.attachEvent("onunload", fnCleanUp);
547}
548})();
Note: See TracBrowser for help on using the repository browser.