Skip to content
Browse files

.unbind() without any arguments now also unbinds namespaced events. f…

…ixes #4609 and #4241
  • Loading branch information...
1 parent 1bd4325 commit 851846aabea72fe784b8a13cfb04cffecdb771b6 @brandonaaron brandonaaron committed Apr 29, 2009
Showing with 10 additions and 4 deletions.
  1. +3 −2 src/event.js
  2. +7 −2 test/unit/event.js
View
5 src/event.js
@@ -116,7 +116,8 @@ jQuery.event = {
// Namespaced event handlers
var namespaces = type.split(".");
type = namespaces.shift();
- var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)");
+ var all = !namespaces.length,
+ namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)");
if ( events[type] ) {
// remove the given handler for the given type
@@ -127,7 +128,7 @@ jQuery.event = {
else
for ( var handle in events[type] )
// Handle the removal of namespaced events
- if ( namespace.test(events[type][handle].type) )
+ if ( all || namespace.test(events[type][handle].type) )
delete events[type][handle];
if ( jQuery.event.specialAll[type] )
View
9 test/unit/event.js
@@ -194,6 +194,11 @@ test("unbind(type)", function() {
$elem.bind('error error2',error)
.unbind('error error2')
.trigger('error').triggerHandler('error2');
+
+ message = "unbind without a type or handler";
+ $elem.bind("error error2.test",error)
+ .unbind()
+ .trigger("error").triggerHandler("error2");
});
test("unbind(eventObject)", function() {
@@ -651,14 +656,14 @@ test(".live()/.die()", function() {
// bind one pair in one order
jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
- jQuery('span#liveSpan1').live('click', function(){ livee++; });
+ jQuery('span#liveSpan1').live('click', function(){ livee++; });
jQuery('span#liveSpan1 a').click();
equals( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler don't." );
// and one pair in inverse
- jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
+ jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; });
jQuery('span#liveSpan2 a').click();

0 comments on commit 851846a

Please sign in to comment.
Something went wrong with that request. Please try again.