X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=76b1dfb20102c9a0ec2780d3bc2249bcb7b963d9;hb=9ebb2fc654d51244618e208705e2258fe733058f;hp=380d3d49e38d9d069b6cc2d7a8daae19bddacb64;hpb=bca82254137a161094377b2d8189c2d9d5906a0f;p=jquery.git diff --git a/src/event.js b/src/event.js index 380d3d4..76b1dfb 100644 --- a/src/event.js +++ b/src/event.js @@ -564,11 +564,18 @@ jQuery.each({ }); 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; } @@ -579,10 +586,16 @@ jQuery.fn.extend({ }, 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; } @@ -597,6 +610,14 @@ jQuery.fn.extend({ }, 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 ); });