From 25f206e01fc7fab03e596f707130440d89714628 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 24 Sep 2015 01:07:24 +0000 Subject: [PATCH] List Tables: add JS code to dynamically toggle the `disabled` attribute of the Bulk Actions dropdown and Apply button. Props wonderboymusic, pareshradadiya. Fixes #31634. Built from https://develop.svn.wordpress.org/trunk@34467 git-svn-id: http://core.svn.wordpress.org/trunk@34431 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-list-table.php | 8 ++-- wp-admin/includes/update-core.php | 2 +- wp-admin/js/list-table.js | 46 +++++++++++++++++++++++ wp-admin/js/list-table.min.js | 1 + wp-includes/script-loader.php | 4 +- wp-includes/version.php | 2 +- 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 wp-admin/js/list-table.js create mode 100644 wp-admin/js/list-table.min.js diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index 469601c231..26a44f381c 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -437,14 +437,14 @@ class WP_List_Table { if ( empty( $this->_actions ) ) return; - echo ""; - echo "\n"; + echo '\n"; foreach ( $this->_actions as $name => $title ) { $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; - echo "\t\n"; + echo "\t" . '\n"; } echo "\n"; diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index ac1ac37645..0de0ab33c9 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -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', diff --git a/wp-admin/js/list-table.js b/wp-admin/js/list-table.js new file mode 100644 index 0000000000..10b49a6ba1 --- /dev/null +++ b/wp-admin/js/list-table.js @@ -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)); \ No newline at end of file diff --git a/wp-admin/js/list-table.min.js b/wp-admin/js/list-table.min.js new file mode 100644 index 0000000000..67ec9a08a2 --- /dev/null +++ b/wp-admin/js/list-table.min.js @@ -0,0 +1 @@ +!function(a){"use strict";function b(){return d.find('table .check-column input[type="checkbox"]:checked')}function c(a){var c=b().length;"SELECT"===a.target.tagName&&e.val(a.target.value),e.prop("disabled",!c),f.prop("disabled",!c||-1===parseInt(e.val(),10))}var d,e,f;a(document).ready(function(){d=a(".wp-list-table").closest("form"),d.length&&(e=d.find('select[name="action"], select[name="action2"]').on("change",c).prop("disabled",!0),f=d.find("#doaction, #doaction2").prop("disabled",!0),d.find("table").on("click",".check-column :checkbox",c))})}(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 26a3f8cab7..f5648a7c26 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 260faccc33..2321783070 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34466'; +$wp_version = '4.4-alpha-34467'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.