From 9bb3494ce99889e05a7333e38e4da9579ce6af8e Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 18 Jun 2012 04:42:24 +0200 Subject: [PATCH] Fix #11925, Pass eventHandle to special.teardown. Closes gh-831. * Added unit test to confirm. The third assertion fails without the fix in ./src/event.js --- src/event.js | 2 +- test/unit/event.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index 6f7252489..33610fd6f 100644 --- a/src/event.js +++ b/src/event.js @@ -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 ); } diff --git a/test/unit/event.js b/test/unit/event.js index a3ba04d8d..401d3e9bf 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -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);