Skip to content

Instantly share code, notes, and snippets.

@jed
Forked from 140bytes/LICENSE.txt
Created May 12, 2011 08:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jed/968186 to your computer and use it in GitHub Desktop.
Save jed/968186 to your computer and use it in GitHub Desktop.
bind and unbind events
function(
a, // A DOM element
b, // an event name such as "click"
c, // a handler function
d // (placeholder)
){
a = a || document; // use the document by default
d = a[ // save the current onevent handler
b = "on" + b // prepend the event name with "on"
];
b = a[b] = // cache and replace the current handler
function(e) { // with a function that
d = d && d( // executes/caches the previous handler
e = e || a.event // with a cross-browser object,
);
return (c = c && b(e)) // and executes/caches the passed function,
? b // returning the current handler if it rebinds
: d // and the previous handler otherwise.
};
a = this // cache the window to fetch IE events
}
function(a,b,c,d){a=a||document;d=a[b="on"+b];b=a[b]=function(e){d=d&&d(e=e||a.event);return(c=c&&b(e))?b:d};a=this}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "on",
"keywords": ["bind", "events", "event", "DOM"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment