mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Allow mapped types to be removed by a namespace-only type name.
This commit is contained in:
parent
6736dd7168
commit
ca8fc725ac
@ -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 ) ) {
|
||||
|
@ -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;
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user