Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 84163152be7e2344976cc20f4b896cf87315b1f7 1 parent 1b18d97
John Bender authored August 24, 2012
32  js/widgets/popup.js
@@ -398,9 +398,9 @@ define( [ "jquery",
398 398
 		_animate: function( args ) {
399 399
 			if ( this.options.overlayTheme && args.additionalCondition ) {
400 400
 				this._ui.screen
  401
+					.animationComplete( $.proxy( args.prereqs.screen, "resolve" ) )
401 402
 					.removeClass( args.classToRemove )
402  
-					.addClass( args.screenClassToAdd )
403  
-					.animationComplete( $.proxy( args.prereqs.screen, "resolve" ) );
  403
+					.addClass( args.screenClassToAdd );
404 404
 			} else {
405 405
 				args.prereqs.screen.resolve();
406 406
 			}
@@ -410,9 +410,9 @@ define( [ "jquery",
410 410
 					this._applyTransition( args.transition );
411 411
 				}
412 412
 				this._ui.container
  413
+					.animationComplete( $.proxy( args.prereqs.container, "resolve" ) )
413 414
 					.addClass( args.containerClassToAdd )
414  
-					.removeClass( args.classToRemove )
415  
-					.animationComplete( $.proxy( args.prereqs.container, "resolve" ) );
  415
+					.removeClass( args.classToRemove );
416 416
 			} else {
417 417
 				args.prereqs.container.resolve();
418 418
 			}
@@ -463,10 +463,19 @@ define( [ "jquery",
463 463
 		},
464 464
 
465 465
 		_openPrereqsComplete: function() {
466  
-			this._ui.container.addClass( "ui-popup-active" );
467  
-			this._isOpen = true;
468  
-			this._ui.container.attr( "tabindex", "0" ).focus();
469  
-			this._trigger( "afteropen" );
  466
+			var self = this;
  467
+
  468
+			self._ui.container.addClass( "ui-popup-active" );
  469
+			self._isOpen = true;
  470
+
  471
+			// Android appears to trigger the animation complete before the popup
  472
+			// is visible. Allowing the stack to unwind before applying focus prevents
  473
+			// the "blue flash" of element focus in android 4.0
  474
+			setTimeout(function(){
  475
+				self._ui.container.attr( "tabindex", "0" ).focus();
  476
+			});
  477
+
  478
+			self._trigger( "afteropen" );
470 479
 		},
471 480
 
472 481
 		_open: function( options ) {
@@ -481,8 +490,6 @@ define( [ "jquery",
481 490
 			// Copy out the transition, because we may be overwriting it later and we don't want to pass that change back to the caller
482 491
 			transition = options.transition;
483 492
 
484  
-			this._link = options.link;
485  
-
486 493
 			// Give applications a chance to modify the contents of the container before it appears
487 494
 			this._trigger( "beforeposition" );
488 495
 
@@ -543,11 +550,6 @@ define( [ "jquery",
543 550
 			// remove the global mutex for popups
544 551
 			$.mobile.popup.active = undefined;
545 552
 
546  
-			// if the popup was opened by a link focus is on close
547  
-			if( this._link ){
548  
-				this._link.focus();
549  
-			}
550  
-
551 553
 			// alert users that the popup is closed
552 554
 			this._trigger( "afterclose" );
553 555
 		},
24  tests/unit/popup/popup_core.js
@@ -416,25 +416,21 @@
416 416
 		]);
417 417
 	});
418 418
 
419  
-	asyncTest( "Popup link focused on close", function() {
420  
-		var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" );
  419
+	asyncTest( "Popup focused after open", function() {
  420
+		var $link = $( "#open-test-popup" ), $popup = $( "#test-popup" ), eventCount = 0;
421 421
 
422 422
 		expect( 2 );
423 423
 
424  
-		// make sure the link is blurred
425  
-		$link.blur();
426  
-		ok( !$link.is( ":focus" ), "link is not focused to start" );
  424
+		$popup.popup( "open" );
427 425
 
428 426
 		// check that after the popup is closed the focus is correct
429  
-		$popup.one( "popupafterclose", function() {
430  
-			ok( $link.is( ":focus" ), "link is focused after the popup closes" );
431  
-			start();
432  
-		});
433  
-
434  
-		// open the popup
435  
-		$link.click();
  427
+		$popup.one( "popupafteropen", function() {
  428
+			ok( true, "afteropen has fired" );
436 429
 
437  
-		// close the popup
438  
-		$popup.popup( "close" );
  430
+			$popup.parent().one( "focus", function() {
  431
+				ok( true, "focus fired after 'afteropen'" );
  432
+				start();
  433
+			});
  434
+		});
439 435
 	});
440 436
 })( jQuery );

0 notes on commit 8416315

Please sign in to comment.
Something went wrong with that request. Please try again.