1 | ( function( ) |
---|
2 | { |
---|
3 | function config( pObj, pEvent, pHandler ) |
---|
4 | { |
---|
5 | if ( typeof pObj == 'object' ) |
---|
6 | { |
---|
7 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
8 | pEvent = pEvent.substring(2, pEvent.length ); |
---|
9 | |
---|
10 | if ( arguments.length == 3 ) |
---|
11 | { |
---|
12 | if ( pObj.addEventListener ) |
---|
13 | pObj.addEventListener(pEvent, pHandler, false ); |
---|
14 | else if ( pObj.attachEvent ) |
---|
15 | pObj.attachEvent( 'on' + pEvent, pHandler ); |
---|
16 | |
---|
17 | ( arguments[0].preventDefault ) ? |
---|
18 | arguments[0].preventDefault( ) : arguments[0].returnValue = false; |
---|
19 | } |
---|
20 | else if ( arguments.length == 4 ) |
---|
21 | { |
---|
22 | if ( pObj.removeEventListener ) |
---|
23 | pObj.removeEventListener( pEvent, pHandler, false ); |
---|
24 | else if ( pObj.detachEvent ) |
---|
25 | pObj.detachEvent( 'on' + pEvent, pHandler ); |
---|
26 | } |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | function add( pObj, pEvent, pHandler ) |
---|
31 | { |
---|
32 | config( pObj, pEvent, pHandler ); |
---|
33 | } |
---|
34 | |
---|
35 | function remove( pObj, pEvent, pHandler ) |
---|
36 | { |
---|
37 | config( pObj, pEvent, pHandler, true ); |
---|
38 | } |
---|
39 | |
---|
40 | function Events( ) |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | Events.prototype.add = add; |
---|
45 | Events.prototype.remove = remove; |
---|
46 | |
---|
47 | window.XEvents = new Events; |
---|
48 | } )( ); |
---|