﻿Index: misc/tableselect.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tableselect.js,v
retrieving revision 1.9
diff -u -r1.9 tableselect.js
--- misc/tableselect.js	29 Oct 2008 10:01:26 -0000	1.9
+++ misc/tableselect.js	28 Jan 2009 03:09:25 -0000
@@ -7,35 +7,48 @@
 };
 
 Drupal.tableSelect = function() {
-  // Do not add a "Select all" checkbox if there are no rows with checkboxes in the table
+  // Do not add a "Select all" checkbox if there are no rows with checkboxes in the table.
   if ($('td input:checkbox', this).size() == 0) {
     return;
   }
 
   // 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 the select operations links.
+  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 <th> with class select-all, and insert the check all checkbox.
-  $('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);
-    }
-  });
-
+  // Append select operations link to the top and bottom of table.
+  $(table)
+    .before('<div class="select-operations"></span>')
+    .after('<div class="select-operations"></span>');
+  $('.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 +62,29 @@
       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';
Index: modules/system/system.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.css,v
retrieving revision 1.53
diff -u -r1.53 system.css
--- modules/system/system.css	5 Dec 2008 12:50:28 -0000	1.53
+++ modules/system/system.css	28 Jan 2009 03:09:25 -0000
@@ -472,6 +472,9 @@
 /*
 ** To be used with tableselect.js
 */
+table.tableSelect-processed {
+  margin: 0;
+}
 tr.selected td {
   background: #ffc;
 }
