]> source.dussan.org Git - jquery.git/commitdiff
Fix #11925, Pass eventHandle to special.teardown. Closes gh-831.
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 18 Jun 2012 02:42:24 +0000 (04:42 +0200)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 22 Jun 2012 19:57:46 +0000 (15:57 -0400)
* Added unit test to confirm.
  The third assertion fails without the fix in ./src/event.js

src/event.js
test/unit/event.js

index 6f7252489d5746bc503be92008cac09b0335a414..33610fd6f32e5796e7871235c4bfc8d943b85024 100644 (file)
@@ -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 );
                                }
 
index a3ba04d8db14411d9b4293f99ee7ffa616100763..401d3e9bf78976aaef75430dae0feecd50176b07 100644 (file)
@@ -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);