Skip to content

Commit

Permalink
Added support for map of events in live, die, delegate and undelegate…
Browse files Browse the repository at this point in the history
…. Fixes #6282.
  • Loading branch information
rkatic committed Mar 14, 2010
1 parent 5cba876 commit 0ed8cc6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/event.js
Expand Up @@ -940,6 +940,14 @@ jQuery.each(["live", "die"], function( i, name ) {
var type, i = 0, match, namespaces, preType,
selector = origSelector || this.selector,
context = origSelector ? this : jQuery( this.context );

if ( typeof types === "object" && !types.preventDefault ) {
for ( var key in types ) {
context[ name ]( key, data, types[key], selector );
}

return this;
}

if ( jQuery.isFunction( data ) ) {
fn = data;
Expand Down
39 changes: 39 additions & 0 deletions test/unit/event.js
Expand Up @@ -206,6 +206,45 @@ test("bind/one/unbind(Object)", function(){
equals( mouseoverCounter, 4, "bind(Object)" );
});

test("live/die(Object), delegate/undelegate(String, Object)", function() {
expect(6);

var clickCounter = 0, mouseoverCounter = 0,
$p = jQuery("#firstp"), $a = $p.find("a");

var events = {
click: function( event ) {
clickCounter += ( event.data || 1 );
},
mouseover: function( event ) {
mouseoverCounter += ( event.data || 1 );
}
};

function trigger() {
$a.trigger("click").trigger("mouseover");
}

$a.live( events );
$p.delegate( "a", events, 2 );

trigger();
equals( clickCounter, 3, "live/delegate(Object)" );
equals( mouseoverCounter, 3, "live/delegate(Object)" );

$p.undelegate( "a", events );

trigger();
equals( clickCounter, 4, "undelegate(Object)" );
equals( mouseoverCounter, 4, "undelegate(Object)" );

$a.die( events );

trigger();
equals( clickCounter, 4, "die(Object)" );
equals( mouseoverCounter, 4, "die(Object)" );
});

test("bind(), iframes", function() {
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
var doc = jQuery("#loadediframe").contents();
Expand Down

2 comments on commit 0ed8cc6

@leeoniya
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you ever make a pull request for this?

@rkatic
Copy link
Owner Author

@rkatic rkatic commented on 0ed8cc6 Mar 23, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. 9 days ago. In meantime MIX2010 takes place, so I suppose it suspended jQuery development a bit. I just made pull request again, in case the first one was "lost".

Please sign in to comment.