Created
May 15, 2011 11:19
-
-
Save netroy/973062 to your computer and use it in GitHub Desktop.
Better AttachEvent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function(c,a,e,b){function d(a){e.apply(c,[a||event].concat(b))}b=b||[];try{c.addEventListener(a,d,!1)}catch(f){c.attachEvent("on"+a,d)}}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addEvent( | |
| node, // Node to attach event to | |
| eventName, // Event Name | |
| handler, // Callback for event | |
| args){ // Extra arguments to pass to handler (default none) | |
| args = args || []; | |
| function callback(e){ | |
| e = e||event; | |
| e.target = e.target||e.srcElement; | |
| handler.apply(node,[e].concat(args)) | |
| } | |
| if (node.addEventListener){ | |
| node.addEventListener(eventName, callback, false); | |
| } else if (node.attachEvent){ | |
| node.attachEvent('on'+eventName, callback); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment