<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26922] trunk/src/wp-admin: Keyboard navigation friendliness for themes.php.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26922">26922</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2014-01-08 21:34:03 +0000 (Wed, 08 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Keyboard navigation friendliness for themes.php.

props matveb, azaozz, jorbin.
see <a href="http://core.trac.wordpress.org/ticket/26527">#26527</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsswpadmincss">trunk/src/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunksrcwpadminjsthemejs">trunk/src/wp-admin/js/theme.js</a></li>
<li><a href="#trunksrcwpadminthemesphp">trunk/src/wp-admin/themes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/css/wp-admin.css (26921 => 26922)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/css/wp-admin.css      2014-01-08 21:28:15 UTC (rev 26921)
+++ trunk/src/wp-admin/css/wp-admin.css 2014-01-08 21:34:03 UTC (rev 26922)
</span><span class="lines">@@ -6465,6 +6465,24 @@
</span><span class="cx">  -webkit-transition: opacity 0.1s ease-in-out;
</span><span class="cx">  transition:         opacity 0.1s ease-in-out;
</span><span class="cx"> }
</span><ins>+.theme-browser .theme:focus {
+       outline: 1px dotted #222;
+}
+/* Hide shortcut actions and hover feedback when using tab navigation */
+.theme-browser .theme:focus .theme-actions {
+       display: none;
+}
+/* Restore display of theme controls if you hover a focused theme */
+.theme-browser .theme:focus:hover .theme-actions {
+       display: block;
+}
+.theme-browser .theme:focus .more-details {
+       opacity: 1;
+}
+/* Current theme needs to have its action always on view */
+.theme-browser .theme.active:focus .theme-actions {
+       display: block;
+}
</ins><span class="cx"> 
</span><span class="cx"> .theme-browser.rendered .theme:hover .more-details {
</span><span class="cx">  opacity: 1;
</span><span class="lines">@@ -6690,10 +6708,13 @@
</span><span class="cx">  width: 50px;
</span><span class="cx">  text-align: center;
</span><span class="cx">  float: right;
</span><ins>+       border: 0;
</ins><span class="cx">   border-left: 1px solid #ddd;
</span><ins>+       background-color: transparent;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-.theme-overlay .theme-header .close:hover:before {
</del><ins>+.theme-overlay .theme-header .close:hover:before,
+.theme-overlay .theme-header .close:focus:before {
</ins><span class="cx">   color: #fff;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -6710,20 +6731,21 @@
</span><span class="cx"> .theme-overlay .theme-header .left {
</span><span class="cx">  cursor: pointer;
</span><span class="cx">  color: #777;
</span><ins>+       background-color: transparent;
</ins><span class="cx">   height: 48px;
</span><span class="cx">  width: 54px;
</span><span class="cx">  float: left;
</span><span class="cx">  text-align: center;
</span><ins>+       border: 0;
</ins><span class="cx">   border-right: 1px solid #ddd;
</span><del>-       -webkit-user-select: none;
-       -moz-user-select:    none;
-       -ms-user-select:     none;
-       user-select:         none;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .theme-overlay .theme-header .close:hover,
</span><span class="cx"> .theme-overlay .theme-header .right:hover,
</span><del>-.theme-overlay .theme-header .left:hover {
</del><ins>+.theme-overlay .theme-header .left:hover,
+.theme-overlay .theme-header .close:focus,
+.theme-overlay .theme-header .right:focus,
+.theme-overlay .theme-header .left:focus {
</ins><span class="cx">   background: #0074a2;
</span><span class="cx">  color: #fff;
</span><span class="cx"> }
</span><span class="lines">@@ -6832,7 +6854,8 @@
</span><span class="cx">  background: transparent;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.theme-overlay .theme-actions .delete-theme:hover {
</del><ins>+.theme-overlay .theme-actions .delete-theme:hover,
+.theme-overlay .theme-actions .delete-theme:focus {
</ins><span class="cx">   background: #d54e21;
</span><span class="cx">  color: #fff;
</span><span class="cx">  border-color: #d54e21;
</span></span></pre></div>
<a id="trunksrcwpadminjsthemejs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/js/theme.js (26921 => 26922)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/js/theme.js   2014-01-08 21:28:15 UTC (rev 26921)
+++ trunk/src/wp-admin/js/theme.js      2014-01-08 21:34:03 UTC (rev 26922)
</span><span class="lines">@@ -188,6 +188,7 @@
</span><span class="cx"> 
</span><span class="cx">  events: {
</span><span class="cx">          'click': 'expand',
</span><ins>+               'keydown': 'expand',
</ins><span class="cx">           'touchend': 'expand',
</span><span class="cx">          'touchmove': 'preventExpand'
</span><span class="cx">  },
</span><span class="lines">@@ -197,7 +198,8 @@
</span><span class="cx">  render: function() {
</span><span class="cx">          var data = this.model.toJSON();
</span><span class="cx">          // Render themes using the html template
</span><del>-               this.$el.html( this.html( data ) );
</del><ins>+                this.$el.html( this.html( data ) ).attr( 'tabindex', 0 );
+
</ins><span class="cx">           // Renders active theme styles
</span><span class="cx">          this.activeTheme();
</span><span class="cx"> 
</span><span class="lines">@@ -219,19 +221,27 @@
</span><span class="cx">  expand: function( event ) {
</span><span class="cx">          var self = this;
</span><span class="cx"> 
</span><ins>+               event = event || window.event;
+
+               // 'enter' and 'space' keys expand the details view when a theme is :focused
+               if ( event.type === 'keydown' && ( event.which !== 13 && event.which !== 32 ) ) {
+                       return;
+               }
+
</ins><span class="cx">           // Bail if the user scrolled on a touch device
</span><span class="cx">          if ( this.touchDrag === true ) {
</span><span class="cx">                  return this.touchDrag = false;
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               event = event || window.event;
-
</del><span class="cx">           // Prevent the modal from showing when the user clicks
</span><span class="cx">          // one of the direct action buttons
</span><span class="cx">          if ( $( event.target ).is( '.theme-actions a' ) ) {
</span><span class="cx">                  return;
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               // Set focused theme to current element
+               themes.focusedTheme = this.$el;
+
</ins><span class="cx">           this.trigger( 'theme:expand', self.model.cid );
</span><span class="cx">  },
</span><span class="cx"> 
</span><span class="lines">@@ -266,6 +276,8 @@
</span><span class="cx">          this.navigation();
</span><span class="cx">          // Checks screenshot size
</span><span class="cx">          this.screenshotCheck( this.$el );
</span><ins>+               // Contain "tabbing" inside the overlay
+               this.containFocus( this.$el );
</ins><span class="cx">   },
</span><span class="cx"> 
</span><span class="cx">  // Adds a class to the currently active theme
</span><span class="lines">@@ -275,6 +287,34 @@
</span><span class="cx">          this.$el.toggleClass( 'active', this.model.get( 'active' ) );
</span><span class="cx">  },
</span><span class="cx"> 
</span><ins>+       // Keeps :focus within the theme details elements
+       containFocus: function( $el ) {
+               var $target;
+
+               // Move focus to the primary action
+               _.delay( function() {
+                       $( '.theme-wrap a.button-primary:visible' ).focus();
+               }, 500 );
+
+               $el.on( 'keydown.wp-themes', function( event ) {
+
+                       // Tab key
+                       if ( event.which === 9 ) {
+                               $target = $( event.target );
+
+                               // Keep focus within the overlay by making the last link on theme actions
+                               // switch focus to button.left on tabbing and vice versa
+                               if ( $target.is( 'button.left' ) && event.shiftKey ) {
+                                       $el.find( '.theme-actions a:last-child' ).focus();
+                                       event.preventDefault();
+                               } else if ( $target.is( '.theme-actions a:last-child' ) ) {
+                                       $el.find( 'button.left' ).focus();
+                                       event.preventDefault();
+                               }
+                       }
+               });
+       },
+
</ins><span class="cx">   // Single theme overlay screen
</span><span class="cx">  // It's shown when clicking a theme
</span><span class="cx">  collapse: function( event ) {
</span><span class="lines">@@ -291,7 +331,7 @@
</span><span class="cx">          // Detect if the click is inside the overlay
</span><span class="cx">          // and don't close it unless the target was
</span><span class="cx">          // the div.back button
</span><del>-               if ( $( event.target ).is( '.theme-backdrop' ) || $( event.target ).is( 'div.close' ) || event.keyCode === 27 ) {
</del><ins>+                if ( $( event.target ).is( '.theme-backdrop' ) || $( event.target ).is( '.close' ) || event.keyCode === 27 ) {
</ins><span class="cx"> 
</span><span class="cx">                  // Add a temporary closing class while overlay fades out
</span><span class="cx">                  $( 'body' ).addClass( 'closing-overlay' );
</span><span class="lines">@@ -311,6 +351,11 @@
</span><span class="cx"> 
</span><span class="cx">                          // Restore scroll position
</span><span class="cx">                          document.body.scrollTop = scroll;
</span><ins>+
+                               // Return focus to the theme div
+                               if ( themes.focusedTheme ) {
+                                       themes.focusedTheme.focus();
+                               }
</ins><span class="cx">                   });
</span><span class="cx">          }
</span><span class="cx">  },
</span></span></pre></div>
<a id="trunksrcwpadminthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/themes.php (26921 => 26922)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/themes.php    2014-01-08 21:28:15 UTC (rev 26921)
+++ trunk/src/wp-admin/themes.php       2014-01-08 21:34:03 UTC (rev 26922)
</span><span class="lines">@@ -192,7 +192,7 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> foreach ( $themes as $theme ) : ?>
</span><del>-<div class="theme<?php if ( $theme['active'] ) echo ' active'; ?>">
</del><ins>+<div class="theme<?php if ( $theme['active'] ) echo ' active'; ?>" tabindex="0">
</ins><span class="cx">   <?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
</span><span class="cx">          <div class="theme-screenshot">
</span><span class="cx">                  <img src="<?php echo $theme['screenshot'][0]; ?>" alt="" />
</span><span class="lines">@@ -309,9 +309,9 @@
</span><span class="cx">  <div class="theme-backdrop"></div>
</span><span class="cx">  <div class="theme-wrap">
</span><span class="cx">          <div class="theme-header">
</span><del>-                       <div alt="<?php _e( 'Close overlay' ); ?>" class="close dashicons dashicons-no"></div>
-                       <div alt="<?php _e( 'Show previous theme' ); ?>" class="left dashicons dashicons-no"></div>
-                       <div alt="<?php _e( 'Show next theme' ); ?>" class="right dashicons dashicons-no"></div>
</del><ins>+                        <button alt="<?php _e( 'Show previous theme' ); ?>" class="left dashicons dashicons-no"></button>
+                       <button alt="<?php _e( 'Show next theme' ); ?>" class="right dashicons dashicons-no"></button>
+                       <button alt="<?php _e( 'Close overlay' ); ?>" class="close dashicons dashicons-no"></button>
</ins><span class="cx">           </div>
</span><span class="cx">          <div class="theme-about">
</span><span class="cx">                  <div class="theme-screenshots">
</span></span></pre>
</div>
</div>

</body>
</html>