summaryrefslogtreecommitdiff
path: root/misc/tableselect.js
diff options
context:
space:
mode:
Diffstat (limited to 'misc/tableselect.js')
-rw-r--r--misc/tableselect.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/misc/tableselect.js b/misc/tableselect.js
index 1abda24d9..5a88ac20c 100644
--- a/misc/tableselect.js
+++ b/misc/tableselect.js
@@ -2,13 +2,14 @@
Drupal.behaviors.tableSelect = {
attach: function (context, settings) {
- $('table:has(th.select-all)', context).once('table-select', Drupal.tableSelect);
+ // Select the inner-most table in case of nested tables.
+ $('th.select-all', context).closest('table').once('table-select', Drupal.tableSelect);
}
};
Drupal.tableSelect = function () {
// Do not add a "Select all" checkbox if there are no rows with checkboxes in the table
- if ($('td input:checkbox', this).size() == 0) {
+ if ($('td input:checkbox', this).length == 0) {
return;
}
@@ -29,7 +30,7 @@ Drupal.tableSelect = function () {
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');
+ $(this).closest('tr').toggleClass('selected', this.checked);
});
// Update the title and the state of the check all box.
updateSelectAll(event.target.checked);
@@ -39,14 +40,14 @@ Drupal.tableSelect = function () {
// For each of the checkboxes within the table that are not disabled.
checkboxes = $('td input:checkbox:enabled', table).click(function (e) {
// 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');
+ $(this).closest('tr').toggleClass('selected', this.checked);
// If this is a shift click, we need to highlight everything in the range.
// Also make sure that we are actually checking checkboxes over a range and
// that a checkbox has been checked or unchecked before.
if (e.shiftKey && lastChecked && lastChecked != e.target) {
// We use the checkbox's parent TR to do our range searching.
- Drupal.tableSelectRange($(e.target).parents('tr')[0], $(lastChecked).parents('tr')[0], e.target.checked);
+ Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
}
// If all checkboxes are checked, make sure the select-all one is checked too, otherwise keep unchecked.
@@ -69,7 +70,7 @@ Drupal.tableSelectRange = function (from, to, state) {
}
// Either add or remove the selected class based on the state of the target checkbox.
- $(i)[ state ? 'addClass' : 'removeClass' ]('selected');
+ $(i).toggleClass('selected', state);
$('input:checkbox', i).each(function () {
this.checked = state;
});