Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created February 8, 2010 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/298508 to your computer and use it in GitHub Desktop.
Save cowboy/298508 to your computer and use it in GitHub Desktop.
1.4/1.4.1 and 1.4.2+ compatible event special .add method
$.event.special.foo = {
add: function( handler, data, namespaces ) {
var old_handler;
function new_handler(e) {
// customize, using data, namespaces, handler.type, etc.
old_handler.apply( this, arguments );
};
// This may seem a little complicated, but it normalizes the special event
// .add method between jQuery 1.4/1.4.1 and 1.4.2+
if ( $.isFunction( handler ) ) {
// 1.4, 1.4.1
old_handler = handler;
return new_handler;
} else {
// 1.4.2+
data = handler.data;
namespaces = handler.namespaces;
old_handler = handler.handler;
handler.handler = new_handler;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment