~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/core/core/EventManager.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.EventManager
 
11
 * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
 
12
 * several useful events directly.
 
13
 * See {@link Ext.EventObject} for more details on normalized event objects.
 
14
 * @singleton
 
15
 */
 
16
Ext.EventManager = function(){
 
17
    var docReadyEvent, 
 
18
        docReadyProcId, 
 
19
        docReadyState = false,          
 
20
        E = Ext.lib.Event,
 
21
        D = Ext.lib.Dom,
 
22
        DOC = document,
 
23
        WINDOW = window,
 
24
        IEDEFERED = "ie-deferred-loader",
 
25
        DOMCONTENTLOADED = "DOMContentLoaded",
 
26
        elHash = {},
 
27
        propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/;
 
28
 
 
29
    /// There is some jquery work around stuff here that isn't needed in Ext Core.
 
30
    function addListener(el, ename, fn, wrap, scope){       
 
31
        var id = Ext.id(el),
 
32
                es = elHash[id] = elHash[id] || {};             
 
33
       
 
34
        (es[ename] = es[ename] || []).push([fn, wrap, scope]);
 
35
        E.on(el, ename, wrap);
 
36
 
 
37
        // this is a workaround for jQuery and should somehow be removed from Ext Core in the future
 
38
        // without breaking ExtJS.
 
39
        if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery
 
40
                var args = ["DOMMouseScroll", wrap, false];
 
41
                el.addEventListener.apply(el, args);
 
42
            E.on(window, 'unload', function(){
 
43
                    el.removeEventListener.apply(el, args);                
 
44
            });
 
45
        }
 
46
        if(ename == "mousedown" && el == document){ // fix stopped mousedowns on the document
 
47
            Ext.EventManager.stoppedMouseDownEvent.addListener(wrap);
 
48
        }
 
49
    };
 
50
    
 
51
    function fireDocReady(){
 
52
        if(!docReadyState){            
 
53
            Ext.isReady = docReadyState = true;
 
54
            if(docReadyProcId){
 
55
                clearInterval(docReadyProcId);
 
56
            }
 
57
            if(Ext.isGecko || Ext.isOpera) {
 
58
                DOC.removeEventListener(DOMCONTENTLOADED, fireDocReady, false);
 
59
            }
 
60
            if(Ext.isIE){
 
61
                var defer = DOC.getElementById(IEDEFERED);
 
62
                if(defer){
 
63
                    defer.onreadystatechange = null;
 
64
                    defer.parentNode.removeChild(defer);
 
65
                }
 
66
            }
 
67
            if(docReadyEvent){
 
68
                docReadyEvent.fire();
 
69
                docReadyEvent.clearListeners();
 
70
            }
 
71
        }
 
72
    };
 
73
 
 
74
    function initDocReady(){
 
75
            var COMPLETE = "complete";
 
76
                
 
77
        docReadyEvent = new Ext.util.Event();
 
78
        if (Ext.isGecko || Ext.isOpera) {
 
79
            DOC.addEventListener(DOMCONTENTLOADED, fireDocReady, false);
 
80
        } else if (Ext.isIE){
 
81
            DOC.write("<s"+'cript id=' + IEDEFERED + ' defer="defer" src="/'+'/:"></s'+"cript>");            
 
82
            DOC.getElementById(IEDEFERED).onreadystatechange = function(){
 
83
                if(this.readyState == COMPLETE){
 
84
                    fireDocReady();
 
85
                }
 
86
            };
 
87
        } else if (Ext.isWebKit){
 
88
            docReadyProcId = setInterval(function(){                
 
89
                if(DOC.readyState == COMPLETE) {
 
90
                    fireDocReady();
 
91
                 }
 
92
            }, 10);
 
93
        }
 
94
        // no matter what, make sure it fires on load
 
95
        E.on(WINDOW, "load", fireDocReady);
 
96
    };
 
97
 
 
98
    function createTargeted(h, o){
 
99
        return function(){
 
100
                var args = Ext.toArray(arguments);
 
101
            if(o.target == Ext.EventObject.setEvent(args[0]).target){
 
102
                h.apply(this, args);
 
103
            }
 
104
        };
 
105
    };    
 
106
    
 
107
    function createBuffered(h, o){
 
108
        var task = new Ext.util.DelayedTask(h);
 
109
        return function(e){
 
110
            // create new event object impl so new events don't wipe out properties            
 
111
            task.delay(o.buffer, h, null, [new Ext.EventObjectImpl(e)]);
 
112
        };
 
113
    };
 
114
 
 
115
    function createSingle(h, el, ename, fn, scope){
 
116
        return function(e){
 
117
            Ext.EventManager.removeListener(el, ename, fn, scope);
 
118
            h(e);
 
119
        };
 
120
    };
 
121
 
 
122
    function createDelayed(h, o){
 
123
        return function(e){
 
124
            // create new event object impl so new events don't wipe out properties   
 
125
            e = new Ext.EventObjectImpl(e);
 
126
            setTimeout(function(){
 
127
                h(e);
 
128
            }, o.delay || 10);
 
129
        };
 
130
    };
 
131
 
 
132
    function listen(element, ename, opt, fn, scope){
 
133
        var o = !Ext.isObject(opt) ? {} : opt,
 
134
                el = Ext.getDom(element);
 
135
                
 
136
        fn = fn || o.fn; 
 
137
        scope = scope || o.scope;
 
138
        
 
139
        if(!el){
 
140
            throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
 
141
        }
 
142
        function h(e){
 
143
            // prevent errors while unload occurring
 
144
            if(!Ext){// !window[xname]){  ==> can't we do this? 
 
145
                return;
 
146
            }
 
147
            e = Ext.EventObject.setEvent(e);
 
148
            var t;
 
149
            if (o.delegate) {
 
150
                if(!(t = e.getTarget(o.delegate, el))){
 
151
                    return;
 
152
                }
 
153
            } else {
 
154
                t = e.target;
 
155
            }            
 
156
            if (o.stopEvent) {
 
157
                e.stopEvent();
 
158
            }
 
159
            if (o.preventDefault) {
 
160
               e.preventDefault();
 
161
            }
 
162
            if (o.stopPropagation) {
 
163
                e.stopPropagation();
 
164
            }
 
165
            if (o.normalized) {
 
166
                e = e.browserEvent;
 
167
            }
 
168
            
 
169
            fn.call(scope || el, e, t, o);
 
170
        };
 
171
        if(o.target){
 
172
            h = createTargeted(h, o);
 
173
        }
 
174
        if(o.delay){
 
175
            h = createDelayed(h, o);
 
176
        }
 
177
        if(o.single){
 
178
            h = createSingle(h, el, ename, fn, scope);
 
179
        }
 
180
        if(o.buffer){
 
181
            h = createBuffered(h, o);
 
182
        }
 
183
 
 
184
        addListener(el, ename, fn, h, scope);
 
185
        return h;
 
186
    };
 
187
 
 
188
    var pub = {
 
189
            /**
 
190
             * Appends an event handler to an element.  The shorthand version {@link #on} is equivalent.  Typically you will
 
191
             * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
 
192
             * @param {String/HTMLElement} el The html element or id to assign the event handler to
 
193
             * @param {String} eventName The type of event to listen for
 
194
             * @param {Function} handler The handler function the event invokes This function is passed
 
195
             * the following parameters:<ul>
 
196
             * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
 
197
             * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
 
198
             * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
 
199
             * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
 
200
             * </ul>
 
201
             * @param {Object} scope (optional) The scope in which to execute the handler
 
202
             * function (the handler function's "this" context)
 
203
             * @param {Object} options (optional) An object containing handler configuration properties.
 
204
             * This may contain any of the following properties:<ul>
 
205
             * <li>scope {Object} : The scope in which to execute the handler function. The handler function's "this" context.</li>
 
206
             * <li>delegate {String} : A simple selector to filter the target or look for a descendant of the target</li>
 
207
             * <li>stopEvent {Boolean} : True to stop the event. That is stop propagation, and prevent the default action.</li>
 
208
             * <li>preventDefault {Boolean} : True to prevent the default action</li>
 
209
             * <li>stopPropagation {Boolean} : True to prevent event propagation</li>
 
210
             * <li>normalized {Boolean} : False to pass a browser event to the handler function instead of an Ext.EventObject</li>
 
211
             * <li>delay {Number} : The number of milliseconds to delay the invocation of the handler after te event fires.</li>
 
212
             * <li>single {Boolean} : True to add a handler to handle just the next firing of the event, and then remove itself.</li>
 
213
             * <li>buffer {Number} : Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
 
214
             * by the specified number of milliseconds. If the event fires again within that time, the original
 
215
             * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
 
216
             * <li>target {Element} : Only call the handler if the event was fired on the target Element, <i>not</i>
 
217
             * if the event was bubbled up from a child node.</li>
 
218
             * </ul><br>
 
219
             * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
 
220
             */
 
221
                addListener : function(element, eventName, fn, scope, options){                                              
 
222
            if(Ext.isObject(eventName)){                
 
223
                    var o = eventName, e, val;
 
224
                for(e in o){
 
225
                        val = o[e];
 
226
                    if(!propRe.test(e)){                                                 
 
227
                            if(Ext.isFunction(val)){
 
228
                                // shared options
 
229
                                listen(element, e, o, val, o.scope);
 
230
                            }else{
 
231
                                // individual options
 
232
                                listen(element, e, val);
 
233
                            }
 
234
                    }
 
235
                }
 
236
            } else {
 
237
                listen(element, eventName, options, fn, scope);
 
238
                }
 
239
        },
 
240
        
 
241
        /**
 
242
         * Removes an event handler from an element.  The shorthand version {@link #un} is equivalent.  Typically
 
243
         * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
 
244
         * @param {String/HTMLElement} el The id or html element from which to remove the event
 
245
         * @param {String} eventName The type of event
 
246
         * @param {Function} fn The handler function to remove
 
247
         */
 
248
        removeListener : function(element, eventName, fn, scope){            
 
249
            var el = Ext.getDom(element),
 
250
                id = Ext.id(el),
 
251
                    wrap;      
 
252
                
 
253
                Ext.each((elHash[id] || {})[eventName], function (v,i,a) {
 
254
                            if (Ext.isArray(v) && v[0] == fn && (!scope || v[2] == scope)) {                                                    
 
255
                                E.un(el, eventName, wrap = v[1]);
 
256
                                a.splice(i,1);
 
257
                                return false;                           
 
258
                        }
 
259
                });     
 
260
 
 
261
            // jQuery workaround that should be removed from Ext Core
 
262
                if(eventName == "mousewheel" && el.addEventListener && wrap){
 
263
                    el.removeEventListener("DOMMouseScroll", wrap, false);
 
264
                }
 
265
                        
 
266
                if(eventName == "mousedown" && el == DOC && wrap){ // fix stopped mousedowns on the document
 
267
                    Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap);
 
268
                }
 
269
        },
 
270
        
 
271
        /**
 
272
         * Removes all event handers from an element.  Typically you will use {@link Ext.Element#removeAllListeners}
 
273
         * directly on an Element in favor of calling this version.
 
274
         * @param {String/HTMLElement} el The id or html element from which to remove the event
 
275
         */
 
276
        removeAll : function(el){
 
277
                var id = Ext.id(el = Ext.getDom(el)), 
 
278
                                es = elHash[id],                                
 
279
                                ename;
 
280
               
 
281
                for(ename in es){
 
282
                    if(es.hasOwnProperty(ename)){                           
 
283
                        Ext.each(es[ename], function(v) {
 
284
                            E.un(el, ename, v.wrap);                    
 
285
                        });
 
286
                    }            
 
287
                }
 
288
                elHash[id] = null;       
 
289
        },
 
290
 
 
291
        /**
 
292
         * Fires when the document is ready (before onload and before images are loaded). Can be
 
293
         * accessed shorthanded as Ext.onReady().
 
294
         * @param {Function} fn The method the event invokes
 
295
         * @param {Object} scope (optional) An object that becomes the scope of the handler
 
296
         * @param {boolean} options (optional) An object containing standard {@link #addListener} options
 
297
         */
 
298
        onDocumentReady : function(fn, scope, options){
 
299
            if(docReadyState){ // if it already fired
 
300
                docReadyEvent.addListener(fn, scope, options);
 
301
                docReadyEvent.fire();
 
302
                docReadyEvent.clearListeners();               
 
303
            } else {
 
304
                if(!docReadyEvent) initDocReady();
 
305
                options = options || {};
 
306
                    options.delay = options.delay || 1;             
 
307
                    docReadyEvent.addListener(fn, scope, options);
 
308
            }
 
309
        },
 
310
        
 
311
        elHash : elHash   
 
312
    };
 
