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