Commit 683be093 authored by Dave Methvin's avatar Dave Methvin

Catch more cases where special events were incorrectly removed.

We can't take the blow-it-all-away shortcut because something in the middle of the list may be a mapped special event. On the bright side, -22!
parent e0a4aa41
...@@ -180,8 +180,7 @@ jQuery.event = { ...@@ -180,8 +180,7 @@ jQuery.event = {
origCount = eventType.length; origCount = eventType.length;
namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null; namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
// Only need to loop for special events or selective removal // Remove matching events
if ( handler || namespaces || selector || special.remove || origType !== type ) {
for ( j = 0; j < eventType.length; j++ ) { for ( j = 0; j < eventType.length; j++ ) {
handleObj = eventType[ j ]; handleObj = eventType[ j ];
...@@ -199,10 +198,6 @@ jQuery.event = { ...@@ -199,10 +198,6 @@ jQuery.event = {
} }
} }
} }
} else {
// Removing all events
eventType.length = 0;
}
// Remove generic event handler if we removed something and no more handlers exist // Remove generic event handler if we removed something and no more handlers exist
// (avoids potential for endless recursion during removal of special event handlers) // (avoids potential for endless recursion during removal of special event handlers)
......
...@@ -2462,14 +2462,13 @@ test(".on and .off", function() { ...@@ -2462,14 +2462,13 @@ test(".on and .off", function() {
}); });
test("special bind/delegate name mapping", function() { test("special bind/delegate name mapping", function() {
expect( 7 ); expect( 6 );
jQuery.event.special.slap = { jQuery.event.special.slap = {
bindType: "click", bindType: "click",
delegateType: "swing", delegateType: "swing",
handle: function( event ) { handle: function( event ) {
equal( event.handleObj.origType, "slap", "event type is correct for " + event.type ); equal( event.handleObj.origType, "slap", "slapped your mammy, " + event.type );
equal( event.target.id, "mammy", "slapped your mammy" );
} }
}; };
...@@ -2489,12 +2488,30 @@ test("special bind/delegate name mapping", function() { ...@@ -2489,12 +2488,30 @@ test("special bind/delegate name mapping", function() {
.off( "click" ) .off( "click" )
.trigger( "swing" ) // delegateType-slap and swing .trigger( "swing" ) // delegateType-slap and swing
.end() .end()
.off( "slap swing" ) .off( "slap swing", "button" )
.find( "button " ) // everything should be gone .find( "button" ) // everything should be gone
.trigger( "slap" ) .trigger( "slap" )
.trigger( "click" ) .trigger( "click" )
.trigger( "swing" ) .trigger( "swing" )
.end(); .end()
.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" );
}
};
jQuery( '<p>Gut Feeling</p>' )
.on( "click", jQuery.noop )
.on( "gutfeeling", jQuery.noop )
.off( "click" )
.trigger( "gutfeeling" )
.remove();
delete jQuery.event.special.gutfeeling;
}); });
test(".on and .off, selective mixed removal (#10705)", function() { test(".on and .off, selective mixed removal (#10705)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment