summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/theme.inc12
-rw-r--r--misc/tableheader.js2
2 files changed, 10 insertions, 4 deletions
diff --git a/includes/theme.inc b/includes/theme.inc
index cc372afa6..26f1eaa27 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -1228,6 +1228,15 @@ function theme_submenu($links) {
* An HTML string representing the table.
*/
function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
+
+ // Add sticky headers, if applicable.
+ if (count($header)) {
+ drupal_add_js('misc/tableheader.js');
+ // Add 'sticky-enabled' class to the table to identify it for JS.
+ // This is needed to target tables constructed by this function.
+ $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class'] .' sticky-enabled');
+ }
+
$output = '<table'. drupal_attributes($attributes) .">\n";
if (isset($caption)) {
@@ -1236,9 +1245,6 @@ function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
// Format the table header:
if (count($header)) {
- // Include JS for sticky headers.
- drupal_add_js('misc/tableheader.js');
-
$ts = tablesort_init($header);
// HTML requires that the thead tag has tr tags in it follwed by tbody
// tags. Using ternary operator to check and see if we have any rows.
diff --git a/misc/tableheader.js b/misc/tableheader.js
index 3143e14fc..33110873e 100644
--- a/misc/tableheader.js
+++ b/misc/tableheader.js
@@ -9,7 +9,7 @@ Drupal.behaviors.tableHeader = function (context) {
// Keep track of all cloned table headers.
var headers = [];
- $('table thead:not(.tableHeader-processed)', context).each(function () {
+ $('table.sticky-enabled thead:not(.tableHeader-processed)', context).each(function () {
// Clone thead so it inherits original jQuery properties.
var headerClone = $(this).clone(true).insertBefore(this.parentNode).wrap('<table class="sticky-header"></table>').parent().css({
position: 'fixed',