]> source.dussan.org Git - jquery.git/commitdiff
Fix #12203. .undelegate() should not remove direcly bound events.
authorDave Methvin <dave.methvin@gmail.com>
Wed, 8 Aug 2012 00:49:34 +0000 (20:49 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 8 Aug 2012 00:49:34 +0000 (20:49 -0400)
src/event.js
test/unit/event.js

index 4703306ca15fe5faf42a45c0bf5462488fc4f59b..2a2ea24aa304b5921a34b894c041ba325b0de12d 100644 (file)
@@ -973,7 +973,7 @@ jQuery.fn.extend({
        },
        undelegate: function( selector, types, fn ) {
                // ( namespace ) or ( selector, types [, fn] )
-               return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn );
+               return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
        },
 
        trigger: function( type, data ) {
index ecaddf3a45ebc6d6c2579251fdbf789e8731548d..16a9ff0fcfaaf2a4beb901747147017284d666e7 100644 (file)
@@ -2376,18 +2376,24 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
 });
 
 test("undelegate all bound events", function(){
-       expect(1);
+       expect(2);
 
-       var count = 0;
-       var div = jQuery("#body");
+       var count = 0,
+               clicks = 0,
+               div = jQuery("#body");
 
-       div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
+       div.delegate( "div#nothiddendivchild", "click submit", function(){ count++; } );
+       div.bind( "click", function(){ clicks++; } );
        div.undelegate();
 
        jQuery("div#nothiddendivchild").trigger("click");
        jQuery("div#nothiddendivchild").trigger("submit");
 
        equal( count, 0, "Make sure no events were triggered." );
+
+       div.trigger("click");
+       equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
+       div.unbind("click");
 });
 
 test("delegate with multiple events", function(){