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);
- }
});
// For each of the checkboxes within the table.
@@ -49,15 +68,33 @@ 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;
+ case 'invert':
+ checked = this.checked = !this.checked;
+ 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';