Skip to content

Commit

Permalink
Honor stopImmediatePropagation for live/delegate event handlers. Fixe…
Browse files Browse the repository at this point in the history
…s #7217.
  • Loading branch information
dmethvin authored and jeresig committed Oct 25, 2010
1 parent ee845c4 commit 974b5ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/event.js
Expand Up @@ -1132,6 +1132,9 @@ function liveHandler( event ) {
if ( ret === false ) { if ( ret === false ) {
stop = false; stop = false;
} }
if ( event.isImmediatePropagationStopped() ) {
break;
}
} }
} }


Expand Down
30 changes: 30 additions & 0 deletions test/unit/event.js
Expand Up @@ -265,6 +265,36 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() {
equals( mouseoverCounter, 4, "die" ); equals( mouseoverCounter, 4, "die" );
}); });


test("live/delegate immediate propagation", function() {
expect(2);

var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;

lastClick = "";
$a.live( "click", function(e) {
lastClick = "click1";
e.stopImmediatePropagation();
});
$a.live( "click", function(e) {
lastClick = "click2";
});
$a.trigger( "click" );
equals( lastClick, "click1", "live stopImmediatePropagation" );
$a.die( "click" );

lastClick = "";
$p.delegate( "a", "click", function(e) {
lastClick = "click1";
e.stopImmediatePropagation();
});
$p.delegate( "a", "click", function(e) {
lastClick = "click2";
});
$a.trigger( "click" );
equals( lastClick, "click1", "delegate stopImmediatePropagation" );
$p.undelegate( "click" );
});

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

0 comments on commit 974b5ae

Please sign in to comment.