From 1d8bf0a2b57fd429c600aab5b150b2a04b87e451 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 7 Aug 2012 20:49:34 -0400 Subject: [PATCH] Fix #12203. .undelegate() should not remove direcly bound events. --- src/event.js | 2 +- test/unit/event.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/event.js b/src/event.js index 4703306ca..2a2ea24aa 100644 --- a/src/event.js +++ b/src/event.js @@ -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 ) { diff --git a/test/unit/event.js b/test/unit/event.js index ecaddf3a4..16a9ff0fc 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -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(){ -- 2.39.5