=== modified file 'misc/tableselect.js' --- misc/tableselect.js 2008-12-06 09:01:58 +0000 +++ misc/tableselect.js 2009-01-26 15:19:01 +0000 @@ -14,28 +14,34 @@ Drupal.tableSelect = function() { // Keep track of the table, which checkbox is checked and alias the settings. 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') }; - var updateSelectAll = function(state) { - $('th.select-all input:checkbox', table).each(function() { - $(this).attr('title', state ? strings.selectNone : strings.selectAll); - this.checked = state; + var strings = { 'selectAll': Drupal.t('Select all rows in this table'), 'selectAllLabel' : Drupal.t('All'), 'selectNone': Drupal.t('Deselect all rows in this table'), 'selectNoneLabel' : Drupal.t('None') }; + + // Create select operations link + select_all_link = $(document.createElement('a')) + .addClass('select-operation select-all') + .attr('href', '#') + .html(strings.selectAllLabel) + .click(function(){ + Drupal.selectOperation('all', checkboxes); + return false; + }); + select_none_link = $(document.createElement('a')) + .addClass('select-operation select-none') + .attr('href', '#') + .html(strings.selectNoneLabel) + .click(function(){ + Drupal.selectOperation('none', checkboxes); + return false; }); - }; - - // Find all with class select-all, and insert the check all checkbox. - $('th.select-all', table).prepend($('').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); - } - }); + // Append select operations link to the top and bottom of table + $(table).before('
').after('
'); + $('.select-operations') + .append('Select: ') + .append(select_all_link) + .append(', ') + .append(select_none_link) + // For each of the checkboxes within the table. checkboxes = $('td input:checkbox', table).click(function(e) { // Either add or remove the selected class based on the state of the check all checkbox. @@ -49,15 +55,29 @@ Drupal.tableSelect = function() { Drupal.tableSelectRange($(e.target).parents('tr')[0], $(lastChecked).parents('tr')[0], e.target.checked); } - // If all checkboxes are checked, make sure the select-all one is checked too, otherwise keep unchecked. - updateSelectAll((checkboxes.length == $(checkboxes).filter(':checked').length)); - // Keep track of the last checked checkbox. lastChecked = e.target; }); $(this).addClass('tableSelect-processed'); }; +Drupal.selectOperation = function(operation, checkboxes) { + var checked; + // Loop through each checkbox and set the checked status according to the operation + checkboxes.each(function() { + switch (operation) { + case 'all': + checked = this.checked = true; + break; + case 'none': + checked = this.checked = false; + break; + } + // Either add or remove the selected class based on the checked status + $(this).parents('tr:first')[ checked ? 'addClass' : 'removeClass' ]('selected'); + }); +} + Drupal.tableSelectRange = function(from, to, state) { // We determine the looping mode based on the the order of from and to. var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling'; === modified file 'modules/system/system.css' --- modules/system/system.css 2008-12-06 09:01:58 +0000 +++ modules/system/system.css 2009-01-26 15:47:35 +0000 @@ -472,6 +472,9 @@ tr .ahah-progress .throbber { /* ** To be used with tableselect.js */ +table.tableSelect-processed { + margin-top: 0.2em; +} tr.selected td { background: #ffc; }