From d9ed166c865e91ccc8cef1ca282785c500ca2306 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 3 Dec 2014 15:56:50 -0500 Subject: [PATCH] Event: Copy detail property to jQuery.Event on native events Fixes gh-1867 --- src/event.js | 2 +- test/unit/event.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index aee6cb78f..44961ef7d 100644 --- a/src/event.js +++ b/src/event.js @@ -460,7 +460,7 @@ jQuery.event = { }, // Includes some event props shared by KeyEvent and MouseEvent - props: ( "altKey bubbles cancelable ctrlKey currentTarget eventPhase " + + props: ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " + "metaKey relatedTarget shiftKey target timeStamp view which" ).split(" "), fixHooks: {}, diff --git a/test/unit/event.js b/test/unit/event.js index 8572c952b..652d83945 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2381,6 +2381,25 @@ test("hover event no longer special since 1.9", function() { .off("hover"); }); +test( "event object properties on natively-triggered event", function() { + expect( 3 ); + + var link = document.createElement( "a" ), + $link = jQuery( link ), + evt = document.createEvent( "MouseEvents" ); + + // IE9+ requires element to be in the body before it will dispatch + $link.appendTo( "body" ).on( "click", function( e ) { + // Not trying to assert specific values here, just ensure the property exists + equal( "detail" in e, true, "has .detail" ); + equal( "cancelable" in e, true, "has .cancelable" ); + equal( "bubbles" in e, true, "has .bubbles" ); + }); + evt.initEvent( "click", true, true ); + link.dispatchEvent( evt ); + $link.off( "click" ).remove(); +}); + test("fixHooks extensions", function() { expect( 2 ); -- 2.39.5