mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
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
This commit is contained in:
committed by
Dave Methvin
parent
7f2ebd2c4d
commit
e61fccb9d7
@@ -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( "<input type='text' id='hook-fixture' />" ).appendTo( "body" ),
|
||||
saved = jQuery.event.fixHooks.click;
|
||||
var $fixture = jQuery( "<div>" ).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 ) {
|
||||
|
||||
Reference in New Issue
Block a user