1
// $Id: tableheader.js,v 1.16.2.2 2009/03/30 12:48:09 goba Exp $
3
Drupal.tableHeaderDoScroll = function() {
4
if (typeof(Drupal.tableHeaderOnScroll)=='function') {
5
Drupal.tableHeaderOnScroll();
9
Drupal.behaviors.tableHeader = function (context) {
10
// This breaks in anything less than IE 7. Prevent it from running.
11
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
15
// Keep track of all cloned table headers.
18
$('table.sticky-enabled thead:not(.tableHeader-processed)', context).each(function () {
19
// Clone thead so it inherits original jQuery properties.
20
var headerClone = $(this).clone(true).insertBefore(this.parentNode).wrap('<table class="sticky-header"></table>').parent().css({
25
headerClone = $(headerClone)[0];
26
headers.push(headerClone);
28
// Store parent table.
29
var table = $(this).parent('table')[0];
30
headerClone.table = table;
31
// Finish initialzing header positioning.
34
$(table).addClass('sticky-table');
35
$(this).addClass('tableHeader-processed');
38
// Define the anchor holding var.
41
// Track positioning and visibility.
43
// Save positioning data.
44
var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
45
if (e.viewHeight != viewHeight) {
46
e.viewHeight = viewHeight;
47
e.vPosition = $(e.table).offset().top - 4;
48
e.hPosition = $(e.table).offset().left;
49
e.vLength = e.table.clientHeight - 100;
50
// Resize header and its cell widths.
51
var parentCell = $('th', e.table);
52
$('th', e).each(function(index) {
53
var cellWidth = parentCell.eq(index).css('width');
55
if (cellWidth == 'auto') {
56
cellWidth = parentCell.get(index).clientWidth +'px';
58
$(this).css('width', cellWidth);
60
$(e).css('width', $(e.table).css('width'));
63
// Track horizontal positioning relative to the viewport and set visibility.
64
var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
65
var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
66
var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden';
67
$(e).css({left: -hScroll + e.hPosition +'px', visibility: visState});
69
// Check the previous anchor to see if we need to scroll to make room for the header.
70
// Get the height of the header table and scroll up that amount.
71
if (prevAnchor != location.hash) {
72
if (location.hash != '') {
73
var offset = $('td' + location.hash).offset();
76
var scrollLocation = top - $(e).height();
77
$('body, html').scrollTop(scrollLocation);
80
prevAnchor = location.hash;
84
// Only attach to scrollbars once, even if Drupal.attachBehaviors is called
86
if (!$('body').hasClass('tableHeader-processed')) {
87
$('body').addClass('tableHeader-processed');
88
$(window).scroll(Drupal.tableHeaderDoScroll);
89
$(document.documentElement).scroll(Drupal.tableHeaderDoScroll);
93
Drupal.tableHeaderOnScroll = function() {
94
$(headers).each(function () {
101
var resize = function () {
102
// Ensure minimum time between adjustments.
106
time = setTimeout(function () {
107
$('table.sticky-header').each(function () {
108
// Force cell width calculation.
116
$(window).resize(resize);