// $Id: $Drupal.checkAllAttach = function() { // keep track of which checkbox is checked for selecting ranges var checked; // Find all <a> with class check-all, and attach a toggle event to them // so that when the link is clicked, checkboxes within the form are checked // and when the link is clicked again, checkboxes are unchecked $('a.select-all').show().toggle(function() { $('input:checkbox', this.form).each(function() { this.checked = true; $(this).parents('tr').addClass('selected'); }); $(this).html('Select none'); return false; }, function() { $('input:checkbox', this.form).each(function() { this.checked = false; $(this).parents('tr').removeClass('selected'); }); $(this).html('Select all'); return false; }); // If any checkbox is checked in a checkall, highlight it $('form[a.select-all] input:checkbox').click(function(e) { $(this).parents('tr').addClass('selected'); if (e.shiftKey) { from = $(checked).parents('tr')[0]; to = $(e.target).parents('tr')[0]; if (from.rowIndex > to.rowIndex) { temp = to; to = from; from = temp; } // To go row from row, we need to use the checkboxes parent TR selectRange(from, to); } checked = e.target; }); // Select all checkboxes within a range function selectRange(from, to) { // Traverse through the sibling nodes for (var i = from.nextSibling; i; i = i.nextSibling) { // Make sure that we're only dealing with elements if (i.nodeType != 1) continue; // If we find a match then we need to stop if (to.nodeType) { if (i == to) break; } else if (jQuery.filter(to, [i]).r.length) break; $(i).addClass('selected'); $('input:checkbox', i).each(function() { this.checked = true; }); } }}// Global Killswitchif (Drupal.jsEnabled) { $(document).ready(Drupal.checkAllAttach);}