AddEvent. js code of the driver event
The Code is as follows:
Array. prototype. inArray = function (value ){
Var I;
For (I = 0; I <this. length; I ++ ){
If (this [I] === value ){
Return true;
}
}
Return false;
};
Function addEvent (obj, type, fn ){
If (obj. addEventListener ){
Obj. addEventListener (type, fn, false );
EventCache. add (obj, type, fn );
}
Else if (obj. attachEvent ){
Obj ["e" + type + fn] = fn;
Obj [type + fn] = function () {obj ["e" + type + fn] (window. event );}
Obj. attachEvent ("on" + type, obj [type + fn]);
EventCache. add (obj, type, fn );
}
Else {
Obj ["on" + type] = obj ["e" + type + fn];
}
}
Var EventCache = function (){
Var listeven Ts = [];
Return {
Listeven ts: listeven ts,
Add: function (node, sEventName, fHandler ){
Listeven ts. push (arguments );
},
Flush: function (){
Var I, item;
For (I = listeven ts. length-1; I> = 0; I = I-1 ){
Item = listeven ts [I];
If (item [0]. removeEventListener ){
Item [0]. removeEventListener (item [1], item [2], item [3]);
};
If (item [1]. substring (0, 2 )! = "On "){
Item [1] = "on" + item [1];
};
If (item [0]. detachEvent ){
Item [0]. detachEvent (item [1], item [2]);
};
Item [0] [item [1] = null;
};
}
};
}();
AddEvent (window, 'unload', EventCache. flush );