Skip to content

Commit c584ce4

Browse files
committed
Fix #10984. Use origType when unbinding via the event object.
1 parent 2a63b98 commit c584ce4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ jQuery.fn.extend({
922922
// ( event ) dispatched jQuery.Event
923923
var handleObj = types.handleObj;
924924
jQuery( types.delegateTarget ).off(
925-
handleObj.namespace? handleObj.type + "." + handleObj.namespace : handleObj.type,
925+
handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
926926
handleObj.selector,
927927
handleObj.handler
928928
);

test/unit/event.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ test(".on and .off", function() {
25212521
});
25222522

25232523
test("special bind/delegate name mapping", function() {
2524-
expect( 6 );
2524+
expect( 7 );
25252525

25262526
jQuery.event.special.slap = {
25272527
bindType: "click",
@@ -2561,6 +2561,8 @@ test("special bind/delegate name mapping", function() {
25612561
delegateType: "click",
25622562
handle: function( event ) {
25632563
equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
2564+
// Need to call the handler since .one() uses it to unbind
2565+
return event.handleObj.handler.call( this , event );
25642566
}
25652567
};
25662568

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

2584+
// Ensure .one() events are removed after their maiden voyage
2585+
jQuery( '<p>Gut Feeling</p>' )
2586+
.one( "gutfeeling", jQuery.noop )
2587+
.trigger( "gutfeeling" ) // This one should
2588+
.trigger( "gutfeeling" ) // This one should not
2589+
.remove();
2590+
25822591
delete jQuery.event.special.gutfeeling;
25832592
});
25842593

0 commit comments

Comments
 (0)