8 document.addEventListener ?
9 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
11 if( typeof arg2 === 'function' ){
12 callback = X.Callback.create( element, arg2, arg3 );
14 callback = X.Callback.create( arg2, arg3, arg4 );
16 callback.c = X.DomEvent._callback; // override
17 element.addEventListener( type, callback, false );
19 document.attachEvent ?
20 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
22 if( typeof arg2 === 'function' ){
23 callback = X.Callback.create( element, arg2, arg3 );
25 callback = X.Callback.create( arg2, arg3, arg4 );
27 callback.c = X.DomEvent._callback; // override
29 element.attachEvent( 'on' + type, callback );
31 (function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
32 var callback, dom0, helper, list;
33 if( typeof arg2 === 'function' ){
34 callback = X.Callback.create( element, arg2, arg3 );
36 callback = X.Callback.create( arg2, arg3, arg4 );
38 if( X.DomEvent.helper( element, type, callback ) === false ){
39 callback.c = X.DomEvent._callback; // override
42 dom0 = X.DomEvent.Dom0;
43 helper = dom0.find( element, type );
46 if( list.indexOf( callback ) === -1 ) list[ list.length ] = callback;
48 dom0.LIST[ dom0.LIST.length ] = new dom0.Helper( element, type, callback );
52 document.removeEventListener ?
53 (function( element, type, arg2, arg3 ){
54 var callback = X.Callback.find( arg2, arg3 );
56 element.removeEventListener( type, callback, false );
57 X.Callback._correct( callback );
60 document.detachEvent ?
61 (function( element, type, arg2, arg3 ){
62 var callback = X.Callback.find( arg2, arg3 );
64 element.detachEvent( 'on' + type, callback );
65 X.Callback._correct( callback );
68 (function( element, type, arg2, arg3 ){
69 var dom0 = X.DomEvent.Dom0,
70 t = 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 ] = dom0.emptyFunc;
81 t.elm[ 'on' + t.type ] = '';
82 c = X.Callback.find( t );
83 X.Callback._correct( c );
84 dom0.LIST.splice( dom0.LIST.indexOf( t ), 1 );
92 window.addEventListener ?
96 r = f.callback.call( f.context, new X.DomEvent.xEvent( e ) );
97 if( r !== false ) return r;
102 document.attachEvent ?
107 r = f.callback.call( x, new X.DomEvent.xEvent( e, f.e ));
108 if( r !== false ) return r;
109 e.cancelBubble = true;
110 e.returnValue = false;
117 r = f.callback.call( x, new X.DomEvent.xEvent( e, x.elm ));
118 if( r !== false ) return r;
119 e.cancelBubble = true;
120 e.returnValue = false;
124 if( window.addEventListener ){
125 X.DomEvent.xEvent = function( e ){
128 this.target = e.target;
129 this.currentTarget = e.currentTarget;
130 this.relatedTarget = e.relatedTarget;
131 this.eventPhase = e.eventPhase;
133 this.clientX = e.clientX;
134 this.clientY = e.clientY;
135 this.screenX = e.screenX;
136 this.screenY = e.screenY;
138 this.keyCode = e.keyCode;
139 this.altKey = e.altKey;
140 this.ctrlKey = e.ctrlKey;
141 this.shiftKey = e.shiftKey;
143 this.wheelDelta = e.wheelDelta;
146 X.DomEvent.xEvent = function( e, element ){
149 this.target = e.srcElement;
150 this.currentTarget = element;
151 this.relatedTarget = e.formElement ? e.formElement : e.toElement;
152 this.eventPhase = e.srcElement === element ? 2: 3;
154 this.clientX = e.clientX;
155 this.clientY = e.clientY;
156 this.screenX = e.screenX;
157 this.screenY = e.screenY;
159 this.keyCode = e.keyCode;
160 this.altKey = e.altKey;
161 this.ctrlKey = e.ctrlKey;
162 this.shiftKey = e.shiftKey;
164 this.wheelDelta = e.wheelDelta;
167 if( !document.addEventListener && !document.attachEvent ){
170 emptyFunc : new Function(),
171 find : function( element, type ){
172 var list = X.DomEvent.Dom0.LIST,
176 helper = list[ --i ];
177 if( helper.elm === element && helper.type === type ) return helper;
180 Helper : function( elm, type, callback ){
183 this.list = [ callback ];
185 callback = elm[ 'on' + type ] = X.Callback.create( this );
186 callback.c = X.DomEvent._callback; // override
189 X.DomEvent.Dom0.Helper.prototype.handleEvent = function(e){
191 var list = this.list,
195 if( list[ --i ]( e ) === false ) cancel = false;