<!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>[29220] trunk/src/wp-includes: Keyboard accessibility for the media modal:</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/29220">29220</a></dd>
<dt>Author</dt> <dd>helen</dd>
<dt>Date</dt> <dd>2014-07-18 07:56:25 +0000 (Fri, 18 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Keyboard accessibility for the media modal:

* Arrow keys navigate between items in the grid.
* Transfer focus into the panel when selecting a tab along the side.
* Transfer focus into the details sidebar when selecting an item and vice versa.
* Set initial focus on the close button so that it is visible.

props celloexpressions, lessbloat, ericlewis. fixes <a href="http://core.trac.wordpress.org/ticket/25100">#25100</a>, <a href="http://core.trac.wordpress.org/ticket/25101">#25101</a>, <a href="http://core.trac.wordpress.org/ticket/28704">#28704</a>. see <a href="http://core.trac.wordpress.org/ticket/23560">#23560</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescssmediaviewscss">trunk/src/wp-includes/css/media-views.css</a></li>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/css/media-views.css (29219 => 29220)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/css/media-views.css        2014-07-18 06:07:21 UTC (rev 29219)
+++ trunk/src/wp-includes/css/media-views.css   2014-07-18 07:56:25 UTC (rev 29220)
</span><span class="lines">@@ -723,6 +723,13 @@
</span><span class="cx">          0 0 0 3px #ccc;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.selected.attachment:focus {
+       -webkit-box-shadow: 0 0 0 1px #fff,
+        0 0 0 5px #1e8cbe;
+       box-shadow: 0 0 0 1px #fff,
+        0 0 0 5px #1e8cbe;
+}
+
</ins><span class="cx"> .attachment-preview {
</span><span class="cx">  position: relative;
</span><span class="cx">  width: 199px;
</span><span class="lines">@@ -913,6 +920,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .attachment.details .check,
</span><ins>+.attachment.selected .check:focus,
</ins><span class="cx"> .media-grid-view .attachment.selected .check {
</span><span class="cx">  background-color: #1e8cbe;
</span><span class="cx">  -webkit-box-shadow: 0 0 0 1px #fff,
</span><span class="lines">@@ -935,6 +943,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .attachment.details .check:hover div,
</span><ins>+.attachment.selected .check:focus div,
</ins><span class="cx"> .media-grid-view .attachment.selected .check:hover div {
</span><span class="cx">  background-position: -60px 0;
</span><span class="cx"> }
</span><span class="lines">@@ -1478,6 +1487,14 @@
</span><span class="cx">  box-shadow: none;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.attachment.selection.selected:focus {
+       webkit-box-shadow: 0 0 0 1px #5b9dd9,
+        0 0 2px 2px #5b9dd9;
+       box-shadow: 0 0 0 1px #5b9dd9,
+        0 0 2px 2px #5b9dd9;
+       outline: none;
+}
+
</ins><span class="cx"> .attachment.selection.details {
</span><span class="cx">  -webkit-box-shadow:
</span><span class="cx">          0 0 0 1px #fff,
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (29219 => 29220)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js  2014-07-18 06:07:21 UTC (rev 29219)
+++ trunk/src/wp-includes/js/media-views.js     2014-07-18 07:56:25 UTC (rev 29220)
</span><span class="lines">@@ -758,6 +758,9 @@
</span><span class="cx">                          this.frame.content.mode('browse');
</span><span class="cx">                  }
</span><span class="cx">                  this.get('selection').add( attachment );
</span><ins>+
+                       // Set focus back to where it goes when an attachment is selected.
+                       $( '.attachments-browser .attachments .attachment' ).first().focus();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          /**
</span><span class="lines">@@ -3221,7 +3224,7 @@
</span><span class="cx">                          };
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       $el.show().focus();
</del><ins>+                        $el.show().find( '.media-modal-close' ).focus();
</ins><span class="cx">                   return this.propagate('open');
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="lines">@@ -3302,9 +3305,6 @@
</span><span class="cx">                  if ( 27 === event.which && this.$el.is(':visible') ) {
</span><span class="cx">                          this.escape();
</span><span class="cx">                          event.stopImmediatePropagation();
</span><del>-                       } else {
-                               // Keep focus inside the media modal
-                               this.focusManager;
</del><span class="cx">                   }
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="lines">@@ -4404,6 +4404,10 @@
</span><span class="cx">                  } else {
</span><span class="cx">                          this.click();
</span><span class="cx">                  }
</span><ins>+
+                       // When selecting a tab along the left side,
+                       // focus should be transferred into the main panel
+                       $('.media-frame-content input').first().focus();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          click: function() {
</span><span class="lines">@@ -4735,6 +4739,13 @@
</span><span class="cx">           */
</span><span class="cx">          toggleSelectionHandler: function( event ) {
</span><span class="cx">                  var method;
</span><ins>+
+                       // Catch arrow events
+                       if ( 37 === event.keyCode || 38 === event.keyCode || 39 === event.keyCode || 40 === event.keyCode ) {
+                               this.arrowEvent(event);
+                               return;
+                       }
+
</ins><span class="cx">                   // Catch enter and space events
</span><span class="cx">                  if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
</span><span class="cx">                          return;
</span><span class="lines">@@ -4757,6 +4768,54 @@
</span><span class="cx">                  });
</span><span class="cx">          },
</span><span class="cx">          /**
</span><ins>+                * @param {Object} event
+                */
+               arrowEvent: function( event ) {
+                       var attachment = $('.attachments-browser .attachment'),
+                               attachmentsWidth = $('.attachments-browser .attachments').width(),
+                               thumbnailWidth = attachment.first().innerWidth() + 16,
+                               thumbnailsPerRow = Math.floor(attachmentsWidth/thumbnailWidth),
+                               totalThumnails = attachment.length,
+                               totalRows = Math.ceil(totalThumnails/thumbnailsPerRow),
+                               thisIndex = attachment.filter( ':focus' ).index(),
+                               thisIndexAdjusted = thisIndex + 1,
+                               thisRow = thisIndexAdjusted <= thumbnailsPerRow ? 1 : Math.ceil(thisIndexAdjusted/thumbnailsPerRow);
+
+                               // Left arrow
+                               if ( 37 === event.keyCode ) {
+                                       if ( 0 === thisIndex ) {
+                                               return;
+                                       }
+                                       attachment.eq( thisIndex - 1 ).focus();
+                               }
+
+                               // Up arrow
+                               if ( 38 === event.keyCode ) {
+                                       if ( 1 === thisRow ) {
+                                               return;
+                                       }
+                                       attachment.eq( thisIndex - thumbnailsPerRow ).focus();
+                               }
+
+                               // Right arrow
+                               if ( 39 === event.keyCode ) {
+                                       if ( totalThumnails === thisIndex ) {
+                                               return;
+                                       }
+                                       attachment.eq( thisIndex + 1 ).focus();
+                               }
+
+                               // Down arrow
+                               if ( 40 === event.keyCode ) {
+                                       if ( totalRows === thisRow ) {
+                                               return;
+                                       }
+                                       attachment.eq( thisIndex + thumbnailsPerRow ).focus();
+                               }
+
+                               return false;
+               },
+               /**
</ins><span class="cx">            * @param {Object} options
</span><span class="cx">           */
</span><span class="cx">          toggleSelection: function( options ) {
</span><span class="lines">@@ -4792,6 +4851,10 @@
</span><span class="cx"> 
</span><span class="cx">                          selection.add( models );
</span><span class="cx">                          selection.single( model );
</span><ins>+
+                               // When selecting attachments, focus should be transferred to the right details panel
+                               $('.attachment-details input').first().focus();
+
</ins><span class="cx">                           return;
</span><span class="cx"> 
</span><span class="cx">                  // If the `method` is set to `toggle`, just flip the selection
</span><span class="lines">@@ -4799,6 +4862,12 @@
</span><span class="cx">                  } else if ( 'toggle' === method ) {
</span><span class="cx">                          selection[ this.selected() ? 'remove' : 'add' ]( model );
</span><span class="cx">                          selection.single( model );
</span><ins>+
+                               if ( this.selected() ) {
+                                       // When selecting an attachment, focus should be transferred to the right details panel
+                                       $('.attachment-details input').first().focus();
+                               }
+
</ins><span class="cx">                           return;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><span class="lines">@@ -4850,7 +4919,11 @@
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       this.$el.addClass('selected').attr('aria-checked', true);
</del><ins>+                        this.$el.addClass( 'selected' ).attr( 'aria-checked', true )
+                                       .find( '.check' ).attr( 'tabindex', '0' );
+
+                       // When selecting an attachment, focus should be transferred to the right details panel
+                       $('.attachment-details input').first().focus();
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Backbone.Model} model
</span><span class="lines">@@ -4865,7 +4938,8 @@
</span><span class="cx">                  if ( ! selection || ( collection && collection !== selection ) ) {
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><del>-                       this.$el.removeClass('selected').attr('aria-checked', false);
</del><ins>+                        this.$el.removeClass( 'selected' ).attr( 'aria-checked', false )
+                                       .find( '.check' ).attr( 'tabindex', '-1' );
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Backbone.Model} model
</span><span class="lines">@@ -5027,6 +5101,8 @@
</span><span class="cx">                  event.stopPropagation();
</span><span class="cx">                  if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
</span><span class="cx">                          selection.remove( this.model );
</span><ins>+                               // Move focus back to the attachment tile (from the check).
+                               this.$el.focus();
</ins><span class="cx">                   } else {
</span><span class="cx">                          selection.add( this.model );
</span><span class="cx">                  }
</span><span class="lines">@@ -6237,7 +6313,8 @@
</span><span class="cx">                  'click .delete-attachment':       'deleteAttachment',
</span><span class="cx">                  'click .trash-attachment':        'trashAttachment',
</span><span class="cx">                  'click .edit-attachment':         'editAttachment',
</span><del>-                       'click .refresh-attachment':      'refreshAttachment'
</del><ins>+                        'click .refresh-attachment':      'refreshAttachment',
+                       'keydown':                        'toggleSelectionHandler'
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><span class="lines">@@ -6300,6 +6377,17 @@
</span><span class="cx">                  this.$el.removeClass('needs-refresh');
</span><span class="cx">                  event.preventDefault();
</span><span class="cx">                  this.model.fetch();
</span><ins>+               },
+               /**
+                * @param {Object} event
+                */
+               toggleSelectionHandler: function( event ) {
+                       // Reverse tabbing out of the right details panel
+                       // should take me back to the item in the list that was being edited.
+                       if ( 'keydown' === event.type && 9 === event.keyCode && event.shiftKey && event.target === $( ':tabbable', this.$el ).filter( ':first' )[0] ) {
+                               $('.attachments-browser .details').focus();
+                               return false;
+                       }
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">  });
</span></span></pre>
</div>
</div>

</body>
</html>