2014-02-01 16:19:26 +00:00
|
|
|
/*! tablesorter CSS Sticky Headers widget - updated 12/17/2013 (v2.15.0)
|
2013-12-08 20:02:02 +00:00
|
|
|
* Requires a modern browser, tablesorter v2.8+
|
2013-11-25 12:59:30 +00:00
|
|
|
*/
|
2013-12-08 20:02:02 +00:00
|
|
|
/*global jQuery: false, unused:false */
|
2013-11-25 12:59:30 +00:00
|
|
|
;(function($){
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.tablesorter.addWidget({
|
|
|
|
id: "cssStickyHeaders",
|
|
|
|
priority: 10,
|
|
|
|
options: {
|
2013-12-08 20:02:02 +00:00
|
|
|
cssStickyHeaders_offset : 0,
|
|
|
|
cssStickyHeaders_addCaption : false,
|
2013-12-17 23:47:17 +00:00
|
|
|
cssStickyHeaders_attachTo : null,
|
|
|
|
cssStickyHeaders_zIndex : 10
|
2013-11-25 12:59:30 +00:00
|
|
|
},
|
|
|
|
init : function(table, thisWidget, c, wo) {
|
2013-12-08 20:02:02 +00:00
|
|
|
var $attach = $(wo.cssStickyHeaders_attachTo),
|
2013-11-25 12:59:30 +00:00
|
|
|
namespace = '.cssstickyheader',
|
|
|
|
$thead = c.$table.children('thead'),
|
2013-12-08 20:02:02 +00:00
|
|
|
$caption = c.$table.find('caption'),
|
|
|
|
$win = $attach.length ? $attach : $(window);
|
|
|
|
$win.bind('scroll resize '.split(' ').join(namespace + ' '), function() {
|
|
|
|
var top = $attach.length ? $attach.offset().top : $win.scrollTop(),
|
|
|
|
// add caption height; include table padding top & border-spacing or text may be above the fold (jQuery UI themes)
|
|
|
|
// border-spacing needed in Firefox, but not webkit... not sure if I should account for that
|
|
|
|
captionTop = wo.cssStickyHeaders_addCaption ? $caption.outerHeight(true) +
|
|
|
|
(parseInt(c.$table.css('padding-top'), 10) || 0) + (parseInt(c.$table.css('border-spacing'), 10) || 0) : 0,
|
|
|
|
bottom = c.$table.height() - $thead.height() - (c.$table.find('tfoot').height() || 0) - captionTop,
|
|
|
|
deltaY = top - $thead.offset().top + (parseInt(c.$table.css('border-top-width'), 10) || 0) +
|
|
|
|
(wo.cssStickyHeaders_offset || 0) + captionTop,
|
|
|
|
finalY = (deltaY > 0 && deltaY <= bottom ? deltaY : 0),
|
|
|
|
// IE can only transform header cells - fixes #447 thanks to @gakreol!
|
|
|
|
$cells = $thead.children().children();
|
|
|
|
if (wo.cssStickyHeaders_addCaption) {
|
|
|
|
$cells = $cells.add($caption);
|
|
|
|
}
|
|
|
|
$cells.css({
|
2013-12-17 23:47:17 +00:00
|
|
|
"position" : "relative",
|
|
|
|
"z-index" : wo.cssStickyHeaders_zIndex,
|
|
|
|
"transform" : finalY === 0 ? "" : "translate(0px," + finalY + "px)",
|
|
|
|
"-ms-transform" : finalY === 0 ? "" : "translate(0px," + finalY + "px)",
|
|
|
|
"-webkit-transform" : finalY === 0 ? "" : "translate(0px," + finalY + "px)"
|
2013-11-25 12:59:30 +00:00
|
|
|
});
|
2013-12-08 20:02:02 +00:00
|
|
|
});
|
2014-02-02 07:28:03 +00:00
|
|
|
c.$table.bind('filterEnd', function() {
|
|
|
|
// scroll top of table into view
|
|
|
|
window.scrollTo(0, c.$table.position().top);
|
|
|
|
});
|
|
|
|
|
2013-11-25 12:59:30 +00:00
|
|
|
},
|
|
|
|
remove: function(table, c, wo){
|
|
|
|
var namespace = '.cssstickyheader';
|
|
|
|
$(window).unbind('scroll resize '.split(' ').join(namespace + ' '));
|
|
|
|
c.$table
|
|
|
|
.unbind('update updateAll '.split(' ').join(namespace + ' '))
|
2013-12-08 20:02:02 +00:00
|
|
|
.children('thead, caption').css({
|
2013-12-17 23:47:17 +00:00
|
|
|
"position" : "",
|
|
|
|
"z-index" : "",
|
|
|
|
"transform" : "",
|
2013-12-08 20:02:02 +00:00
|
|
|
"-ms-transform" : "",
|
|
|
|
"-webkit-transform" : ""
|
|
|
|
});
|
2013-11-25 12:59:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|