]> source.dussan.org Git - jquery.git/commitdiff
Event: Remove fake originalEvent from jQuery.Event.simulate
authorGabriel Schulhof <gabriel.schulhof@intel.com>
Tue, 12 May 2015 12:30:05 +0000 (15:30 +0300)
committerOleg Gaidarenko <markelog@gmail.com>
Fri, 29 May 2015 16:56:06 +0000 (19:56 +0300)
Fixes gh-2300
Closes gh-2303

src/event.js
test/index.html
test/unit/event.js

index 361a5489f69ed2ab3cf1f894b5084890352e53ce..9bc875e24c4edda29e59262171127648a6b18f19 100644 (file)
@@ -610,10 +610,14 @@ jQuery.event = {
                        event,
                        {
                                type: type,
-                               isSimulated: true,
-                               originalEvent: {}
+                               isSimulated: true
                        }
                );
+
+               // This prevents stopPropagation(), stopImmediatePropagation(), and preventDefault() from
+               // preventing default on the donor event.
+               delete e.originalEvent;
+
                if ( bubble ) {
                        jQuery.event.trigger( e, null, elem );
                } else {
index 9e232895d8fb218969740f0797afa0276244209c..d8ccdaa454ee57c9ac9c15385daacb9c6f7de516 100644 (file)
        <!-- 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>
        <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">
                <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">
index a84ec087afd45f71805a693ecb352b70291b3a99..981e6702fc6091c48b80bf3bdfa9258bf4e9523f 100644 (file)
@@ -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
 if ( !(/firefox/i.test( window.navigator.userAgent )) ) {
        test( "Check order of focusin/focusout events", 2, function() {