Make WordPress Core

Changeset 38981


Ignore:
Timestamp:
10/27/2016 03:22:52 PM (10 years ago)
Author:
afercia
Message:

Accessibility: Improve the Menus post type meta boxes pagination links.

  • adds hidden text to the pagination links
  • slightly increases the links clickable area
  • fixes a JS error when clicking on the current page number
  • avoids to generate nested <div> elements at each click

Props xavortm, cwpnolen, afercia.

Fixes #35577.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/nav-menus.css

    r38912 r38981  
    694694
    695695.add-menu-item-pagelinks {
    696         margin: .5em auto;
     696        margin: .5em -10px;
    697697        text-align: center;
     698}
     699
     700.add-menu-item-pagelinks .page-numbers {
     701        display: inline-block;
     702        min-width: 20px;
     703}
     704
     705.add-menu-item-pagelinks .page-numbers.dots {
     706        min-width: 0;
    698707}
    699708
  • trunk/src/wp-admin/includes/nav-menu.php

    r38754 r38981  
    359359                ),
    360360                'format' => '',
    361                 'prev_text' => __('&laquo;'),
    362                 'next_text' => __('&raquo;'),
    363                 'total' => $num_pages,
     361                'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
     362                'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
     363                'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
     364                'total'   => $num_pages,
    364365                'current' => $pagenum
    365366        ));
     
    643644                ),
    644645                'format' => '',
    645                 'prev_text' => __('&laquo;'),
    646                 'next_text' => __('&raquo;'),
    647                 'total' => $num_pages,
     646                'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
     647                'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
     648                'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
     649                'total'   => $num_pages,
    648650                'current' => $pagenum
    649651        ));
  • trunk/src/wp-admin/js/nav-menu.js

    r38799 r38981  
    10901090                                                $('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom );
    10911091                                        return false;
    1092                                 } else if ( target.hasClass('page-numbers') ) {
    1093                                         $.post( ajaxurl, e.target.href.replace(/.*\?/, '').replace(/action=([^&]*)/, '') + '&action=menu-get-metabox',
    1094                                                 function( resp ) {
    1095                                                         if ( -1 == resp.indexOf('replace-id') )
    1096                                                                 return;
    1097 
    1098                                                         var metaBoxData = $.parseJSON(resp),
    1099                                                         toReplace = document.getElementById(metaBoxData['replace-id']),
    1100                                                         placeholder = document.createElement('div'),
    1101                                                         wrap = document.createElement('div');
    1102 
    1103                                                         if ( ! metaBoxData.markup || ! toReplace )
    1104                                                                 return;
    1105 
    1106                                                         wrap.innerHTML = metaBoxData.markup ? metaBoxData.markup : '';
    1107 
    1108                                                         toReplace.parentNode.insertBefore( placeholder, toReplace );
    1109                                                         placeholder.parentNode.removeChild( toReplace );
    1110 
    1111                                                         placeholder.parentNode.insertBefore( wrap, placeholder );
    1112 
    1113                                                         placeholder.parentNode.removeChild( placeholder );
    1114 
     1092                                }
     1093                        });
     1094
     1095                        /*
     1096                         * Delegate the `click` event and attach it just to the pagination
     1097                         * links thus excluding the current page `<span>`. See ticket #35577.
     1098                         */
     1099                        $( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() {
     1100                                var $container = $( this ).closest( '.inside' );
     1101
     1102                                $.post( ajaxurl, this.href.replace( /.*\?/, '' ).replace( /action=([^&]*)/, '' ) + '&action=menu-get-metabox',
     1103                                        function( resp ) {
     1104                                                var metaBoxData = $.parseJSON( resp ),
     1105                                                        toReplace;
     1106
     1107                                                if ( -1 === resp.indexOf( 'replace-id' ) ) {
     1108                                                        return;
    11151109                                                }
    1116                                         );
    1117 
    1118                                         return false;
    1119                                 }
     1110
     1111                                                // Get the post type menu meta box to update.
     1112                                                toReplace = document.getElementById( metaBoxData['replace-id'] );
     1113
     1114                                                if ( ! metaBoxData.markup || ! toReplace ) {
     1115                                                        return;
     1116                                                }
     1117
     1118                                                // Update the post type menu meta box with new content from the response.
     1119                                                $container.html( metaBoxData.markup );
     1120                                        }
     1121                                );
     1122
     1123                                return false;
    11201124                        });
    11211125                },
Note: See TracChangeset for help on using the changeset viewer.