]> source.dussan.org Git - jquery.git/commitdiff
Don't run direct handlers if delegate did .stopPropagation().
authorDave Methvin <dave.methvin@gmail.com>
Fri, 21 Oct 2011 14:56:16 +0000 (10:56 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 24 Oct 2011 15:18:13 +0000 (11:18 -0400)
src/event.js
test/unit/event.js

index 5d4d9a23b8c81e2608bded1c7a9432c93a4850fa..38fd82b5e22fbb3a810bfd72c87acd51d2eee250 100644 (file)
@@ -459,7 +459,7 @@ jQuery.event = {
                delete event.delegateTarget;
 
                // Run non-delegated handlers for this level
-               if ( handlers.length ) {
+               if ( handlers.length && !event.isPropagationStopped() ) {
                        dispatch( this, event, handlers, args );
                }
 
index 28df8ee39ff9da792cea6aee0b5dfc5f9250bb65..cce9061edab6e05e610adcd18ed2dbf9afb4b823 100644 (file)
@@ -2054,6 +2054,22 @@ test(".delegate()/.undelegate()", function() {
        jQuery("#body").undelegate("#nothiddendiv div", "click");
 });
 
+test("stopPropagation() stops directly-bound events on delegated target", function() {
+       expect(1);
+       
+       var markup = jQuery( '<div><p><a href="#">target</a></p></div>' );
+       markup
+               .on( "click", function() {
+                       ok( false, "directly-bound event on delegate target was called" );
+               })
+               .on( "click", "a", function( e ) {
+                       e.stopPropagation();
+                       ok( true, "delegated handler was called" );
+               })
+               .find("a").click().end()
+               .remove();
+});
+
 test("undelegate all bound events", function(){
        expect(1);