Skip to content

Commit

Permalink
Fix #10984. Use origType when unbinding via the event object.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Dec 14, 2011
1 parent 2a63b98 commit c584ce4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/event.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ jQuery.fn.extend({
// ( event ) dispatched jQuery.Event // ( event ) dispatched jQuery.Event
var handleObj = types.handleObj; var handleObj = types.handleObj;
jQuery( types.delegateTarget ).off( jQuery( types.delegateTarget ).off(
handleObj.namespace? handleObj.type + "." + handleObj.namespace : handleObj.type, handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
handleObj.selector, handleObj.selector,
handleObj.handler handleObj.handler
); );
Expand Down
11 changes: 10 additions & 1 deletion test/unit/event.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2521,7 +2521,7 @@ test(".on and .off", function() {
}); });


test("special bind/delegate name mapping", function() { test("special bind/delegate name mapping", function() {
expect( 6 ); expect( 7 );


jQuery.event.special.slap = { jQuery.event.special.slap = {
bindType: "click", bindType: "click",
Expand Down Expand Up @@ -2561,6 +2561,8 @@ test("special bind/delegate name mapping", function() {
delegateType: "click", delegateType: "click",
handle: function( event ) { handle: function( event ) {
equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" ); equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
// Need to call the handler since .one() uses it to unbind
return event.handleObj.handler.call( this , event );
} }
}; };


Expand All @@ -2579,6 +2581,13 @@ test("special bind/delegate name mapping", function() {
.trigger( "gutfeeling" ) .trigger( "gutfeeling" )
.remove(); .remove();


// Ensure .one() events are removed after their maiden voyage
jQuery( '<p>Gut Feeling</p>' )

This comment has been minimized.

Copy link
@rwaldron

rwaldron Dec 14, 2011

Member

Double quotes please. kthx <3

.one( "gutfeeling", jQuery.noop )
.trigger( "gutfeeling" ) // This one should
.trigger( "gutfeeling" ) // This one should not
.remove();

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


Expand Down

2 comments on commit c584ce4

@martin-g
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you verify that the second doesn't trigger?

@danheberden
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it does trigger, the expect count would be higher, thus failing the test

Please sign in to comment.