diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-14 21:25:48 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-11-14 21:25:48 +0000 |
commit | 940b059010a9f391195ea7f73bdabe81eb542328 (patch) | |
tree | ce81ec491a3f9fb148a88b53c0a3abd02f77661d /misc | |
parent | d4833a4fb6141a14b715af12cfbba031ceb59a54 (diff) | |
download | brdo-940b059010a9f391195ea7f73bdabe81eb542328.tar.gz brdo-940b059010a9f391195ea7f73bdabe81eb542328.tar.bz2 |
#154593 by asimmonds and quicksketch:fix select all checkbox in moving table headers
Diffstat (limited to 'misc')
-rw-r--r-- | misc/tableselect.js | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/misc/tableselect.js b/misc/tableselect.js index b19184241..41ba04905 100644 --- a/misc/tableselect.js +++ b/misc/tableselect.js @@ -6,23 +6,28 @@ Drupal.behaviors.tableSelect = function (context) { Drupal.tableSelect = function() { // Keep track of the table, which checkbox is checked and alias the settings. - var table = this, selectAll, checkboxes, lastChecked; + var table = this, checkboxes, lastChecked; var strings = { 'selectAll': Drupal.t('Select all rows in this table'), 'selectNone': Drupal.t('Deselect all rows in this table') }; - - // Store the select all checkbox in a variable as we need it quite often. - selectAll = $('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll).click(function() { - // Loop through all checkboxes and set their state to the select all checkbox' state. - checkboxes.each(function() { - this.checked = selectAll[0].checked; - // Either add or remove the selected class based on the state of the check all checkbox. - $(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected'); + var updateSelectAll = function(state) { + $('th.select-all input:checkbox', table).each(function() { + $(this).attr('title', state ? strings.selectNone : strings.selectAll); + this.checked = state; }); - // Update the title and the state of the check all box. - selectAll.attr('title', selectAll[0].checked ? strings.selectNone : strings.selectAll); - }); + }; // Find all <th> with class select-all, and insert the check all checkbox. - $('th.select-all', table).prepend(selectAll); + $('th.select-all', table).prepend($('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll)).click(function(event) { + if ($(event.target).is('input:checkbox')) { + // Loop through all checkboxes and set their state to the select all checkbox' state. + checkboxes.each(function() { + this.checked = event.target.checked; + // Either add or remove the selected class based on the state of the check all checkbox. + $(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected'); + }); + // Update the title and the state of the check all box. + updateSelectAll(event.target.checked); + } + }); // For each of the checkboxes within the table. checkboxes = $('td input:checkbox', table).click(function(e) { @@ -38,9 +43,7 @@ Drupal.tableSelect = function() { } // If all checkboxes are checked, make sure the select-all one is checked too, otherwise keep unchecked. - selectAll[0].checked = (checkboxes.length == $(checkboxes).filter(':checked').length); - // Set the title to the current action. - selectAll.attr('title', selectAll[0].checked ? strings.selectNone : strings.selectAll); + updateSelectAll((checkboxes.length == $(checkboxes).filter(':checked').length)); // Keep track of the last checked checkbox. lastChecked = e.target; |