diff --git a/core/misc/tableheader.js b/core/misc/tableheader.js index 364cad2..c5cb1ac 100644 --- a/core/misc/tableheader.js +++ b/core/misc/tableheader.js @@ -174,8 +174,9 @@ $.extend(TableHeader.prototype, { * Create the duplicate header. */ createSticky: function () { - // Clone the table header so it inherits original jQuery properties. - var $stickyHeader = this.$originalHeader.clone(true); + // Deep clone the table header so it and its children inherit their original + // jQuery properties. + var $stickyHeader = this.$originalHeader.clone(true, true); // Hide the table to avoid a flash of the header clone upon page load. this.$stickyTable = $('') .css({ @@ -190,6 +191,9 @@ $.extend(TableHeader.prototype, { // Initialize all computations. this.recalculateSticky(); + + // Let other scripts know a sticky table header was created. + this.$stickyTable.trigger('stickyTableCreated'); }, /** diff --git a/core/misc/tableselect.js b/core/misc/tableselect.js index 36af864..af46565 100644 --- a/core/misc/tableselect.js +++ b/core/misc/tableselect.js @@ -1,93 +1,191 @@ -(function ($) { +(function ($, Drupal) { "use strict"; -Drupal.behaviors.tableSelect = { - attach: function (context, settings) { - // Select the inner-most table in case of nested tables. - $(context).find('th.select-all').closest('table').once('table-select', Drupal.tableSelect); - } -}; +Drupal.behaviors.TableSelect = { + attach: function (context) { + var $selectAllHeaders = $(context).find('th.select-all'); + tableSelectInitHandler($selectAllHeaders); + }, -Drupal.tableSelect = function () { - // Do not add a "Select all" checkbox if there are no rows with checkboxes in the table - if ($(this).find('td input:checkbox').length === 0) { - return; + detach: function (context) { + // @todo: Remove event handlers and 'select all' checkboxes. } +}; - // Keep track of the table, which checkbox is checked and alias the settings. - var table = this, checkboxes, lastChecked; - var $table = $(table); - var strings = { 'selectAll': Drupal.t('Select all rows in this table'), 'selectNone': Drupal.t('Deselect all rows in this table') }; - var updateSelectAll = function (state) { - // Update table's select-all checkbox (and sticky header's if available). - $table.prev('table.sticky-header').andSelf().find('th.select-all input:checkbox').each(function() { - $(this).attr('title', state ? strings.selectNone : strings.selectAll); - this.checked = state; - }); - }; - - // Find all