aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2014-03-05 22:46:23 -0500
committerDave Methvin <dave.methvin@gmail.com>2014-03-12 21:11:26 -0400
commit6a89db86ed817f6a7498076e2a06b90f9fce0831 (patch)
tree770d9e5b715646b60d90e7183fa1c2cb7cf051df
parent26ce21786252981563e49e91a85b3e0bfa16c3e3 (diff)
downloadjquery-6a89db86ed817f6a7498076e2a06b90f9fce0831.tar.gz
jquery-6a89db86ed817f6a7498076e2a06b90f9fce0831.zip
Event: Call underlying stopImmediatePropagation when present
Fixes #13997
-rw-r--r--src/event.js7
-rw-r--r--test/unit/event.js15
2 files changed, 20 insertions, 2 deletions
diff --git a/src/event.js b/src/event.js
index ee1f3fcad..35c1c66b7 100644
--- a/src/event.js
+++ b/src/event.js
@@ -683,7 +683,14 @@ jQuery.Event.prototype = {
}
},
stopImmediatePropagation: function() {
+ var e = this.originalEvent;
+
this.isImmediatePropagationStopped = returnTrue;
+
+ if ( e && e.stopImmediatePropagation ) {
+ e.stopImmediatePropagation();
+ }
+
this.stopPropagation();
}
};
diff --git a/test/unit/event.js b/test/unit/event.js
index 84cad50ac..d93e8f778 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -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
var e = document.createEvent( "MouseEvents" );
@@ -414,6 +417,14 @@ test("on bubbling, isDefaultPrevented", function() {
fakeClick( $anchor2 );
$anchor2.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() {