Skip to content

Commit aa9ca2b

Browse files
committed
Tests (Simulate): Make the blur event async to deal with IE's native blur being async.
(cherry picked from commit 183d6a0)
1 parent 069c645 commit aa9ca2b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/jquery.simulate.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,23 @@ $.extend( $.simulate.prototype, {
194194
element.bind( "blur", trigger );
195195
element[ 0 ].blur();
196196

197-
// Some versions of IE don't actually .blur() on an element - so we focus the body
198-
if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
199-
element[ 0 ].ownerDocument.body.focus();
200-
}
197+
// blur events are async in IE
198+
setTimeout(function() {
199+
// IE won't let the blur occur if the window is inactive
200+
if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
201+
element[ 0 ].ownerDocument.body.focus();
202+
}
201203

202-
if ( !triggered ) {
203-
focusoutEvent = $.Event( "focusout" );
204-
focusoutEvent.preventDefault();
205-
element.trigger( focusoutEvent );
206-
element.triggerHandler( "blur" );
207-
}
208-
element.unbind( "blur", trigger );
204+
// Firefox won't trigger events if the window is inactive
205+
// IE doesn't trigger events if we had to manually focus the body
206+
if ( !triggered ) {
207+
focusoutEvent = $.Event( "focusout" );
208+
focusoutEvent.preventDefault();
209+
element.trigger( focusoutEvent );
210+
element.triggerHandler( "blur" );
211+
}
212+
element.unbind( "blur", trigger );
213+
}, 1 );
209214
}
210215
});
211216

0 commit comments

Comments
 (0)