From 2df590e4ecfb8874b1deaca26d3c4cc2b7f7b140 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Thu, 2 Jun 2016 18:33:47 -0400 Subject: [PATCH] Event: Allow constructing a jQuery.Event without a target Fixes gh-3139 Closes gh-3140 --- src/event.js | 2 +- test/unit/event.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index ff0ab8493..d64b9b6cb 100644 --- a/src/event.js +++ b/src/event.js @@ -527,7 +527,7 @@ jQuery.Event = function( src, props ) { // Create target properties // Support: Safari <=6 - 7 only // Target should not be a text node (#504, #13143) - this.target = ( src.target.nodeType === 3 ) ? + this.target = ( src.target && src.target.nodeType === 3 ) ? src.target.parentNode : src.target; diff --git a/test/unit/event.js b/test/unit/event.js index 99797061f..fef3b173e 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2736,6 +2736,15 @@ QUnit.test( ".off() removes the expando when there's no more data", function( as } } ); +QUnit.test( "jQuery.Event( src ) does not require a target property", function( assert ) { + assert.expect( 2 ); + + var event = jQuery.Event( { type: "offtarget" } ); + + assert.equal( event.type, "offtarget", "correct type" ); + assert.equal( event.target, undefined, "no target" ); +} ); + QUnit.test( "preventDefault() on focusin does not throw exception", function( assert ) { assert.expect( 1 ); -- 2.39.5