]> source.dussan.org Git - jquery.git/commitdiff
Event: Call underlying stopImmediatePropagation when present
authorDave Methvin <dave.methvin@gmail.com>
Thu, 6 Mar 2014 03:46:23 +0000 (22:46 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Thu, 13 Mar 2014 01:45:50 +0000 (21:45 -0400)
Fixes #13997
(cherry picked from commit 6a89db86ed817f6a7498076e2a06b90f9fce0831)

src/event.js
test/unit/event.js

index e2bac6f9be65d907a6f9d7e081cfd5e05a902a09..a15cf6d45e940c9ad6f94ee3714d143fc69e0b66 100644 (file)
@@ -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();
        }
 };
index 0cd181252e40dafef10c86282c6c60b41121e157..d6fece7c0402d4d9430e91280c921e259846cacc 100644 (file)
@@ -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() {