]> source.dussan.org Git - jquery-ui.git/commitdiff
Tests (Simulate): Make the blur event async to deal with IE's native blur being async.
authorScott González <scott.gonzalez@gmail.com>
Tue, 1 Nov 2011 20:35:49 +0000 (16:35 -0400)
committerScott González <scott.gonzalez@gmail.com>
Thu, 12 Jan 2012 14:06:07 +0000 (09:06 -0500)
(cherry picked from commit 183d6a00df531b13c638944796b5bc52ca19ecb4)

tests/jquery.simulate.js

index c1d28f982d99a1dda7d5e47d33591ac281c76c08..adc340049fd7efbaf153bfbf0a87db750f254712 100644 (file)
@@ -194,18 +194,23 @@ $.extend( $.simulate.prototype, {
                element.bind( "blur", trigger );
                element[ 0 ].blur();
 
-               // Some versions of IE don't actually .blur() on an element - so we focus the body
-               if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
-                       element[ 0 ].ownerDocument.body.focus();
-               }
+               // blur events are async in IE
+               setTimeout(function() {
+                       // IE won't let the blur occur if the window is inactive
+                       if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
+                               element[ 0 ].ownerDocument.body.focus();
+                       }
 
-               if ( !triggered ) {
-                       focusoutEvent = $.Event( "focusout" );
-                       focusoutEvent.preventDefault();
-                       element.trigger( focusoutEvent );
-                       element.triggerHandler( "blur" );
-               }
-               element.unbind( "blur", trigger );
+                       // Firefox won't trigger events if the window is inactive
+                       // IE doesn't trigger events if we had to manually focus the body
+                       if ( !triggered ) {
+                               focusoutEvent = $.Event( "focusout" );
+                               focusoutEvent.preventDefault();
+                               element.trigger( focusoutEvent );
+                               element.triggerHandler( "blur" );
+                       }
+                       element.unbind( "blur", trigger );
+               }, 1 );
        }
 });