1 varEventutil = {2GetEvent:function(event) {//Get Event Object3 returnEvent?event:window.event;4 },5AddHandler:function(element, type, handler) {//Binding Events6 if(element.addeventlistener) {7Element.addeventlistener (type, Handler,false);8}Else if(element.attachevent) {9Element.attachevent ("on" +type, handler);Ten}Else { OneElement["on" + type] =handler; A - } - }, theRemoveHandler:function(element, type, handler) {//Remove Bindings - if(element.removeeventlistener) { -Element.removeeventlistener (Type,handler,false); -}Else if(element.detachevent) { +Element.detachevent ("On" +type,handler,false); -}Else{ +element["on" +type] =NULL; A } at }, -Preventdefault:function(event) {//Block Default Events - if(event.preventdefault) { - Event.preventdefault (); -}Else{ -Event.returnvalue =false; in } - }, toStoppropagation:function(event) {//Block Event bubbling + if(event.stoppropagation) { - event.stoppropagation (); the}Else{ *Event.cancelbubble =true; $ }Panax Notoginseng }, -Getrelatetarget:function(event) {//information about event-related elements the if(event.relatedtarget) { + returnEvent.relatedtarget; A}Else if(event.toelement) { the event.toelement; +}Else if(event.fromelement) { - returnevent.fromelement; $}Else{ $ return NULL; - } - }, theGetbutton:function(event) {//Detecting Button Properties - if(Document.implementation.hasFeature ("Mouseevents", "2.0")){Wuyi returnEvent.button; the}Else{ - Switch(Event.button) { Wu Case0: - Case1: About Case3: $ Case5: - Case7: - return0;//primary mouse button - Case2: A Case6: + return2;//Secondary mouse button the Case4: - return1;//Mouse wheel Button $ } the } the }, theGetwheeldelta:function(event) {//Mouse Scrolling property values the if(Event.wheeldelta) { - return(Client.engine.opera && client.engine.opera <9.5?-Event.wheelDelta:event.wheelDelta) in}Else{ the return-event.detail *40; the } About }, theGetcharcode:function(event) {//Get character encoding the if(typeofEvent.charcode = = "Number"){ the returnEvent.charcode; +}Else{ - returnEvent.keycode; the }Bayi }, theGetcilpboardtext:function(event) {//Get Clipboard contents the varCilpboarddata = (Event.clipboarddata | |window.clipboarddata); - returnClipboarddata.getdata ("Text"); - }, theSetclipboardtext:function(Event,value) {//cut to shear plate the if(event.clipboarddata) { the returnEvent.clipboardData.setData ("Text/plain", value); the}Else if(window.clipboarddata) { - returnWindow.clipboardData.setData ("Text", value); the } the } the 94 the}
The code is summarized in the JavaScript Advanced Programming Events section.