From e61fccb9d736235b4b011f89cba6866bc0b8997d Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 31 Oct 2013 22:36:38 -0700 Subject: Event: Remove fixHooks, propHooks; switch to ES5 getter with addProp Fixes gh-3103 Fixes gh-1746 Closes gh-2860 - Removes the copy loop in jQuery.event.fix - Avoids accessing properties such as client/offset/page/screen X/Y which may cause style recalc or layouts - Simplifies adding property hooks to event object --- test/unit/event.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/unit/event.js b/test/unit/event.js index 5b00c7c3b..236214730 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2410,36 +2410,28 @@ QUnit.test( "event object properties on natively-triggered event", function( ass $link.off( "click" ).remove(); } ); -QUnit.test( "fixHooks extensions", function( assert ) { +QUnit.test( "addProp extensions", function( assert ) { assert.expect( 2 ); - // IE requires focusable elements to be visible, so append to body - var $fixture = jQuery( "" ).appendTo( "body" ), - saved = jQuery.event.fixHooks.click; + var $fixture = jQuery( "
" ).appendTo( "#qunit-fixture" ); // Ensure the property doesn't exist $fixture.on( "click", function( event ) { - assert.ok( !( "blurrinessLevel" in event ), "event.blurrinessLevel does not exist" ); + assert.ok( !( "testProperty" in event ), "event.testProperty does not exist" ); } ); fireNative( $fixture[ 0 ], "click" ); $fixture.off( "click" ); - jQuery.event.fixHooks.click = { - filter: function( event ) { - event.blurrinessLevel = 42; - return event; - } - }; + jQuery.event.addProp( "testProperty", function() { return 42; } ); // Trigger a native click and ensure the property is set $fixture.on( "click", function( event ) { - assert.equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" ); + assert.equal( event.testProperty, 42, "event.testProperty getter was invoked" ); } ); fireNative( $fixture[ 0 ], "click" ); + $fixture.off( "click" ); - delete jQuery.event.fixHooks.click; - $fixture.off( "click" ).remove(); - jQuery.event.fixHooks.click = saved; + $fixture.remove(); } ); QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2009)", function( assert ) { -- cgit v1.2.3