Skip to content

Commit 841e7fa

Browse files
committed
Event: remove outdated originalEvent hack
Ref jquerygh-2300 Ref 2506c5d
1 parent 2506c5d commit 841e7fa

File tree

2 files changed

+89
-22
lines changed

2 files changed

+89
-22
lines changed

src/event.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,6 @@ jQuery.event = {
602602
},
603603

604604
simulate: function( type, elem, event, bubble ) {
605-
// Piggyback on a donor event to simulate a different one.
606-
// Fake originalEvent to avoid donor's stopPropagation, but if the
607-
// simulated event prevents default then we do the same on the donor.
608605
var e = jQuery.extend(
609606
new jQuery.Event(),
610607
event,
@@ -614,10 +611,6 @@ jQuery.event = {
614611
}
615612
);
616613

617-
// This prevents stopPropagation(), stopImmediatePropagation(), and preventDefault() from
618-
// preventing default on the donor event.
619-
delete e.originalEvent;
620-
621614
if ( bubble ) {
622615
jQuery.event.trigger( e, null, elem );
623616
} else {

test/unit/event.js

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,37 +2701,111 @@ test( "preventDefault() on focusin does not throw exception", function( assert )
27012701
.focus();
27022702
} );
27032703

2704-
test( "jQuery.event.simulate() event has no originalEvent", function( assert ) {
2705-
expect( 1 );
2704+
test( "Donor event interference", function( assert ) {
2705+
assert.expect( 10 );
27062706

2707-
var done = assert.async(),
2708-
input = jQuery( "<input>" )
2709-
.on( "click", function( event ) {
2710-
assert.strictEqual( "originalEvent" in event, false,
2711-
"originalEvent not present on simulated event" );
2712-
done();
2713-
} );
2714-
2715-
jQuery.event.simulate( "click", input[ 0 ], new jQuery.Event(), true );
2716-
} );
2707+
var html = "<div id='donor-outer'>" +
2708+
"<form id='donor-form'>" +
2709+
"<input id='donor-input' type='radio' />" +
2710+
"</form>" +
2711+
"</div>";
27172712

2718-
test( "Donor event interference", function( assert ) {
2719-
assert.expect( 4 );
2713+
jQuery( "#qunit-fixture" ).append( html );
27202714

2721-
jQuery( "#donor-outer" ).on( "click", function() {
2715+
jQuery( "#donor-outer" ).on( "click", function( event ) {
27222716
assert.ok( true, "click bubbled to outer div" );
2717+
assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
2718+
assert.equal( event.type, "click", "make sure event type is correct" );
27232719
} );
27242720
jQuery( "#donor-input" ).on( "click", function( event ) {
27252721
assert.ok( true, "got a click event from the input" );
27262722
assert.ok( !event.isPropagationStopped(), "propagation says it's not stopped" );
2723+
assert.equal( event.type, "click", "make sure event type is correct" );
2724+
assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
27272725
} );
27282726
jQuery( "#donor-input" ).on( "change", function( event ) {
2727+
assert.equal( typeof event.originalEvent, "object", "make sure originalEvent exist" );
2728+
assert.equal( event.type, "change", "make sure event type is correct" );
27292729
assert.ok( true, "got a change event from the input" );
27302730
event.stopPropagation();
27312731
} );
27322732
jQuery( "#donor-input" )[0].click();
27332733
} );
27342734

2735+
test( "originalEvent property for IE8", function( assert ) {
2736+
if ( !(/msie 8\.0/i.test( window.navigator.userAgent )) ) {
2737+
assert.expect( 1 );
2738+
assert.ok( true, "Assertions should run only in IE" );
2739+
return;
2740+
}
2741+
2742+
assert.expect( 12 );
2743+
2744+
var html = "<div id='donor-outer'>" +
2745+
"<form id='donor-form'>" +
2746+
"<input id='donor-input' type='radio' />" +
2747+
"</form>" +
2748+
"</div>";
2749+
2750+
jQuery( "#qunit-fixture" ).append( html );
2751+
2752+
jQuery( "#donor-outer" ).on( "change", function( event ) {
2753+
assert.ok( true, "click bubbled to outer div" );
2754+
assert.equal( event.originalEvent.type, "click", "make sure simulated event is a click" );
2755+
assert.equal( event.type, "change", "make sure event type is correct" );
2756+
} );
2757+
2758+
jQuery( "#donor-outer" ).on( "click", function( event ) {
2759+
assert.ok( true, "click bubbled to outer div" );
2760+
assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
2761+
} );
2762+
jQuery( "#donor-input" ).on( "click", function( event ) {
2763+
assert.ok( true, "got a click event from the input" );
2764+
assert.ok( !event.isPropagationStopped(), "propagation says it's not stopped" );
2765+
assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
2766+
assert.equal( event.type, "click", "make sure event type is correct" );
2767+
} );
2768+
jQuery( "#donor-input" ).on( "change", function( event ) {
2769+
assert.equal( event.originalEvent.type, "click", "make sure originalEvent exist" );
2770+
assert.equal( event.type, "change", "make sure event type is correct" );
2771+
assert.ok( true, "got a change event from the input" );
2772+
} );
2773+
jQuery( "#donor-input" )[0].click();
2774+
} );
2775+
2776+
test( "originalEvent property for Chrome, Safari and FF of simualted event", function( assert ) {
2777+
var userAgent = window.navigator.userAgent;
2778+
2779+
if ( !(/chrome/i.test( userAgent ) ||
2780+
/firefox/i.test( userAgent ) ||
2781+
/safari/i.test( userAgent ) ) ) {
2782+
assert.expect( 1 );
2783+
assert.ok( true, "Assertions should run only in Chrome, Safari and FF" );
2784+
return;
2785+
}
2786+
2787+
assert.expect( 4 );
2788+
2789+
var html = "<div id='donor-outer'>" +
2790+
"<form id='donor-form'>" +
2791+
"<input id='donor-input' type='radio' />" +
2792+
"</form>" +
2793+
"</div>";
2794+
2795+
jQuery( "#qunit-fixture" ).append( html );
2796+
2797+
jQuery( "#donor-outer" ).on( "focusin", function( event ) {
2798+
assert.ok( true, "focusin bubbled to outer div" );
2799+
assert.equal( event.originalEvent.type, "focus",
2800+
"make sure originalEvent type is correct" );
2801+
assert.equal( event.type, "focusin", "make sure type is correct" );
2802+
} );
2803+
jQuery( "#donor-input" ).on( "focus", function() {
2804+
assert.ok( true, "got a focus event from the input" );
2805+
} );
2806+
jQuery( "#donor-input" )[0].focus();
2807+
} );
2808+
27352809
// This tests are unreliable in Firefox
27362810
if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
27372811
test( "Check order of focusin/focusout events", 2, function() {

0 commit comments

Comments
 (0)