public
Last active

1.4/1.4.1 and 1.4.2+ compatible event special .add method

  • Download Gist
jquery.event.special.foo.add.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
$.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;
}
}
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.