});
jQuery.fn.extend({
+ // TODO: make bind(), unbind() and one() DRY!
bind: function( type, data, fn, thisObject ) {
- if ( jQuery.isFunction( data ) ) {
- if ( fn !== undefined ) {
- thisObject = fn;
+ // Handle object literals
+ if ( typeof type === "object" ) {
+ for ( var key in type ) {
+ this.bind(key, data, type[key], fn);
}
+ return this;
+ }
+
+ if ( jQuery.isFunction( data ) ) {
+ thisObject = fn;
fn = data;
data = undefined;
}
},
one: function( type, data, fn, thisObject ) {
- if ( jQuery.isFunction( data ) ) {
- if ( fn !== undefined ) {
- thisObject = fn;
+ // Handle object literals
+ if ( typeof type === "object" ) {
+ for ( var key in type ) {
+ this.one(key, data, type[key], fn);
}
+ return this;
+ }
+
+ if ( jQuery.isFunction( data ) ) {
+ thisObject = fn;
fn = data;
data = undefined;
}
},
unbind: function( type, fn ) {
+ // Handle object literals
+ if ( typeof type === "object" && !type.preventDefault ) {
+ for ( var key in type ) {
+ this.unbind(key, type[key]);
+ }
+ return this;
+ }
+
return this.each(function() {
jQuery.event.remove( this, type, fn );
});