Skip to content
Permalink
Browse files

Allow mapped types to be removed by a namespace-only type name.

  • Loading branch information...
dmethvin committed Nov 15, 2011
1 parent 6736dd7 commit ca8fc725ac8f590fff965e70c270c53ab0a6c0f3
Showing with 15 additions and 7 deletions.
  1. +4 −5 src/event.js
  2. +11 −2 test/unit/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 ) ) {
@@ -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,20 +2508,29 @@ 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",
handle: function( event ) {
equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
}
};

// Ensure a special event isn't removed by its mapped type
jQuery( '<p>Gut Feeling</p>' )
.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( '<p>Gut Feeling</p>' )
.on( "gutfeeling.Devo", jQuery.noop )
.off( ".Devo" )
.trigger( "gutfeeling" )
.remove();

delete jQuery.event.special.gutfeeling;
});

0 comments on commit ca8fc72

Please sign in to comment.
You can’t perform that action at this time.