Skip to content
Permalink
Browse files

Tests (Simulate): Make the blur event async to deal with IE's native …

…blur being async.
  • Loading branch information...
scottgonzalez committed Nov 1, 2011
1 parent 63d1cbc commit 183d6a00df531b13c638944796b5bc52ca19ecb4
Showing with 16 additions and 11 deletions.
  1. +16 −11 tests/jquery.simulate.js
@@ -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 );
}
});

0 comments on commit 183d6a0

Please sign in to comment.
You can’t perform that action at this time.