List Tables: add JS code to dynamically toggle the disabled attribute of the Bulk Actions dropdown and Apply button.

Props wonderboymusic, pareshradadiya.
Fixes #31634.


git-svn-id: https://develop.svn.wordpress.org/trunk@34467 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-09-24 01:06:17 +00:00
parent d92723a33f
commit 21dad99c1b
4 changed files with 54 additions and 6 deletions

View File

@ -437,14 +437,14 @@ class WP_List_Table {
if ( empty( $this->_actions ) )
return;
echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . __( 'Select bulk action' ) . "</label>";
echo "<select name='action$two' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n";
foreach ( $this->_actions as $name => $title ) {
$class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
echo "\t<option value='$name'$class>$title</option>\n";
echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n";
}
echo "</select>\n";

View File

@ -279,7 +279,7 @@ $_old_files = array(
'wp-admin/images/logo-login.gif',
'wp-admin/images/star.gif',
'wp-admin/js/list-table.dev.js',
'wp-admin/js/list-table.js',
//'wp-admin/js/list-table.js', // restored in 4.4
'wp-includes/default-embeds.php',
'wp-includes/js/tinymce/plugins/wordpress/img/help.gif',
'wp-includes/js/tinymce/plugins/wordpress/img/more.gif',

View File

@ -0,0 +1,46 @@
/*globals jQuery */
(function ($) {
'use strict';
var listTable,
actions,
doActions;
function getChecked() {
return listTable.find( 'table .check-column input[type="checkbox"]:checked' );
}
/**
* Enable and Disable Apply button in wp-list
*
* @param {jQuery.Event} e
*/
function setApplyButton( e ) {
var checked = getChecked().length;
if ( 'SELECT' === e.target.tagName ) {
actions.val( e.target.value );
}
actions.prop( 'disabled', ! checked );
doActions.prop( 'disabled', ! checked || -1 === parseInt( actions.val(), 10 ) );
}
$(document).ready(function () {
listTable = $( '.wp-list-table' ).closest( 'form' );
if ( ! listTable.length ) {
return;
}
actions = listTable.find( 'select[name="action"], select[name="action2"]' )
.on( 'change', setApplyButton )
.prop( 'disabled', true );
doActions = listTable.find( '#doaction, #doaction2' )
.prop( 'disabled', true );
listTable.find( 'table' ).on( 'click', '.check-column :checkbox', setApplyButton );
});
}(jQuery));

View File

@ -77,7 +77,7 @@ function wp_default_scripts( &$scripts ) {
'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
) );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 );
$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils', 'list-table'), false, 1 );
did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array(
'warnDelete' => __( "You are about to permanently delete the selected items.\n 'Cancel' to stop, 'OK' to delete." ),
'dismiss' => __( 'Dismiss this notice.' ),
@ -396,6 +396,8 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
$scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery' ), false, 1 );
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
$scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery' ), false, 1 );