Index: misc/tableheader.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tableheader.js,v
retrieving revision 1.9
diff -u -p -r1.9 tableheader.js
--- misc/tableheader.js 2 Oct 2007 07:09:51 -0000 1.9
+++ misc/tableheader.js 7 Jan 2008 21:26:28 -0000
@@ -6,66 +6,55 @@ Drupal.behaviors.tableHeader = function
return;
}
- // Keep track of all header cells.
- var cells = [];
+ // Keep track of all cloned headers rows.
+ var headers = [];
- var z = 0;
$('table thead:not(.tableHeader-processed)', context).each(function () {
// Find table height.
var table = $(this).parent('table')[0];
- var height = $(table).addClass('sticky-table').height();
- var i = 0;
- // Find all header cells.
- $('th', this).each(function () {
-
- // Ensure each cell has an element in it.
- var html = $(this).html();
- if (html == ' ') {
- html = ' ';
- }
- if ($(this).children().size() == 0) {
- html = ''+ html +'';
- }
+ var header_clone = $(this).clone(true).insertBefore(this.parentNode).wrap('
').parent().css({
+ position: 'fixed',
+ visibility: 'hidden',
+ top: '0px',
+ left: $(table).offset().left +'px',
+ width: $(table).width() +'px'
+ });
- // Clone and wrap cell contents in sticky wrapper that overlaps the cell's padding.
- $('').prependTo(this);
- var div = $('div.sticky-header', this).css({
- 'marginLeft': '-'+ $(this).css('paddingLeft'),
- 'marginRight': '-'+ $(this).css('paddingRight'),
- 'paddingLeft': $(this).css('paddingLeft'),
- 'paddingTop': $(this).css('paddingTop'),
- 'paddingBottom': $(this).css('paddingBottom'),
- 'z-index': ++z
- })[0];
- cells.push(div);
-
- // Adjust width to fit cell/table.
- var ref = this;
- if (!i++) {
- // The first cell is as wide as the table to prevent gaps.
- ref = table;
- div.wide = true;
- }
- $(div).width(Math.max(0, $(ref).width() - parseInt($(div).css('paddingLeft'))));
+ var thead = $(header_clone)[0];
+ headers.push(thead);
- // Get position and store.
- div.cell = this;
- div.table = table;
- div.stickyMax = height;
- div.stickyPosition = $(this).offset().top;
+ // Copy cell widths from header to sticky headers.
+ // IE7 chokes on this.
+ var cellcounter = 0;
+ $('th', this).each(function () {
+ $('th', thead).eq(cellcounter++).width($(this).width() - (parseInt($(this).css('paddingLeft')) + parseInt($(this).css('paddingRight'))));
});
+
+ // Store objects.
+ thead.thead = this;
+ thead.table = table;
+ $(table).addClass('sticky-table');
$(this).addClass('tableHeader-processed');
});
// Track scrolling.
var scroll = function() {
- $(cells).each(function () {
+ $(headers).each(function () {
+ // Keep positioning data up to date.
+ var docheight = document.documentElement.offsetHeight || document.body.offsetHeight;
+ if (this.docheight != docheight) {
+ this.docheight = docheight;
+ this.stickyPosition = $(this.table).offset().top;
+ this.stickyMax = $(this.table).height();
+ }
// Fetch scrolling position.
var scroll = document.documentElement.scrollTop || document.body.scrollTop;
var offset = scroll - this.stickyPosition - 4;
if (offset > 0 && offset < this.stickyMax - 100) {
- $(this).css('visibility', 'visible');
+ var hscroll = document.documentElement.scrollLeft || document.body.scrollLeft;
+ $(this).css({visibility: 'visible', left: -hscroll + $(this.table).offset().left +'px'
+ });
}
else {
$(this).css('visibility', 'hidden');
@@ -83,24 +72,16 @@ Drupal.behaviors.tableHeader = function
return;
}
time = setTimeout(function () {
-
- // Precalculate table heights
- $('table.sticky-table').each(function () {
- this.savedHeight = $(this).height();
- });
-
- $('table.sticky-table div.sticky-header').each(function () {
+ $('table.sticky-header').each(function () {
// Get position.
- this.stickyPosition = $(this.cell).offset().top;
- this.stickyMax = this.table.savedHeight;
-
- // Reflow the cell.
- var ref = this.cell;
- if (this.wide) {
- // Resize the first cell to fit the table.
- ref = this.table;
- }
- $(this).width(Math.max(0, $(ref).width() - parseInt($(this).css('paddingLeft'))));
+ this.stickyPosition = $(this.thead).offset().top;
+ this.stickyMax = $(this.table).height();
+ // Reposition and resize header.
+ var hscroll = document.documentElement.scrollLeft || document.body.scrollLeft;
+ $(this).css({
+ left: -hscroll + $(this.table).offset().left +'px',
+ width: $(this.table).width()
+ });
});
// Reset timer
Index: modules/system/system.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.css,v
retrieving revision 1.46
diff -u -p -r1.46 system.css
--- modules/system/system.css 22 Dec 2007 22:25:50 -0000 1.46
+++ modules/system/system.css 7 Jan 2008 21:26:29 -0000
@@ -468,7 +468,9 @@ tr.selected td {
/*
** Floating header for tableheader.js
*/
-thead div.sticky-header {
+table.sticky-header {
+ padding: 0;
+ margin: 0;
background: #fff;
}
Index: themes/garland/style.css
===================================================================
RCS file: /cvs/drupal/drupal/themes/garland/style.css,v
retrieving revision 1.36
diff -u -p -r1.36 style.css
--- themes/garland/style.css 29 Dec 2007 16:02:52 -0000 1.36
+++ themes/garland/style.css 7 Jan 2008 21:26:29 -0000
@@ -201,7 +201,7 @@ thead th {
font-weight: bold;
}
-thead div.sticky-header {
+thead.sticky-header {
border-bottom: 2px solid #d3e7f4;
}