313
     /**
 
314
     * Appends an event handler to an element.  Shorthand for {@link #addListener}.
 
315
     * @param {String/HTMLElement} el The html element or id to assign the event handler to
 
316
     * @param {String} eventName The type of event to listen for
 
317
     * @param {Function} handler The handler function the event invokes
 
318
     * @param {Object} scope (optional) The scope in which to execute the handler
 
319
     * function (the handler function's "this" context)
 
320
     * @param {Object} options (optional) An object containing standard {@link #addListener} options
 
321
     * @member Ext.EventManager
 
322
     * @method on
 
323
     */
 
324
    pub.on = pub.addListener;
 
325
    /**
 
326
     * Removes an event handler from an element.  Shorthand for {@link #removeListener}.
 
327
     * @param {String/HTMLElement} el The id or html element from which to remove the event
 
328
     * @param {String} eventName The type of event
 
329
     * @param {Function} fn The handler function to remove
 
330
     * @return {Boolean} True if a listener was actually removed, else false
 
331
     * @member Ext.EventManager
 
332
     * @method un
 
333
     */
 
334
    pub.un = pub.removeListener;
 
335
 
 
336
    pub.stoppedMouseDownEvent = new Ext.util.Event();
 
337
    return pub;
 
338
}();
 
339
/**
 
340
  * Fires when the document is ready (before onload and before images are loaded).  Shorthand of {@link Ext.EventManager#onDocumentReady}.
 
341
  * @param {Function} fn The method the event invokes
 
342
  * @param {Object} scope An object that becomes the scope of the handler
 
343
  * @param {boolean} options (optional) An object containing standard {@link #addListener} options
 
344
  * @member Ext
 
345
  * @method onReady
 
346
 */
 
347
Ext.onReady = Ext.EventManager.onDocumentReady;
 
348
 
 
349
 
 
350
//Initialize doc classes
 
351
(function(){
 
352
    
 
353
    var initExtCss = function(){
 
354
        // find the body element
 
355
        var bd = document.body || document.getElementsByTagName('body')[0];
 
356
        if(!bd){ return false; }
 
357
        var cls = [' ',
 
358
                Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : (Ext.isIE7 ? 'ext-ie7' : 'ext-ie8'))
 
359
                : Ext.isGecko ? "ext-gecko " + (Ext.isGecko2 ? 'ext-gecko2' : 'ext-gecko3')
 
360
                : Ext.isOpera ? "ext-opera"
 
361
                : Ext.isWebKit ? "ext-webkit" : ""];
 
362
 
 
363
        if(Ext.isSafari){
 
364
            cls.push("ext-safari " + (Ext.isSafari2 ? 'ext-safari2' : (Ext.isSafari3 ? 'ext-safari3' : 'ext-safari4')));
 
365
        }else if(Ext.isChrome){
 
366
            cls.push("ext-chrome");
 
367
        }
 
368
 
 
369
        if(Ext.isMac){
 
370
            cls.push("ext-mac");
 
371
        }
 
372
        if(Ext.isLinux){
 
373
            cls.push("ext-linux");
 
374
        }
 
375
        if(Ext.isBorderBox){
 
376
            cls.push('ext-border-box');
 
377
        }
 
378
        if(Ext.isStrict){ // add to the parent to allow for selectors like ".ext-strict .ext-ie"
 
379
            var p = bd.parentNode;
 
380
            if(p){
 
381
                p.className += ' ext-strict';
 
382
            }
 
383
        }
 
384
        bd.className += cls.join(' ');
 
385
        return true;
 
386
    }
 
387
 
 
388
    if(!initExtCss()){
 
389
        Ext.onReady(initExtCss);
 
390
    }
 
391
})();
 
392
 
 
393
 
 
394
/**
 
395
 * @class Ext.EventObject
 
396
 * Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject 
 
397
 * wraps the browser's native event-object normalizing cross-browser differences,
 
398
 * such as which mouse button is clicked, keys pressed, mechanisms to stop
 
399
 * event-propagation along with a method to prevent default actions from taking place.
 
400
 * <p>For example:</p>
 
401
 * <pre><code>
 
402
function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
 
403
    e.preventDefault();
 
404
    var target = e.getTarget(); // same as t (the target HTMLElement)
 
405
    ...
 
406
}
 
407
var myDiv = {@link Ext#get Ext.get}("myDiv");  // get reference to an {@link Ext.Element}
 
408
myDiv.on(         // 'on' is shorthand for addListener
 
409
    "click",      // perform an action on click of myDiv
 
410
    handleClick   // reference to the action handler
 
411
);  
 
412
// other methods to do the same:
 
413
Ext.EventManager.on("myDiv", 'click', handleClick);
 
414
Ext.EventManager.addListener("myDiv", 'click', handleClick);
 
415
 </code></pre>
 
416
 * @singleton
 
417
 */
 
