From 68cff6ac407af542f2ee5cac6514f82523876042 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 11 Jul 2016 21:49:30 +0000 Subject: [PATCH] Plugins: Improve Ajax search of installed plugins. Fixes a few accessibility issues, tweaks the design of the search form to match other Ajax search fields and improves compatibility with older browsers. See #37230. git-svn-id: https://develop.svn.wordpress.org/trunk@38033 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/common.css | 1 + src/wp-admin/css/forms.css | 10 ++++++ src/wp-admin/includes/ajax-actions.php | 1 + .../includes/class-wp-plugins-list-table.php | 31 ++++++++++++++++++ src/wp-admin/js/updates.js | 32 +++++++++++++++---- src/wp-admin/plugins.php | 1 + src/wp-includes/script-loader.php | 2 ++ tests/qunit/fixtures/updates.js | 4 ++- 8 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index 906fd5b137..705e64d942 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -582,6 +582,7 @@ code { color: #555d66; font-size: 14px; font-weight: 400; + line-height: 1; } .wrap .add-new-h2, /* deprecated */ diff --git a/src/wp-admin/css/forms.css b/src/wp-admin/css/forms.css index f2198314e1..15be606f8e 100644 --- a/src/wp-admin/css/forms.css +++ b/src/wp-admin/css/forms.css @@ -564,6 +564,16 @@ p.search-box { margin: 0 4px 0 0; } +.js.plugins-php .search-box .wp-filter-search { + margin: 0; + width: 280px; + font-size: 16px; + font-weight: 300; + line-height: 1.5; + padding: 3px 5px; + height: 32px; +} + input[type="text"].ui-autocomplete-loading, input[type="email"].ui-autocomplete-loading { background-image: url(../images/loading.gif); diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index c16f338cdb..5e04365f2f 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3810,6 +3810,7 @@ function wp_ajax_search_plugins() { ob_start(); $wp_list_table->display(); + $status['count'] = count( $wp_list_table->items ); $status['items'] = ob_get_clean(); wp_send_json_success( $status ); diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index c36b77fbac..ddc1ad2338 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -341,6 +341,37 @@ class WP_Plugins_List_Table extends WP_List_Table { _e( 'You do not appear to have any plugins available at this time.' ); } + /** + * Display the search box. + * + * @since 4.6.0 + * @access public + * + * @param string $text The search button text + * @param string $input_id The search input id + */ + public function search_box( $text, $input_id ) { + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { + return; + } + + $input_id = $input_id . '-search-input'; + + if ( ! empty( $_REQUEST['orderby'] ) ) { + echo ''; + } + if ( ! empty( $_REQUEST['order'] ) ) { + echo ''; + } + ?> + + 0 ) { + $pluginSearch.attr( 'aria-describedby', 'live-search-desc' ); + } + /** * Handles changes to the plugin search box on the Installed Plugins screen, * searching the plugin list dynamically. * * @since 4.6.0 */ - $( '#plugin-search-input' ).on( 'keyup search', _.debounce( function() { + $pluginSearch.on( 'keyup input', _.debounce( function( event ) { var data = { _ajax_nonce: wp.updates.ajaxNonce, - s: $( '

' ).html( $( this ).val() ).text() + s: event.target.value }; + // Clear on escape. + if ( 'keyup' === event.type && 27 === event.which ) { + event.target.value = ''; + } + if ( wp.updates.searchTerm === data.s ) { return; } else { wp.updates.searchTerm = data.s; } - history.pushState( null, '', location.href.split( '?' )[0] + '?s=' + data.s ); + if ( history.pushState ) { + history.pushState( null, '', location.href.split( '?' )[ 0 ] + '?s=' + data.s ); + } if ( 'undefined' !== typeof wp.updates.searchRequest ) { wp.updates.searchRequest.abort(); @@ -2045,6 +2059,12 @@ $( 'body' ).removeClass( 'loading-content' ); $bulkActionForm.append( response.items ); delete wp.updates.searchRequest; + + if ( 0 === response.count ) { + wp.a11y.speak( wp.updates.l10n.noPluginsFound ); + } else { + wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) ); + } } ); }, 500 ) ); diff --git a/src/wp-admin/plugins.php b/src/wp-admin/plugins.php index 60107845ea..fd905152fa 100644 --- a/src/wp-admin/plugins.php +++ b/src/wp-admin/plugins.php @@ -371,6 +371,7 @@ get_current_screen()->add_help_tab( array( 'title' => __('Overview'), 'content' => '

' . __('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.') . '

' . + '

' . __( 'The search for installed plugins will search for terms in their name, description, or author.' ) . ' ' . __( 'The search results will be updated as you type.' ) . '

' . '

' . sprintf( /* translators: %s: WordPress Plugin Directory URL */ __( 'If you would like to see more plugins to choose from, click on the “Add New” button and you will be able to browse or search for additional plugins from the WordPress.org Plugin Directory. Plugins in the WordPress.org Plugin Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they’re free!' ), diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 3b1e8fa8a9..2945b480fb 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -653,6 +653,8 @@ function wp_default_scripts( &$scripts ) { 'activateTheme' => is_network_admin() ? __( 'Network Enable' ) : __( 'Activate' ), 'activateImporter' => __( 'Activate importer' ), 'unknownError' => __( 'An unknown error occured' ), + 'pluginsFound' => __( 'Number of plugins found: %d' ), + 'noPluginsFound' => __( 'No plugins found. Try a different search.' ), ), ) ); diff --git a/tests/qunit/fixtures/updates.js b/tests/qunit/fixtures/updates.js index 657ef73308..d570aa67f5 100644 --- a/tests/qunit/fixtures/updates.js +++ b/tests/qunit/fixtures/updates.js @@ -39,7 +39,9 @@ window._wpUpdatesSettings = { 'activatePlugin': 'Activate', 'activateTheme': 'Activate', 'activateImporter': 'Activate importer', - 'unknownError': 'An unknown error occured' + 'unknownError': 'An unknown error occured', + 'pluginsFound': 'Number of plugins found: %d', + 'noPluginsFound': 'No plugins found. Try a different search.' } }; window._wpUpdatesItemCounts = {