Plugins: Fix checkbox selection when searching for installed plugins.

Since the plugin search works via Ajax, the JavaScript events need to delegated in order for the checkboxes to work properly.

Props afercia.
Fixes #37973.

git-svn-id: https://develop.svn.wordpress.org/trunk@38703 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2016-10-03 06:36:19 +00:00
parent a39953e1e3
commit fd5d2a65ad
1 changed files with 8 additions and 6 deletions

View File

@ -426,10 +426,11 @@ $document.ready( function() {
// Init screen meta // Init screen meta
screenMeta.init(); screenMeta.init();
// check all checkboxes // This event needs to be delegated. Ticket #37973.
$('tbody').children().children('.check-column').find(':checkbox').click( function(e) { $body.on( 'click', 'tbody .check-column :checkbox', function( even ) {
if ( 'undefined' == e.shiftKey ) { return true; } // Shift click to select a range of checkboxes.
if ( e.shiftKey ) { if ( 'undefined' == event.shiftKey ) { return true; }
if ( event.shiftKey ) {
if ( !lastClicked ) { return true; } if ( !lastClicked ) { return true; }
checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' ); checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' ).filter( ':visible:enabled' );
first = checks.index( lastClicked ); first = checks.index( lastClicked );
@ -447,7 +448,7 @@ $document.ready( function() {
} }
lastClicked = this; lastClicked = this;
// toggle "check all" checkboxes // Toggle the "Select all" checkboxes depending if the other ones are all checked or not.
var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked'); var unchecked = $(this).closest('tbody').find(':checkbox').filter(':visible:enabled').not(':checked');
$(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() { $(this).closest('table').children('thead, tfoot').find(':checkbox').prop('checked', function() {
return ( 0 === unchecked.length ); return ( 0 === unchecked.length );
@ -456,7 +457,8 @@ $document.ready( function() {
return true; return true;
}); });
$('thead, tfoot').find('.check-column :checkbox').on( 'click.wp-toggle-checkboxes', function( event ) { // This event needs to be delegated. Ticket #37973.
$body.on( 'click.wp-toggle-checkboxes', 'thead .check-column :checkbox, tfoot .check-column :checkbox', function( event ) {
var $this = $(this), var $this = $(this),
$table = $this.closest( 'table' ), $table = $this.closest( 'table' ),
controlChecked = $this.prop('checked'), controlChecked = $this.prop('checked'),