summaryrefslogtreecommitdiff
path: root/misc/tableheader.js
diff options
context:
space:
mode:
Diffstat (limited to 'misc/tableheader.js')
-rw-r--r--misc/tableheader.js180
1 files changed, 91 insertions, 89 deletions
diff --git a/misc/tableheader.js b/misc/tableheader.js
index 3127464d8..9fa58ce5d 100644
--- a/misc/tableheader.js
+++ b/misc/tableheader.js
@@ -6,108 +6,110 @@ Drupal.tableHeaderDoScroll = function() {
}
};
-Drupal.behaviors.tableHeader = function (context) {
- // This breaks in anything less than IE 7. Prevent it from running.
- if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
- return;
- }
+Drupal.behaviors.tableHeader = {
+ attach: function(context) {
+ // This breaks in anything less than IE 7. Prevent it from running.
+ if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
+ return;
+ }
- // Keep track of all cloned table headers.
- var headers = [];
+ // Keep track of all cloned table headers.
+ var headers = [];
- $('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',
- top: '0px'
- });
+ $('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',
+ top: '0px'
+ });
- headerClone = $(headerClone)[0];
- headers.push(headerClone);
+ headerClone = $(headerClone)[0];
+ headers.push(headerClone);
- // Store parent table.
- var table = $(this).parent('table')[0];
- headerClone.table = table;
- // Finish initialzing header positioning.
- tracker(headerClone);
+ // Store parent table.
+ var table = $(this).parent('table')[0];
+ headerClone.table = table;
+ // Finish initialzing header positioning.
+ tracker(headerClone);
- $(table).addClass('sticky-table');
- $(this).addClass('tableHeader-processed');
- });
+ $(table).addClass('sticky-table');
+ $(this).addClass('tableHeader-processed');
+ });
- // Define the anchor holding var.
- var prevAnchor = '';
+ // Define the anchor holding var.
+ var prevAnchor = '';
- // Track positioning and visibility.
- function tracker(e) {
- // Save positioning data.
- var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
- if (e.viewHeight != viewHeight) {
- e.viewHeight = viewHeight;
- e.vPosition = $(e.table).offset().top - 4;
- e.hPosition = $(e.table).offset().left;
- e.vLength = e.table.clientHeight - 100;
- // Resize header and its cell widths.
- var parentCell = $('th', e.table);
- $('th', e).each(function(index) {
- var cellWidth = parentCell.eq(index).css('width');
- // Exception for IE7.
- if (cellWidth == 'auto') {
- cellWidth = parentCell.get(index).clientWidth +'px';
- }
- $(this).css('width', cellWidth);
- });
- $(e).css('width', $(e.table).css('width'));
- }
+ // Track positioning and visibility.
+ function tracker(e) {
+ // Save positioning data.
+ var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
+ if (e.viewHeight != viewHeight) {
+ e.viewHeight = viewHeight;
+ e.vPosition = $(e.table).offset().top - 4;
+ e.hPosition = $(e.table).offset().left;
+ e.vLength = e.table.clientHeight - 100;
+ // Resize header and its cell widths.
+ var parentCell = $('th', e.table);
+ $('th', e).each(function(index) {
+ var cellWidth = parentCell.eq(index).css('width');
+ // Exception for IE7.
+ if (cellWidth == 'auto') {
+ cellWidth = parentCell.get(index).clientWidth +'px';
+ }
+ $(this).css('width', cellWidth);
+ });
+ $(e).css('width', $(e.table).css('width'));
+ }
- // Track horizontal positioning relative to the viewport and set visibility.
- var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
- var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
- var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden';
- $(e).css({left: -hScroll + e.hPosition +'px', visibility: visState});
+ // Track horizontal positioning relative to the viewport and set visibility.
+ var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
+ var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition;
+ var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden';
+ $(e).css({left: -hScroll + e.hPosition +'px', visibility: visState});
- // Check the previous anchor to see if we need to scroll to make room for the header.
- // Get the height of the header table and scroll up that amount.
- if (prevAnchor != location.hash) {
- if (location.hash != '') {
- var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
- $('body, html').scrollTop(scrollLocation);
+ // Check the previous anchor to see if we need to scroll to make room for the header.
+ // Get the height of the header table and scroll up that amount.
+ if (prevAnchor != location.hash) {
+ if (location.hash != '') {
+ var scrollLocation = $('td' + location.hash).offset().top - $(e).height();
+ $('body, html').scrollTop(scrollLocation);
+ }
+ prevAnchor = location.hash;
}
- prevAnchor = location.hash;
}
- }
-
- // Only attach to scrollbars once, even if Drupal.attachBehaviors is called
- // multiple times.
- if (!$('body').hasClass('tableHeader-processed')) {
- $('body').addClass('tableHeader-processed');
- $(window).scroll(Drupal.tableHeaderDoScroll);
- $(document.documentElement).scroll(Drupal.tableHeaderDoScroll);
- }
-
- // Track scrolling.
- Drupal.tableHeaderOnScroll = function() {
- $(headers).each(function () {
- tracker(this);
- });
- };
- // Track resizing.
- var time = null;
- var resize = function () {
- // Ensure minimum time between adjustments.
- if (time) {
- return;
+ // Only attach to scrollbars once, even if Drupal.attachBehaviors is called
+ // multiple times.
+ if (!$('body').hasClass('tableHeader-processed')) {
+ $('body').addClass('tableHeader-processed');
+ $(window).scroll(Drupal.tableHeaderDoScroll);
+ $(document.documentElement).scroll(Drupal.tableHeaderDoScroll);
}
- time = setTimeout(function () {
- $('table.sticky-header').each(function () {
- // Force cell width calculation.
- this.viewHeight = 0;
+
+ // Track scrolling.
+ Drupal.tableHeaderOnScroll = function() {
+ $(headers).each(function () {
tracker(this);
});
- // Reset timer.
- time = null;
- }, 250);
- };
- $(window).resize(resize);
+ };
+
+ // Track resizing.
+ var time = null;
+ var resize = function () {
+ // Ensure minimum time between adjustments.
+ if (time) {
+ return;
+ }
+ time = setTimeout(function () {
+ $('table.sticky-header').each(function () {
+ // Force cell width calculation.
+ this.viewHeight = 0;
+ tracker(this);
+ });
+ // Reset timer.
+ time = null;
+ }, 250);
+ };
+ $(window).resize(resize);
+ }
};