aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event.js18
-rw-r--r--test/unit/event.js22
2 files changed, 36 insertions, 4 deletions
diff --git a/src/event.js b/src/event.js
index 788bb20eb..a4f02a7a0 100644
--- a/src/event.js
+++ b/src/event.js
@@ -1,6 +1,7 @@
(function( jQuery ) {
-var rnamespaces = /\.(.*)$/,
+var hasOwn = Object.prototype.hasOwnProperty,
+ rnamespaces = /\.(.*)$/,
rformElems = /^(?:textarea|input|select)$/i,
rperiod = /\./g,
rspace = / /g,
@@ -563,7 +564,15 @@ jQuery.Event = function( src ) {
// Event object
if ( src && src.type ) {
this.originalEvent = src;
- this.type = src.type;
+
+ // Push explicitly provided properties onto the event object
+ for ( var prop in src ) {
+ // Ensure we don't clobber jQuery.Event prototype
+ // with own properties.
+ if ( hasOwn.call( src, prop ) ) {
+ this[ prop ] = src[ prop ];
+ }
+ }
// Events bubbling up the document may have been marked as prevented
// by a handler lower down the tree; reflect the correct value.
@@ -852,10 +861,10 @@ function trigger( type, elem, args ) {
// Create "bubbling" focus and blur events
if ( !jQuery.support.focusinBubbles ) {
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
-
+
// Attach a single capturing handler while someone wants focusin/focusout
var attaches = 0;
-
+
jQuery.event.special[ fix ] = {
setup: function() {
if ( attaches++ === 0 ) {
@@ -1168,3 +1177,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
});
})( jQuery );
+
diff --git a/test/unit/event.js b/test/unit/event.js
index 50bf4e174..cefdf5833 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -975,6 +975,27 @@ test("trigger(eventObject, [data], [fn])", function() {
$parent.unbind().remove();
});
+test("jQuery.Event({ /* props */ })", function() {
+
+ expect(4);
+
+ var event = jQuery.Event({ type: "keydown", keyCode: 64 }),
+ handler = function( event ) {
+ ok( "keyCode" in event, "Special property 'keyCode' exists" );
+ equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
+ };
+
+ // Supports jQuery.Event implementation
+ equal( event.type, "keydown", "Verify type" );
+
+ ok( "keyCode" in event, "Special 'keyCode' property exists" );
+
+ jQuery("body").bind( "keydown", handler ).trigger( event );
+
+ jQuery("body").unbind( "keydown" );
+
+});
+
test("jQuery.Event.currentTarget", function(){
expect(1);
@@ -2151,3 +2172,4 @@ test("event properties", function() {
}).click();
});
*/
+