Skip to content

Commit b9644d2

Browse files
committed
Honor stopImmediatePropagation for live/delegate event handlers. Fixes #7217.
1 parent f887c14 commit b9644d2

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
@@ -1129,6 +1129,9 @@ function liveHandler( event ) {
11291129
if ( ret === false ) {
11301130
stop = false;
11311131
}
1132+
if ( event.isImmediatePropagationStopped() ) {
1133+
break;
1134+
}
11321135
}
11331136
}
11341137

test/unit/event.js

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

248+
test("live/delegate immediate propagation", function() {
249+
expect(2);
250+
251+
var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
252+
253+
lastClick = "";
254+
$a.live( "click", function(e) {
255+
lastClick = "click1";
256+
e.stopImmediatePropagation();
257+
});
258+
$a.live( "click", function(e) {
259+
lastClick = "click2";
260+
});
261+
$a.trigger( "click" );
262+
equals( lastClick, "click1", "live stopImmediatePropagation" );
263+
$a.die( "click" );
264+
265+
lastClick = "";
266+
$p.delegate( "a", "click", function(e) {
267+
lastClick = "click1";
268+
e.stopImmediatePropagation();
269+
});
270+
$p.delegate( "a", "click", function(e) {
271+
lastClick = "click2";
272+
});
273+
$a.trigger( "click" );
274+
equals( lastClick, "click1", "delegate stopImmediatePropagation" );
275+
$p.undelegate( "click" );
276+
});
277+
248278
test("bind(), iframes", function() {
249279
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
250280
var doc = jQuery("#loadediframe").contents();

0 commit comments

Comments
 (0)