Ticket #47145: 47145.diff
| File 47145.diff, 5.2 KB (added by , 6 years ago) |
|---|
-
src/js/media/views/modal.js
117 117 // Set initial focus on the content instead of this view element, to avoid page scrolling. 118 118 this.$( '.media-modal' ).focus(); 119 119 120 // Hide the page content from assistive technologies. 121 this.hideBodyFromScreenReaders( $el ); 122 120 123 return this.propagate('open'); 121 124 }, 122 125 … … 135 138 // Hide modal and remove restricted media modal tab focus once it's closed 136 139 this.$el.hide().undelegate( 'keydown' ); 137 140 141 /* 142 * Make all body children that have been made hidden when the modal opened 143 * visible again to assistive technologies. 144 */ 145 _.each( $( this.hiddenElements ), function( element ) { 146 element.removeAttribute( 'aria-hidden' ); 147 } ); 148 149 this.hiddenElements = []; 150 this.isBodyHidden = false; 151 138 152 // Move focus back in useful location once modal is closed. 139 153 if ( null !== this.clickedOpenerEl ) { 140 154 // Move focus back to the element that opened the modal. … … 202 216 this.escape(); 203 217 event.stopImmediatePropagation(); 204 218 } 219 }, 220 221 /** 222 * Stores elements that should be hidden from assistive technologies when 223 * the modal opens. 224 */ 225 hiddenElements: [], 226 227 /** 228 * Hides from assistive technologies all elements in the body element except 229 * the provided element and other elements that should not be hidden. 230 * 231 * The reason we do this is because `aria-modal="true"` is buggy in Safari 11.1 232 * and support is spotty in other browsers overall. In the future we should 233 * consider removing these helper functions in favor of `aria-modal="true"`. 234 * 235 * @param {object} dialogElement The jQuery object representing the element that should not be hidden. 236 */ 237 hideBodyFromScreenReaders: function( dialogElement ) { 238 var elements, 239 self = this; 240 241 if ( this.isBodyHidden ) { 242 return; 243 } 244 245 // Get all the body children. 246 elements = document.body.children; 247 248 // Loop through the body children and hide the ones that should be hidden. 249 _.each( elements, function( element ) { 250 // Don't hide the modal element. 251 if ( element === dialogElement[0] ) { 252 return; 253 } 254 255 // Determine the body children to hide. 256 if ( self.elementShouldBeHidden( element ) ) { 257 element.setAttribute( 'aria-hidden', 'true' ); 258 // Store the hidden elements. 259 self.hiddenElements.push( element ); 260 } 261 } ); 262 263 this.isBodyHidden = true; 264 }, 265 266 /** 267 * Determines if the passed element should not be hidden from assistive technologies. 268 * 269 * @param {object} element The DOM element that should be checked. 270 * 271 * @return {boolean} Whether the element should not be hidden from assistive technologies. 272 */ 273 elementShouldBeHidden: function( element ) { 274 var role = element.getAttribute( 'role' ), 275 liveRegionsRoles = [ 'alert', 'status', 'log', 'marquee', 'timer' ]; 276 277 /* 278 * Don't hide scripts, elements that already have `aria-hidden`, and 279 * ARIA live regions. 280 */ 281 return ! ( 282 element.tagName === 'SCRIPT' || 283 element.hasAttribute( 'aria-hidden' ) || 284 element.hasAttribute( 'aria-live' ) || 285 liveRegionsRoles.indexOf( role ) !== -1 286 ); 205 287 } 206 288 }); 207 289 -
src/wp-includes/css/media-views.css
542 542 right: 0; 543 543 bottom: 0; 544 544 margin: 0; 545 padding: 10px 0;545 padding: 50px 0 10px; 546 546 background: #f3f3f3; 547 547 border-right-width: 1px; 548 548 border-right-style: solid; … … 2530 2530 2531 2531 /* Landscape specific header override */ 2532 2532 @media screen and (max-height: 400px) { 2533 .media-menu { 2534 padding: 0; 2533 .media-menu, 2534 .media-frame:not(.hide-menu) .media-menu { 2535 top: 44px; 2535 2536 } 2536 2537 2537 2538 .media-frame-router { -
src/wp-includes/media-template.php
177 177 178 178 <?php // Template for the media frame: used both in the media grid and in the media modal. ?> 179 179 <script type="text/html" id="tmpl-media-frame"> 180 <div class="media-frame-title" id="media-frame-title"></div> 180 181 <div class="media-frame-menu"></div> 181 <div class="media-frame-title"></div>182 182 <div class="media-frame-router"></div> 183 183 <div class="media-frame-content"></div> 184 184 <div class="media-frame-toolbar"></div> … … 187 187 188 188 <?php // Template for the media modal. ?> 189 189 <script type="text/html" id="tmpl-media-modal"> 190 <div tabindex="0" class="<?php echo $class; ?>" >190 <div tabindex="0" class="<?php echo $class; ?>" role="dialog" aria-modal="true" aria-labelledby="media-frame-title"> 191 191 <# if ( data.hasCloseButton ) { #> 192 192 <button type="button" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text"><?php _e( 'Close dialog' ); ?></span></span></button> 193 193 <# } #> 194 <div class="media-modal-content" ></div>194 <div class="media-modal-content" role="document"></div> 195 195 </div> 196 196 <div class="media-modal-backdrop"></div> 197 197 </script>