Permalink
Browse files

remove link focus, unwind stack before applying focus and tab index

  • Loading branch information...
johnbender committed Aug 24, 2012
1 parent 1b18d97 commit 84163152be7e2344976cc20f4b896cf87315b1f7
Showing with 27 additions and 29 deletions.
  1. +17 −15 js/widgets/popup.js
  2. +10 −14 tests/unit/popup/popup_core.js
View
@@ -398,9 +398,9 @@ define( [ "jquery",
_animate: function( args ) {
if ( this.options.overlayTheme && args.additionalCondition ) {
this._ui.screen
.animationComplete( $.proxy( args.prereqs.screen, "resolve" ) )
.removeClass( args.classToRemove )
.addClass( args.screenClassToAdd )
.animationComplete( $.proxy( args.prereqs.screen, "resolve" ) );
.addClass( args.screenClassToAdd );
} else {
args.prereqs.screen.resolve();
}
@@ -410,9 +410,9 @@ define( [ "jquery",
this._applyTransition( args.transition );
}
this._ui.container
.animationComplete( $.proxy( args.prereqs.container, "resolve" ) )
.addClass( args.containerClassToAdd )
.removeClass( args.classToRemove )
.animationComplete( $.proxy( args.prereqs.container, "resolve" ) );
.removeClass( args.classToRemove );
} else {
args.prereqs.container.resolve();
}
@@ -463,10 +463,19 @@ define( [ "jquery",
},
_openPrereqsComplete: function() {
this._ui.container.addClass( "ui-popup-active" );
this._isOpen = true;
this._ui.container.attr( "tabindex", "0" ).focus();
this._trigger( "afteropen" );
var self = this;
self._ui.container.addClass( "ui-popup-active" );
self._isOpen = true;
// Android appears to trigger the animation complete before the popup
// is visible. Allowing the stack to unwind before applying focus prevents
// the "blue flash" of element focus in android 4.0
setTimeout(function(){
self._ui.container.attr( "tabindex", "0" ).focus();
});
self._trigger( "afteropen" );
},
_open: function( options ) {
@@ -481,8 +490,6 @@ define( [ "jquery",
// Copy out the transition, because we may be overwriting it later and we don't want to pass that change back to the caller
transition = options.transition;
this._link = options.link;
// Give applications a chance to modify the contents of the container before it appears
this._trigger( "beforeposition" );
@@ -543,11 +550,6 @@ define( [ "jquery",
// remove the global mutex for popups
$.mobile.popup.active = undefined;
// if the popup was opened by a link focus is on close
if( this._link ){
this._link.focus();
}
// alert users that the popup is closed
this._trigger( "afterclose" );
},
@@ -416,25 +416,21 @@
]);
});
asyncTest( "Popup link focused on close", function() {
var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" );
asyncTest( "Popup focused after open", function() {
var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" ), eventCount = 0;
expect( 2 );
// make sure the link is blurred
$link.blur();
ok( !$link.is( ":focus" ), "link is not focused to start" );
$popup.popup( "open" );
// check that after the popup is closed the focus is correct
$popup.one( "popupafterclose", function() {
ok( $link.is( ":focus" ), "link is focused after the popup closes" );
start();
});
// open the popup
$link.click();
$popup.one( "popupafteropen", function() {
ok( true, "afteropen has fired" );
// close the popup
$popup.popup( "close" );
$popup.parent().one( "focus", function() {
ok( true, "focus fired after 'afteropen'" );
start();
});
});
});
})( jQuery );

0 comments on commit 8416315

Please sign in to comment.