From 42b5133a2557c0fd58dae731d8694408133ea339 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 23 Sep 2019 12:41:14 +0000 Subject: [PATCH] Accessibility: Menus: Improve the menu items "Select All". - changes "Select All" from a link to a checkbox - the new checkbox is available only when JavaScript support is on - semantically and for accessibility, a checkbox is a better user interface control because the available action is clear to all users and the selected state is communicated natively - it's consistent with the existing pattern for the admin tables Props birgire, audrasjb, afercia. Fixes #47048. git-svn-id: https://develop.svn.wordpress.org/trunk@46240 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/lib/nav-menu.js | 43 +++++++++++++++++++++--------- src/wp-admin/includes/nav-menu.php | 43 ++++++------------------------ 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index 3f1f9a7480..af013fedd6 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -208,7 +208,8 @@ // Add the items api.addItemToMenu(menuItems, processMethod, function(){ // Deselect the items and hide the ajax spinner - checkboxes.removeAttr('checked'); + checkboxes.prop( 'checked', false ); + t.find( '.button-controls .select-all' ).prop( 'checked', false ); t.find( '.button-controls .spinner' ).removeClass( 'is-active' ); }); }); @@ -1061,7 +1062,7 @@ attachTabsPanelListeners : function() { $('#menu-settings-column').bind('click', function(e) { - var selectAreaMatch, panelId, wrapper, items, + var selectAreaMatch, selectAll, panelId, wrapper, items, target = $(e.target); if ( target.hasClass('nav-tab-link') ) { @@ -1071,7 +1072,7 @@ wrapper = target.parents('.accordion-section-content').first(); // upon changing tabs, we want to uncheck all checkboxes - $('input', wrapper).removeAttr('checked'); + $( 'input', wrapper ).prop( 'checked', false ); $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); $('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active'); @@ -1090,15 +1091,28 @@ } e.preventDefault(); - } else if ( target.hasClass('select-all') ) { - selectAreaMatch = /#(.*)$/.exec(e.target.href); - if ( selectAreaMatch && selectAreaMatch[1] ) { - items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input'); - if( items.length === items.filter(':checked').length ) - items.removeAttr('checked'); - else - items.prop('checked', true); - return false; + } else if ( target.hasClass( 'select-all' ) ) { + selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' ); + if ( selectAreaMatch ) { + items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' ); + + if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) { + items.prop( 'checked', false ); + } else if ( target.is( ':checked' ) ) { + items.prop( 'checked', true ); + } + } + } else if ( target.hasClass( 'menu-item-checkbox' ) ) { + selectAreaMatch = target.closest( '.tabs-panel-active' ).parent().attr( 'id' ); + if ( selectAreaMatch ) { + items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' ); + selectAll = $( '.button-controls[data-items-type="' + selectAreaMatch + '"] .select-all' ); + + if ( items.length === items.filter( ':checked' ).length && ! selectAll.is( ':checked' ) ) { + selectAll.prop( 'checked', true ); + } else if ( selectAll.is( ':checked' ) ) { + selectAll.prop( 'checked', false ); + } } } else if ( target.hasClass('submit-add-to-menu') ) { api.registerChange(); @@ -1226,6 +1240,7 @@ pattern = /menu-item[(\[^]\]*/, $items = $('
').html(resp).find('li'), wrapper = panel.closest( '.accordion-section-content' ), + selectAll = wrapper.find( '.button-controls .select-all' ), $item; if( ! $items.length ) { @@ -1260,6 +1275,10 @@ $('.categorychecklist', panel).html( $items ); $( '.spinner', panel ).removeClass( 'is-active' ); wrapper.removeClass( 'has-no-menu-item' ); + + if ( selectAll.is( ':checked' ) ) { + selectAll.prop( 'checked', false ); + } }, /** diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index 25fddcf6a0..11e8c7f92f 100644 --- a/src/wp-admin/includes/nav-menu.php +++ b/src/wp-admin/includes/nav-menu.php @@ -593,11 +593,6 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) { $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); - if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { - $checkbox_items = preg_replace( '/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items ); - - } - echo $checkbox_items; ?> @@ -608,21 +603,10 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
-

- - +

+ + + @@ -848,21 +832,10 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) { -

- - +

+ + +