Event: Call underlying stopImmediatePropagation when present

Fixes #13997
This commit is contained in:
Dave Methvin 2014-03-05 22:46:23 -05:00
parent 26ce217862
commit 6a89db86ed
2 changed files with 20 additions and 2 deletions

View File

@ -683,7 +683,14 @@ jQuery.Event.prototype = {
} }
}, },
stopImmediatePropagation: function() { stopImmediatePropagation: function() {
var e = this.originalEvent;
this.isImmediatePropagationStopped = returnTrue; this.isImmediatePropagationStopped = returnTrue;
if ( e && e.stopImmediatePropagation ) {
e.stopImmediatePropagation();
}
this.stopPropagation(); this.stopPropagation();
} }
}; };

View File

@ -386,10 +386,13 @@ test("on immediate propagation", function() {
$p.off( "click", "**" ); $p.off( "click", "**" );
}); });
test("on bubbling, isDefaultPrevented", function() { test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function() {
expect(2); expect( 3 );
var $anchor2 = jQuery( "#anchor2" ), var $anchor2 = jQuery( "#anchor2" ),
$main = jQuery( "#qunit-fixture" ), $main = jQuery( "#qunit-fixture" ),
neverCallMe = function() {
ok( false, "immediate propagation should have been stopped" );
},
fakeClick = function($jq) { fakeClick = function($jq) {
// Use a native click so we don't get jQuery simulated bubbling // Use a native click so we don't get jQuery simulated bubbling
var e = document.createEvent( "MouseEvents" ); var e = document.createEvent( "MouseEvents" );
@ -414,6 +417,14 @@ test("on bubbling, isDefaultPrevented", function() {
fakeClick( $anchor2 ); fakeClick( $anchor2 );
$anchor2.off( "click" ); $anchor2.off( "click" );
$main.off( "click", "**" ); $main.off( "click", "**" );
$anchor2.on( "click", function( e ) {
e.stopImmediatePropagation();
ok( true, "anchor was clicked and prop stopped" );
});
$anchor2[0].addEventListener( "click", neverCallMe, false );
fakeClick( $anchor2 );
$anchor2[0].removeEventListener( "click", neverCallMe );
}); });
test("on(), iframes", function() { test("on(), iframes", function() {