From 51164230dbb17f5ed4cdbff1a8f69982a8c69c16 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Tue, 28 Feb 2012 23:27:01 -0800
Subject: [PATCH] Issue #988930 by davidwhthomas, jyve, tim.plunkett,
 effulgentsia, droplet, nod_ | mariusz.slonina: Fixed Sticky table headers
 need to react properly to 'show/hide weights column' link.

---
 core/misc/tabledrag.js   |  4 ++++
 core/misc/tableheader.js | 28 ++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js
index 4315057bff44..da10a0e7a1df 100644
--- a/core/misc/tabledrag.js
+++ b/core/misc/tabledrag.js
@@ -201,6 +201,8 @@ Drupal.tableDrag.prototype.hideColumns = function () {
     // The cookie expires in one year.
     expires: 365
   });
+  // Trigger an event to allow other scripts to react to this display change.
+  $('table.tabledrag-processed').trigger('columnschange', 'hide');
 };
 
 /**
@@ -224,6 +226,8 @@ Drupal.tableDrag.prototype.showColumns = function () {
     // The cookie expires in one year.
     expires: 365
   });
+  // Trigger an event to allow other scripts to react to this display change.
+  $('table.tabledrag-processed').trigger('columnschange', 'show');
 };
 
 /**
diff --git a/core/misc/tableheader.js b/core/misc/tableheader.js
index 63de30c8c655..543862cddd2a 100644
--- a/core/misc/tableheader.js
+++ b/core/misc/tableheader.js
@@ -27,6 +27,14 @@ Drupal.tableHeader = function (table) {
   this.originalTable = $(table);
   this.originalHeader = $(table).children('thead');
   this.originalHeaderCells = this.originalHeader.find('> tr > th');
+  this.displayWeight = null;
+
+  // React to columns change to avoid making checks in the scroll callback.
+  this.originalTable.bind('columnschange', function (e, display) {
+    // This will force header size to be calculated on scroll.
+    self.widthCalculated = (self.displayWeight !== null && self.displayWeight === display);
+    self.displayWeight = display;
+  });
 
   // Clone the table header so it inherits original jQuery properties. Hide
   // the table to avoid a flash of the header clone upon page load.
@@ -95,11 +103,23 @@ Drupal.tableHeader.prototype.eventhandlerRecalculateStickyHeader = function (eve
   // visible or when forced.
   if (this.stickyVisible && (calculateWidth || !this.widthCalculated)) {
     this.widthCalculated = true;
+    var $that = null;
+    var $stickyCell = null;
+    var display = null;
     // Resize header and its cell widths.
-    this.stickyHeaderCells.each(function (index) {
-      var cellWidth = self.originalHeaderCells.eq(index).css('width');
-      $(this).css('width', cellWidth);
-    });
+    // Only apply width to visible table cells. This prevents the header from
+    // displaying incorrectly when the sticky header is no longer visible.
+    for (var i = 0, il = this.originalHeaderCells.length; i < il; i += 1) {
+      $that = $(this.originalHeaderCells[i]);
+      $stickyCell = this.stickyHeaderCells.eq($that.index());
+      display = $that.css('display');
+      if (display !== 'none') {
+        $stickyCell.css({'width': $that.css('width'), 'display': display});
+      }
+      else {
+        $stickyCell.css('display', 'none');
+      }
+    }
     this.stickyTable.css('width', this.originalTable.css('width'));
   }
 };
-- 
GitLab