aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-11-15 11:38:55 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-11-15 11:38:55 -0500
commitca8fc725ac8f590fff965e70c270c53ab0a6c0f3 (patch)
tree9186f411482a7a4342a432a242e9378059bcb43c
parent6736dd7168ccd1e6d72aca2e3c89d685c5d9c63a (diff)
downloadjquery-ca8fc725ac8f590fff965e70c270c53ab0a6c0f3.tar.gz
jquery-ca8fc725ac8f590fff965e70c270c53ab0a6c0f3.zip
Allow mapped types to be removed by a namespace-only type name.
-rw-r--r--src/event.js9
-rw-r--r--test/unit/event.js13
2 files changed, 15 insertions, 7 deletions
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( '<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;
});