mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Call underlying stopImmediatePropagation when present
Fixes #13997
(cherry picked from commit 6a89db86ed
)
This commit is contained in:
parent
725cdebd39
commit
4c68d107b5
@ -751,7 +751,14 @@ jQuery.Event.prototype = {
|
||||
e.cancelBubble = true;
|
||||
},
|
||||
stopImmediatePropagation: function() {
|
||||
var e = this.originalEvent;
|
||||
|
||||
this.isImmediatePropagationStopped = returnTrue;
|
||||
|
||||
if ( e && e.stopImmediatePropagation ) {
|
||||
e.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
this.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
@ -386,10 +386,13 @@ test("on immediate propagation", function() {
|
||||
$p.off( "click", "**" );
|
||||
});
|
||||
|
||||
test("on bubbling, isDefaultPrevented", function() {
|
||||
expect(2);
|
||||
test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function() {
|
||||
expect( 3 );
|
||||
var $anchor2 = jQuery( "#anchor2" ),
|
||||
$main = jQuery( "#qunit-fixture" ),
|
||||
neverCallMe = function() {
|
||||
ok( false, "immediate propagation should have been stopped" );
|
||||
},
|
||||
fakeClick = function($jq) {
|
||||
// Use a native click so we don't get jQuery simulated bubbling
|
||||
if ( document.createEvent ) {
|
||||
@ -427,6 +430,18 @@ test("on bubbling, isDefaultPrevented", function() {
|
||||
fakeClick( $anchor2 );
|
||||
$anchor2.off( "click" );
|
||||
$main.off( "click", "**" );
|
||||
|
||||
if ( !window.addEventListener ) {
|
||||
ok( true, "Old IE, skipping native stopImmediatePropagation check" );
|
||||
} else {
|
||||
$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() {
|
||||
|
Loading…
Reference in New Issue
Block a user