Skip to content

Commit

Permalink
Fix #11925, Pass eventHandle to special.teardown. Closes jquerygh-831.
Browse files Browse the repository at this point in the history
* Added unit test to confirm.
  The third assertion fails without the fix in ./src/event.js
  • Loading branch information
Krinkle authored and dmethvin committed Jun 22, 2012
1 parent d2b0c60 commit 9bb3494
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ jQuery.event = {
// Remove generic event handler if we removed something and no more handlers exist
// (avoids potential for endless recursion during removal of special event handlers)
if ( eventType.length === 0 && origCount !== eventType.length ) {
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
jQuery.removeEvent( elem, type, elemData.handle );
}

Expand Down
15 changes: 15 additions & 0 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,21 @@ test("Submit event can be stopped (#11049)", function() {
form.remove();
});

test("on(beforeunload) creates/deletes window property instead of adding/removing event listener", function() {
expect(3);

equal( window.onbeforeunload, null, "window property is null/undefined up until now" );

var handle = function () {};
jQuery(window).on( "beforeunload", handle );

equal( typeof window.onbeforeunload, "function", "window property is set to a function");

jQuery(window).off( "beforeunload", handle );

equal( window.onbeforeunload, null, "window property has been unset to null/undefined" );
})

test("jQuery.Event( type, props )", function() {

expect(5);
Expand Down

0 comments on commit 9bb3494

Please sign in to comment.