diff --git a/src/event.js b/src/event.js index 199110c00..c9c891992 100644 --- a/src/event.js +++ b/src/event.js @@ -148,7 +148,7 @@ jQuery.event = { global: {}, // Detach an event or set of events from an element - remove: function( elem, types, handler, selector ) { + remove: function( elem, types, handler, selector, mappedTypes ) { var elemData = jQuery.hasData( elem ) && jQuery._data( elem ), t, tns, type, origType, namespaces, origCount, @@ -167,9 +167,8 @@ jQuery.event = { // Unbind all events (on this namespace, if provided) for the element if ( !type ) { - namespaces = namespaces? "." + namespaces : ""; - for ( j in events ) { - jQuery.event.remove( elem, j + namespaces, handler, selector ); + for ( type in events ) { + jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); } continue; } @@ -184,7 +183,7 @@ jQuery.event = { for ( j = 0; j < eventType.length; j++ ) { handleObj = eventType[ j ]; - if ( origType === handleObj.origType && + if ( ( mappedTypes || origType === handleObj.origType ) && ( !handler || handler.guid === handleObj.guid ) && ( !namespaces || namespaces.test( handleObj.namespace ) ) && ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) { diff --git a/test/unit/event.js b/test/unit/event.js index fb42bec35..c207d0289 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1132,7 +1132,7 @@ test("trigger(eventObject, [data], [fn])", function() { $child.unbind(); $parent.unbind().remove(); - + // Ensure triggerHandler doesn't molest its event object (#xxx) var event = jQuery.Event( "zowie" ); jQuery( document ).triggerHandler( event ); @@ -2508,7 +2508,6 @@ test("special bind/delegate name mapping", function() { .remove(); delete jQuery.event.special.slap; - // Ensure a special event isn't removed by its mapped type jQuery.event.special.gutfeeling = { bindType: "click", delegateType: "click", @@ -2516,12 +2515,22 @@ test("special bind/delegate name mapping", function() { equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" ); } }; + + // Ensure a special event isn't removed by its mapped type jQuery( '
Gut Feeling
' ) .on( "click", jQuery.noop ) .on( "gutfeeling", jQuery.noop ) .off( "click" ) .trigger( "gutfeeling" ) .remove(); + + // Ensure special events are removed when only a namespace is provided + jQuery( 'Gut Feeling
' ) + .on( "gutfeeling.Devo", jQuery.noop ) + .off( ".Devo" ) + .trigger( "gutfeeling" ) + .remove(); + delete jQuery.event.special.gutfeeling; });