]> source.dussan.org Git - jquery.git/commitdiff
Honor stopImmediatePropagation for live/delegate event handlers. Fixes #7217.
authordmethvin <dave.methvin@gmail.com>
Sat, 23 Oct 2010 18:36:24 +0000 (14:36 -0400)
committerJohn Resig <jeresig@gmail.com>
Mon, 25 Oct 2010 20:05:31 +0000 (13:05 -0700)
src/event.js
test/unit/event.js

index d491ae8a116998447ff54daff392f0fc2be31ba8..959e89c5e96f18bbf67ecd809e90caadcfa7f880 100644 (file)
@@ -1132,6 +1132,9 @@ function liveHandler( event ) {
                        if ( ret === false ) {
                                stop = false;
                        }
+                       if ( event.isImmediatePropagationStopped() ) {
+                               break;
+                       }
                }
        }
 
index 5efa0ec51de44941de5d7956d8f4ea05e5a11c8a..54431dd33e094d4fe8f9267bf41683c92e796c3c 100644 (file)
@@ -265,6 +265,36 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() {
        equals( mouseoverCounter, 4, "die" );
 });
 
+test("live/delegate immediate propagation", function() {
+       expect(2);
+       
+       var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
+       
+       lastClick = "";
+       $a.live( "click", function(e) { 
+               lastClick = "click1"; 
+               e.stopImmediatePropagation();
+       });
+       $a.live( "click", function(e) {
+               lastClick = "click2";
+       });
+       $a.trigger( "click" );
+       equals( lastClick, "click1", "live stopImmediatePropagation" );
+       $a.die( "click" );
+       
+       lastClick = "";
+       $p.delegate( "a", "click", function(e) { 
+               lastClick = "click1"; 
+               e.stopImmediatePropagation();
+       });
+       $p.delegate( "a", "click", function(e) {
+               lastClick = "click2";
+       });
+       $a.trigger( "click" );
+       equals( lastClick, "click1", "delegate stopImmediatePropagation" );
+       $p.undelegate( "click" );
+});
+
 test("bind(), iframes", function() {
        // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
        var doc = jQuery("#loadediframe").contents();