418
Ext.EventObject = function(){
 
419
    var E = Ext.lib.Event,
 
420
        // safari keypress events for special keys return bad keycodes
 
421
        safariKeys = {
 
422
                3 : 13, // enter
 
423
                63234 : 37, // left
 
424
                63235 : 39, // right
 
425
                63232 : 38, // up
 
426
                63233 : 40, // down
 
427
                63276 : 33, // page up
 
428
                63277 : 34, // page down
 
429
                63272 : 46, // delete
 
430
                63273 : 36, // home
 
431
                63275 : 35  // end
 
432
        },
 
433
        // normalize button clicks
 
434
        btnMap = Ext.isIE ? {1:0,4:1,2:2} :
 
435
                (Ext.isWebKit ? {1:0,2:1,3:2} : {0:0,1:1,2:2});
 
436
 
 
437
    Ext.EventObjectImpl = function(e){
 
438
        if(e){
 
439
            this.setEvent(e.browserEvent || e);
 
440
        }
 
441
    };
 
442
 
 
443
    Ext.EventObjectImpl.prototype = {
 
444
           /** @private */
 
445
        setEvent : function(e){
 
446
                var me = this;
 
447
            if(e == me || (e && e.browserEvent)){ // already wrapped
 
448
                return e;
 
449
            }
 
450
            me.browserEvent = e;
 
451
            if(e){
 
452
                // normalize buttons
 
453
                me.button = e.button ? btnMap[e.button] : (e.which ? e.which - 1 : -1);
 
454
                if(e.type == 'click' && me.button == -1){
 
455
                    me.button = 0;
 
456
                }
 
457
                me.type = e.type;
 
458
                me.shiftKey = e.shiftKey;
 
459
                // mac metaKey behaves like ctrlKey
 
460
                me.ctrlKey = e.ctrlKey || e.metaKey;
 
461
                me.altKey = e.altKey;
 
462
                // in getKey these will be normalized for the mac
 
463
                me.keyCode = e.keyCode;
 
464
                me.charCode = e.charCode;
 
465
                // cache the target for the delayed and or buffered events
 
466
                me.target = E.getTarget(e);
 
467
                // same for XY
 
468
                me.xy = E.getXY(e);
 
469
            }else{
 
470
                me.button = -1;
 
471
                me.shiftKey = false;
 
472
                me.ctrlKey = false;
 
473
                me.altKey = false;
 
474
                me.keyCode = 0;
 
475
                me.charCode = 0;
 
476
                me.target = null;
 
477
                me.xy = [0, 0];
 
478
            }
 
479
            return me;
 
480
        },
 
481
 
 
482
        /**
 
483
         * Stop the event (preventDefault and stopPropagation)
 
484
         */
 
485
        stopEvent : function(){
 
486
                var me = this;
 
487
            if(me.browserEvent){
 
488
                if(me.browserEvent.type == 'mousedown'){
 
489
                    Ext.EventManager.stoppedMouseDownEvent.fire(me);
 
490
                }
 
491
                E.stopEvent(me.browserEvent);
 
492
            }
 
493
        },
 
494
 
 
495
        /**
 
496
         * Prevents the browsers default handling of the event.
 
497
         */
 
498
        preventDefault : function(){
 
499
            if(this.browserEvent){
 
500
                E.preventDefault(this.browserEvent);
 
501
            }
 
502
        },        
 
503
 
 
504
        /**
 
505
         * Cancels bubbling of the event.
 
506
         */
 
507
        stopPropagation : function(){
 
508
                var me = this;
 
509
            if(me.browserEvent){
 
510
                if(me.browserEvent.type == 'mousedown'){
 
511
                    Ext.EventManager.stoppedMouseDownEvent.fire(me);
 
512
                }
 
513
                E.stopPropagation(me.browserEvent);
 
514
            }
 
515
        },
 
516
 
 
517
        /**
 
518
         * Gets the character code for the event.
 
519
         * @return {Number}
 
520
         */
 
521
        getCharCode : function(){
 
522
            return this.charCode || this.keyCode;
 
523
        },
 
524
 
 
525
        /**
 
526
         * Returns a normalized keyCode for the event.
 
527
         * @return {Number} The key code
 
528
         */
 
529
        getKey : function(){
 
530
            return this.normalizeKey(this.keyCode || this.charCode)
 
531
        },
 
532
                
 
533
                // private
 
534
                normalizeKey: function(k){
 
535
                        return Ext.isSafari ? (safariKeys[k] || k) : k; 
 
536
                },
 
537
 
 
538
        /**
 
539
         * Gets the x coordinate of the event.
 
540
         * @return {Number}
 
541
         */
 
542
        getPageX : function(){
 
543
            return this.xy[0];
 
544
        },
 
545
 
 
546
        /**
 
547
         * Gets the y coordinate of the event.
 
548
         * @return {Number}
 
549
         */
 
550
        getPageY : function(){
 
551
            return this.xy[1];
 
552
        },
 
553
 
 
554
//         /**
 
555
//          * Gets the time of the event.
 
556
//          * @return {Number}
 
557
//          */
 
558
//         getTime : function(){
 
559
//             if(this.browserEvent){
 
560
//                 return E.getTime(this.browserEvent);
 
561
//             }
 
562
//             return null;
 
563
//         },
 
564
 
 
565
        /**
 
566
         * Gets the page coordinates of the event.
 
567
         * @return {Array} The xy values like [x, y]
 
568
         */
 
569
        getXY : function(){
 
570
            return this.xy;
 
571
        },
 
572
 
 
573
        /**
 
574
         * Gets the target for the event.
 
575
         * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
 
576
         * @param {Number/Mixed} maxDepth (optional) The max depth to
 
577
                search as a number or element (defaults to 10 || document.body)
 
578
         * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
 
579
         * @return {HTMLelement}
 
580
         */
 
581
        getTarget : function(selector, maxDepth, returnEl){
 
582
            return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target);
 
583
        },
 
584
 
 
585
        /**
 
586
         * Gets the related target.
 
587
         * @return {HTMLElement}
 
588
         */
 
589
        getRelatedTarget : function(){
 
590
            return this.browserEvent ? E.getRelatedTarget(this.browserEvent) : null;
 
591
        },
 
592
 
 
593
        /**
 
594
         * Normalizes mouse wheel delta across browsers
 
595
         * @return {Number} The delta
 
596
         */
 
597
        getWheelDelta : function(){
 
598
            var e = this.browserEvent;
 
599
            var delta = 0;
 
600
            if(e.wheelDelta){ /* IE/Opera. */
 
601
                delta = e.wheelDelta/120;
 
602
            }else if(e.detail){ /* Mozilla case. */
 
603
                delta = -e.detail/3;
 
604
            }
 
605
            return delta;
 
606
        },
 
607
                
 
608
                /**
 
609
                * Returns true if the target of this event is a child of el.  Unless the allowEl parameter is set, it will return false if if the target is el.
 
610
                * Example usage:<pre><code>
 
611
                // Handle click on any child of an element
 
612
                Ext.getBody().on('click', function(e){
 
613
                        if(e.within('some-el')){
 
614
                                alert('Clicked on a child of some-el!');
 
615
                        }
 
616
                });
 
617
                
 
618
                // Handle click directly on an element, ignoring clicks on child nodes
 
619
                Ext.getBody().on('click', function(e,t){
 
620
                        if((t.id == 'some-el') && !e.within(t, true)){
 
621
                                alert('Clicked directly on some-el!');
 
622
                        }
 
623
                });
 
624
                </code></pre>
 
625
                 * @param {Mixed} el The id, DOM element or Ext.Element to check
 
626
                 * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
 
627
                 * @param {Boolean} allowEl {optional} true to also check if the passed element is the target or related target
 
628
                 * @return {Boolean}
 
629
                 */
 
630
                within : function(el, related, allowEl){
 
631
            if(el){
 
632
                            var t = this[related ? "getRelatedTarget" : "getTarget"]();
 
633
                            return t && ((allowEl ? (t == Ext.getDom(el)) : false) || Ext.fly(el).contains(t));
 
634
            }
 
635
            return false;
 
636
                }
 
637
         };
 
638
 
 
639
    return new Ext.EventObjectImpl();
 
640
}();
 
 
b'\\ No newline at end of file'