11 document.addEventListener ?
12 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
14 if( typeof arg2 === 'function' ){
15 callback = X.Callback.create( element, arg2, arg3 );
17 callback = X.Callback.create( arg2, arg3, arg4 );
19 callback.c = X.DomEvent._callback; // override
20 element.addEventListener( type, callback, false );
22 document.attachEvent ?
23 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
25 if( typeof arg2 === 'function' ){
26 callback = X.Callback.create( element, arg2, arg3 );
28 callback = X.Callback.create( arg2, arg3, arg4 );
30 callback.c = X.DomEvent._callback; // override
32 element.attachEvent( 'on' + type, callback );
34 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
36 if( typeof arg2 === 'function' ){
37 callback = X.Callback.create( element, arg2, arg3 );
39 callback = X.Callback.create( arg2, arg3, arg4 );
41 if( X.DomEvent.helper( element, type, callback ) === false ){
42 callback.c = X.DomEvent._callback; // override
45 helper = X.DomEvent.Dom0.find( element, type, callback );
47 if( helper.list.indexOf( callback ) === -1 ) helper.list[ helper.list.length ] = callback;
49 new X.DomEvent.Dom0.Helper( element, type, callback );
53 document.removeEventListener ?
54 (function( element, type, arg2, arg3 ){
55 var callback = X.Callback.find( arg2, arg3 );
57 element.removeEventListener( type, callback, false );
58 X.Callback._correct( callback );
61 document.detachEvent ?
62 (function( element, type, arg2, arg3 ){
63 var callback = X.Callback.find( arg2, arg3 );
65 element.detachEvent( 'on' + type, callback );
66 X.Callback._correct( callback );
69 (function( element, type, arg2, arg3 ){
70 var t = X.DomEvent.Dom0.find( element, type ),
71 c = X.Callback.find( arg2, arg3 ),
74 i = t.list.indexOf( c );
76 t.list.splice( i, 1 );
77 X.Callback._correct( c );
79 if( t.list.length === 0 ){
80 t.elm[ 'on' + t.type ] = X.DomEvent.Dom0.emptyFunc;
81 t.elm[ 'on' + t.type ] = '';
82 c = X.Callback.find( t );
83 X.Callback._correct( c );
84 X.DomEvent.Dom0.LIST.splice( X.DomEvent.Dom0.LIST.indexOf( t ), 1 );
92 window.addEventListener ?
95 r = f.callback.call( f.context, event );
96 if( r !== false ) return r;
97 event.preventDefault();
98 event.stopPropagation();
105 r = f.callback.call( x, new X.DomEvent.xEvent( e, x.elm ));
106 if( r !== false ) return r;
107 e.cancelBubble = true;
108 e.returnValue = false;
112 if( !window.addEventListener ){
113 X.DomEvent.xEvent = function( e, element ){
116 this.target = e.srcElement;
117 this.currentTarget = element;
118 this.relatedTarget = e.formElement ? e.formElement : e.toElement;
119 this.eventPhase = e.srcElement === element ? 2: 3;
121 this.clientX = e.clientX;
122 this.clientY = e.clientY;
123 this.screenX = e.screenX;
124 this.screenY = e.screenY;
126 this.keyCode = e.keyCode;
127 this.altKey = e.altKey;
128 this.ctrlKey = e.ctrlKey;
129 this.shiftKey = e.shiftKey;
131 this.wheelDelta = e.wheelDelta;
134 if( !document.addEventListener && !document.attachEvent ){
137 emptyFunc : new Function(),
138 find : function( element, type ){
139 var list = X.DomEvent.Dom0.LIST,
143 helper = list[ --i ];
144 if( helper.elm === element && helper.type === type ) return helper;
148 Helper : function( elm, type, callback ){
151 this.list = [ callback ];
153 var callback = elm[ 'on' + type ] = X.DomEvent.create( this );
154 callback.c = X.DomEvent._callback; // override
155 X.DomEvent.Dom0.LIST[ X.DomEvent.Dom0.LIST.length ] = this;
158 X.DomEvent.Dom0.Helper.prototype.handleEvent = function(e){
160 var list = this.list,
164 if( list[ --i ]( e ) === false ) cancel = false;