Skip to content

Commit 974b5ae

Browse files
dmethvinjeresig
authored andcommitted
Honor stopImmediatePropagation for live/delegate event handlers. Fixes #7217.
1 parent ee845c4 commit 974b5ae

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/event.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,9 @@ function liveHandler( event ) {
11321132
if ( ret === false ) {
11331133
stop = false;
11341134
}
1135+
if ( event.isImmediatePropagationStopped() ) {
1136+
break;
1137+
}
11351138
}
11361139
}
11371140

test/unit/event.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,36 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() {
265265
equals( mouseoverCounter, 4, "die" );
266266
});
267267

268+
test("live/delegate immediate propagation", function() {
269+
expect(2);
270+
271+
var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
272+
273+
lastClick = "";
274+
$a.live( "click", function(e) {
275+
lastClick = "click1";
276+
e.stopImmediatePropagation();
277+
});
278+
$a.live( "click", function(e) {
279+
lastClick = "click2";
280+
});
281+
$a.trigger( "click" );
282+
equals( lastClick, "click1", "live stopImmediatePropagation" );
283+
$a.die( "click" );
284+
285+
lastClick = "";
286+
$p.delegate( "a", "click", function(e) {
287+
lastClick = "click1";
288+
e.stopImmediatePropagation();
289+
});
290+
$p.delegate( "a", "click", function(e) {
291+
lastClick = "click2";
292+
});
293+
$a.trigger( "click" );
294+
equals( lastClick, "click1", "delegate stopImmediatePropagation" );
295+
$p.undelegate( "click" );
296+
});
297+
268298
test("bind(), iframes", function() {
269299
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
270300
var doc = jQuery("#loadediframe").contents();

0 commit comments

Comments
 (0)