<!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>[28607] trunk/src/wp-includes: At long last, improved 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/28607">28607</a></dd>
<dt>Author</dt> <dd>helen</dd>
<dt>Date</dt> <dd>2014-05-29 03:38:31 +0000 (Thu, 29 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>At long last, improved keyboard accessibility for the media modal.

props lessbloat, grahamarmfield, sharonaustin, bramd.
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>
<li><a href="#trunksrcwpincludesmediatemplatephp">trunk/src/wp-includes/media-template.php</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 (28606 => 28607)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/css/media-views.css        2014-05-29 00:58:11 UTC (rev 28606)
+++ trunk/src/wp-includes/css/media-views.css   2014-05-29 03:38:31 UTC (rev 28607)
</span><span class="lines">@@ -478,8 +478,7 @@
</span><span class="cx">  border-right: 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.media-router > a:active,
-.media-router > a:focus {
</del><ins>+.media-router > a:active {
</ins><span class="cx">   outline: none;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -696,6 +695,16 @@
</span><span class="cx">  user-select: none;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.attachment: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"> .selected.attachment {
</span><span class="cx">  -webkit-box-shadow:
</span><span class="cx">          0 0 0 1px #fff,
</span><span class="lines">@@ -925,6 +934,7 @@
</span><span class="cx">  right: 300px;
</span><span class="cx">  bottom: 0;
</span><span class="cx">  overflow: auto;
</span><ins>+       outline: none;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .attachments-browser .instructions {
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (28606 => 28607)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js  2014-05-29 00:58:11 UTC (rev 28606)
+++ trunk/src/wp-includes/js/media-views.js     2014-05-29 03:38:31 UTC (rev 28607)
</span><span class="lines">@@ -2313,6 +2313,12 @@
</span><span class="cx">                                          } else {
</span><span class="cx">                                                  frame.close();
</span><span class="cx">                                          }
</span><ins>+
+                                               // Keep focus inside media modal
+                                               // after canceling a gallery
+                                               new media.view.FocusManager({
+                                                       el: this.el
+                                               }).focus();
</ins><span class="cx">                                   }
</span><span class="cx">                          },
</span><span class="cx">                          separateCancel: new media.View({
</span><span class="lines">@@ -2495,6 +2501,12 @@
</span><span class="cx">                                  }) );
</span><span class="cx"> 
</span><span class="cx">                                  this.controller.setState('gallery-edit');
</span><ins>+
+                                       // Keep focus inside media modal
+                                       // after jumping to gallery view
+                                       new media.view.FocusManager({
+                                               el: this.el
+                                       }).focus();
</ins><span class="cx">                           }
</span><span class="cx">                  });
</span><span class="cx">          },
</span><span class="lines">@@ -2521,6 +2533,12 @@
</span><span class="cx">                                  }) );
</span><span class="cx"> 
</span><span class="cx">                                  this.controller.setState('playlist-edit');
</span><ins>+
+                                       // Keep focus inside media modal
+                                       // after jumping to playlist view
+                                       new media.view.FocusManager({
+                                               el: this.el
+                                       }).focus();
</ins><span class="cx">                           }
</span><span class="cx">                  });
</span><span class="cx">          },
</span><span class="lines">@@ -2547,6 +2565,12 @@
</span><span class="cx">                                  }) );
</span><span class="cx"> 
</span><span class="cx">                                  this.controller.setState('video-playlist-edit');
</span><ins>+
+                                       // Keep focus inside media modal
+                                       // after jumping to video playlist view
+                                       new media.view.FocusManager({
+                                               el: this.el
+                                       }).focus();
</ins><span class="cx">                           }
</span><span class="cx">                  });
</span><span class="cx">          },
</span><span class="lines">@@ -2956,6 +2980,10 @@
</span><span class="cx">                          propagate: true,
</span><span class="cx">                          freeze:    true
</span><span class="cx">                  });
</span><ins>+
+                       this.focusManager = new media.view.FocusManager({
+                               el: this.el
+                       });
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @returns {Object}
</span><span class="lines">@@ -3037,7 +3065,12 @@
</span><span class="cx">                          return this;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       this.$el.hide();
</del><ins>+                        // Hide modal and remove restricted media modal tab focus once it's closed
+                       this.$el.hide().undelegate( 'keydown' );
+
+                       // Put focus back in useful location once modal is closed
+                       $('#wpbody-content').focus();
+
</ins><span class="cx">                   this.propagate('close');
</span><span class="cx"> 
</span><span class="cx">                  // If the `freeze` option is set, restore the container's scroll position.
</span><span class="lines">@@ -3098,6 +3131,9 @@
</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><ins>+                       } else {
+                               // Keep focus inside the media modal
+                               this.focusManager;
</ins><span class="cx">                   }
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="lines">@@ -3117,15 +3153,8 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          focus: function() {
</span><del>-                       if ( _.isUndefined( this.index ) ) {
-                               return;
-                       }
-
-                       // Update our collection of `$tabbables`.
-                       this.$tabbables = this.$(':tabbable');
-
-                       // If tab is saved, focus it.
-                       this.$tabbables.eq( this.index ).focus();
</del><ins>+                        // Reset focus on first left menu item
+                       $('.media-menu-item').first().focus();
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Object} event
</span><span class="lines">@@ -3136,37 +3165,23 @@
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       // First try to update the index.
-                       if ( _.isUndefined( this.index ) ) {
-                               this.updateIndex( event );
</del><ins>+                        // Keep tab focus within media modal while it's open
+                       if ( event.target === this.tabbableLast[0] && !event.shiftKey ) {
+                               this.tabbableFirst.focus();
+                               return false;
+                       } else if ( event.target === this.tabbableFirst[0] && event.shiftKey ) {
+                               this.tabbableLast.focus();
+                               return false;
</ins><span class="cx">                   }
</span><del>-
-                       // If we still don't have an index, bail.
-                       if ( _.isUndefined( this.index ) ) {
-                               return;
-                       }
-
-                       var index = this.index + ( event.shiftKey ? -1 : 1 );
-
-                       if ( index >= 0 && index < this.$tabbables.length ) {
-                               this.index = index;
-                       } else {
-                               delete this.index;
-                       }
</del><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Object} event
</span><span class="cx">           */
</span><span class="cx">          updateIndex: function( event ) {
</span><del>-                       this.$tabbables = this.$(':tabbable');
-
-                       var index = this.$tabbables.index( event.target );
-
-                       if ( -1 === index ) {
-                               delete this.index;
-                       } else {
-                               this.index = index;
-                       }
</del><ins>+                        // Resets tabbable elements
+                       this.tabbables = $( ':tabbable', this.$el );
+                       this.tabbableFirst = this.tabbables.filter( ':first' );
+                       this.tabbableLast = this.tabbables.filter( ':last' );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="lines">@@ -4397,6 +4412,11 @@
</span><span class="cx">          className: 'attachment',
</span><span class="cx">          template:  media.template('attachment'),
</span><span class="cx"> 
</span><ins>+               attributes: {
+                       tabIndex: 0,
+                       role: 'checkbox'
+               },
+
</ins><span class="cx">           events: {
</span><span class="cx">                  'click .attachment-preview':      'toggleSelectionHandler',
</span><span class="cx">                  'change [data-setting]':          'updateSetting',
</span><span class="lines">@@ -4405,7 +4425,8 @@
</span><span class="cx">                  'change [data-setting] textarea': 'updateSetting',
</span><span class="cx">                  'click .close':                   'removeFromLibrary',
</span><span class="cx">                  'click .check':                   'removeFromSelection',
</span><del>-                       'click a':                        'preventDefault'
</del><ins>+                        'click a':                        'preventDefault',
+                       'keydown':                        'toggleSelectionHandler'
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          buttons: {},
</span><span class="lines">@@ -4413,6 +4434,7 @@
</span><span class="cx">          initialize: function() {
</span><span class="cx">                  var selection = this.options.selection;
</span><span class="cx"> 
</span><ins>+                       this.$el.attr('aria-label', this.model.attributes.title).attr('aria-checked', false);
</ins><span class="cx">                   this.model.on( 'change:sizes change:uploading', this.render, this );
</span><span class="cx">                  this.model.on( 'change:title', this._syncTitle, this );
</span><span class="cx">                  this.model.on( 'change:caption', this._syncCaption, this );
</span><span class="lines">@@ -4517,6 +4539,10 @@
</span><span class="cx">          toggleSelectionHandler: function( event ) {
</span><span class="cx">                  var method;
</span><span class="cx"> 
</span><ins>+                       // Catch enter and space events
+                       if ( 'keydown' === event.type && 13 !== event.keyCode && 32 !== event.keyCode ) {
+                               return;
+                       }
</ins><span class="cx">                   if ( event.shiftKey ) {
</span><span class="cx">                          method = 'between';
</span><span class="cx">                  } else if ( event.ctrlKey || event.metaKey ) {
</span><span class="lines">@@ -4573,6 +4599,10 @@
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><ins>+                       // Fixes bug that loses focus when selecting a featured image
+                       if ( !method ) {
+                               method = 'add';
+                       }
</ins><span class="cx">                   if ( method !== 'add' ) {
</span><span class="cx">                          method = 'reset';
</span><span class="cx">                  }
</span><span class="lines">@@ -4617,7 +4647,7 @@
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><span class="cx"> 
</span><del>-                       this.$el.addClass('selected');
</del><ins>+                        this.$el.addClass('selected').attr('aria-checked', true);
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Backbone.Model} model
</span><span class="lines">@@ -4632,7 +4662,7 @@
</span><span class="cx">                  if ( ! selection || ( collection && collection !== selection ) ) {
</span><span class="cx">                          return;
</span><span class="cx">                  }
</span><del>-                       this.$el.removeClass('selected');
</del><ins>+                        this.$el.removeClass('selected').attr('aria-checked', false);
</ins><span class="cx">           },
</span><span class="cx">          /**
</span><span class="cx">           * @param {Backbone.Model} model
</span><span class="lines">@@ -4865,6 +4895,10 @@
</span><span class="cx">          tagName:   'ul',
</span><span class="cx">          className: 'attachments',
</span><span class="cx"> 
</span><ins>+               attributes: {
+                       tabIndex: -1
+               },
+
</ins><span class="cx">           cssTemplate: media.template('attachments-css'),
</span><span class="cx"> 
</span><span class="cx">          events: {
</span><span class="lines">@@ -5579,6 +5613,12 @@
</span><span class="cx">          clear: function( event ) {
</span><span class="cx">                  event.preventDefault();
</span><span class="cx">                  this.collection.reset();
</span><ins>+
+                       // Keep focus inside media modal
+                       // after clear link is selected
+                       new media.view.FocusManager({
+                               el: this.el
+                       }).focus();
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="lines">@@ -5904,12 +5944,6 @@
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><span class="cx">                  /**
</span><del>-                        * @member {wp.media.view.FocusManager}
-                        */
-                       this.focusManager = new media.view.FocusManager({
-                               el: this.el
-                       });
-                       /**
</del><span class="cx">                    * call 'initialize' directly on the parent class
</span><span class="cx">                   */
</span><span class="cx">                  media.view.Attachment.prototype.initialize.apply( this, arguments );
</span><span class="lines">@@ -5922,7 +5956,6 @@
</span><span class="cx">                   * call 'render' directly on the parent class
</span><span class="cx">                   */
</span><span class="cx">                  media.view.Attachment.prototype.render.apply( this, arguments );
</span><del>-                       this.focusManager.focus();
</del><span class="cx">                   return this;
</span><span class="cx">          },
</span><span class="cx">          /**
</span><span class="lines">@@ -5933,6 +5966,11 @@
</span><span class="cx"> 
</span><span class="cx">                  if ( confirm( l10n.warnDelete ) ) {
</span><span class="cx">                          this.model.destroy();
</span><ins>+                               // Keep focus inside media modal
+                               // after image is deleted
+                               new media.view.FocusManager({
+                                       el: this.el
+                               }).focus();
</ins><span class="cx">                   }
</span><span class="cx">          },
</span><span class="cx">          /**
</span><span class="lines">@@ -5988,13 +6026,6 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       /**
-                        * @member {wp.media.view.FocusManager}
-                        */
-                       this.focusManager = new media.view.FocusManager({
-                               el: this.el
-                       });
-
</del><span class="cx">                   this.model.on( 'change:compat', this.render, this );
</span><span class="cx">          },
</span><span class="cx">          /**
</span><span class="lines">@@ -6021,8 +6052,6 @@
</span><span class="cx">                  this.views.detach();
</span><span class="cx">                  this.$el.html( compat.item );
</span><span class="cx">                  this.views.render();
</span><del>-
-                       this.focusManager.focus();
</del><span class="cx">                   return this;
</span><span class="cx">          },
</span><span class="cx">          /**
</span></span></pre></div>
<a id="trunksrcwpincludesmediatemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/media-template.php (28606 => 28607)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/media-template.php 2014-05-29 00:58:11 UTC (rev 28606)
+++ trunk/src/wp-includes/media-template.php    2014-05-29 03:38:31 UTC (rev 28607)
</span><span class="lines">@@ -119,6 +119,16 @@
</span><span class="cx">  if ( $is_IE && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false )
</span><span class="cx">          $class .= ' ie7';
</span><span class="cx">  ?>
</span><ins>+       <!--[if lte IE 8]>
+       <style>
+               .attachment:focus {
+                       outline: #1e8cbe solid;
+               }
+               .selected.attachment {
+                       outline: #1e8cbe solid;
+               }
+       </style>
+       <![endif]-->
</ins><span class="cx">   <script type="text/html" id="tmpl-media-frame">
</span><span class="cx">          <div class="media-frame-menu"></div>
</span><span class="cx">          <div class="media-frame-title"></div>
</span><span class="lines">@@ -238,7 +248,7 @@
</span><span class="cx">                  <# } else if ( 'image' === data.type ) { #>
</span><span class="cx">                          <div class="thumbnail">
</span><span class="cx">                                  <div class="centered">
</span><del>-                                               <img src="{{ data.size.url }}" draggable="false" />
</del><ins>+                                                <img src="{{ data.size.url }}" draggable="false" alt="" />
</ins><span class="cx">                                   </div>
</span><span class="cx">                          </div>
</span><span class="cx">                  <# } else { #>
</span><span class="lines">@@ -253,7 +263,7 @@
</span><span class="cx">                  <# } #>
</span><span class="cx"> 
</span><span class="cx">                  <# if ( data.buttons.check ) { #>
</span><del>-                               <a class="check" href="#" title="<?php esc_attr_e('Deselect'); ?>"><div class="media-modal-icon"></div></a>
</del><ins>+                                <a class="check" href="#" title="<?php esc_attr_e('Deselect'); ?>" tabindex="-1"><div class="media-modal-icon"></div></a>
</ins><span class="cx">                   <# } #>
</span><span class="cx">          </div>
</span><span class="cx">          <#
</span></span></pre>
</div>
</div>

</body>
</html>