mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Remove fake originalEvent from jQuery.Event.simulate
Fixes gh-2300 Closes gh-2303
This commit is contained in:
parent
3c92770867
commit
7475d5debe
@ -610,10 +610,14 @@ jQuery.event = {
|
|||||||
event,
|
event,
|
||||||
{
|
{
|
||||||
type: type,
|
type: type,
|
||||||
isSimulated: true,
|
isSimulated: true
|
||||||
originalEvent: {}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// This prevents stopPropagation(), stopImmediatePropagation(), and preventDefault() from
|
||||||
|
// preventing default on the donor event.
|
||||||
|
delete e.originalEvent;
|
||||||
|
|
||||||
if ( bubble ) {
|
if ( bubble ) {
|
||||||
jQuery.event.trigger( e, null, elem );
|
jQuery.event.trigger( e, null, elem );
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +42,11 @@
|
|||||||
<!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
|
<!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
|
||||||
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
|
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
|
||||||
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px;">
|
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px;">
|
||||||
|
<div id="donor-outer">
|
||||||
|
<form id="donor-form">
|
||||||
|
<input id="donor-input" type="radio" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<div id="qunit-fixture">
|
<div id="qunit-fixture">
|
||||||
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
|
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
|
||||||
<p id="ap">
|
<p id="ap">
|
||||||
|
@ -2671,6 +2671,60 @@ test( ".off() removes the expando when there's no more data", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "preventDefault() on focusin does not throw exception", function( assert ) {
|
||||||
|
expect( 1 );
|
||||||
|
|
||||||
|
var done = assert.async(),
|
||||||
|
input = jQuery( "<input/>" ).appendTo( "#form" );
|
||||||
|
input
|
||||||
|
.on( "focusin", function( event ) {
|
||||||
|
var exceptionCaught;
|
||||||
|
|
||||||
|
try {
|
||||||
|
event.preventDefault();
|
||||||
|
} catch ( theException ) {
|
||||||
|
exceptionCaught = theException;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.strictEqual( exceptionCaught, undefined,
|
||||||
|
"Preventing default on focusin throws no exception" );
|
||||||
|
|
||||||
|
done();
|
||||||
|
} )
|
||||||
|
.focus();
|
||||||
|
} );
|
||||||
|
|
||||||
|
test( "jQuery.event.simulate() event has no originalEvent", function( assert ) {
|
||||||
|
expect( 1 );
|
||||||
|
|
||||||
|
var done = assert.async(),
|
||||||
|
input = jQuery( "<input>" )
|
||||||
|
.on( "click", function( event ) {
|
||||||
|
assert.strictEqual( "originalEvent" in event, false,
|
||||||
|
"originalEvent not present on simulated event" );
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
|
||||||
|
jQuery.event.simulate( "click", input[ 0 ], new jQuery.Event(), true );
|
||||||
|
} );
|
||||||
|
|
||||||
|
test( "Donor event interference", function( assert ) {
|
||||||
|
assert.expect( 4 );
|
||||||
|
|
||||||
|
jQuery( "#donor-outer" ).on( "click", function() {
|
||||||
|
assert.ok( true, "click bubbled to outer div" );
|
||||||
|
} );
|
||||||
|
jQuery( "#donor-input" ).on( "click", function( event ) {
|
||||||
|
assert.ok( true, "got a click event from the input" );
|
||||||
|
assert.ok( !event.isPropagationStopped(), "propagation says it's not stopped" );
|
||||||
|
} );
|
||||||
|
jQuery( "#donor-input" ).on( "change", function( event ) {
|
||||||
|
assert.ok( true, "got a change event from the input" );
|
||||||
|
event.stopPropagation();
|
||||||
|
} );
|
||||||
|
jQuery( "#donor-input" )[0].click();
|
||||||
|
} );
|
||||||
|
|
||||||
// This tests are unreliable in Firefox
|
// This tests are unreliable in Firefox
|
||||||
if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
|
if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
|
||||||
test( "Check order of focusin/focusout events", 2, function() {
|
test( "Check order of focusin/focusout events", 2, function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user