2015-03-28 20:03:50 +00:00
/*! Widget: cssStickyHeaders - updated 2/9/2015 (v2.19.1) */
2015-10-31 15:08:21 +00:00
/ *
* Requires a modern browser , tablesorter v2 . 8 +
* /
/*jshint jquery:true, unused:false */
! function ( a , b ) { "use strict" ; var c = a . tablesorter ; c . addWidget ( { id : "cssStickyHeaders" , priority : 10 , options : { cssStickyHeaders _offset : 0 , cssStickyHeaders _addCaption : ! 1 ,
// jQuery selector or object to attach sticky header to
cssStickyHeaders _attachTo : null , cssStickyHeaders _filteredToTop : ! 0 } , init : function ( d , e , f , g ) { var h , i , j , k = f . $table , l = a ( g . cssStickyHeaders _attachTo ) , m = "ActiveXObject" in b , // target all versions of IE
n = f . namespace + "cssstickyheader " , o = k . children ( "thead" ) , p = k . children ( "caption" ) , q = l . length ? l : a ( b ) , r = k . parent ( ) . closest ( "table." + c . css . table ) , s = r . length && c . hasWidget ( r [ 0 ] , "cssStickyHeaders" ) ? r . children ( "thead" ) : [ ] , t = parseInt ( k . css ( "border-top-width" ) , 10 ) || 0 , u = g . cssStickyHeaders _addCaption ,
// table offset top changes while scrolling in FF
v = ! 1 , w = ! 1 , x = function ( a , b ) { var c = 0 === b ? "" : "translate(0px," + b + "px)" ; a . css ( { transform : c , "-ms-transform" : c , "-webkit-transform" : c } ) } ;
// Firefox fixes
p . length && ( h = k . height ( ) , p . hide ( ) , w = k . height ( ) === h , p . show ( ) , i = k . offset ( ) . top , x ( p , 20 ) , v = k . offset ( ) . top !== i , x ( p , 0 ) ) , q . unbind ( "scroll resize " . split ( " " ) . join ( n ) . replace ( /\s+/g , " " ) ) . bind ( "scroll resize " . split ( " " ) . join ( n ) , function ( ) { g = f . widgetOptions , v && ( x ( p , 0 ) , j = k . offset ( ) . top ) ; var a = l . length ? l . offset ( ) . top : q . 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
b = ( p . outerHeight ( ! 0 ) || 0 ) + ( parseInt ( k . css ( "padding-top" ) , 10 ) || 0 ) + ( parseInt ( k . css ( "border-spacing" ) , 10 ) || 0 ) , c = k . height ( ) + ( w && g . cssStickyHeaders _addCaption ? b : 0 ) - o . height ( ) - ( k . children ( "tfoot" ) . height ( ) || 0 ) - ( g . cssStickyHeaders _addCaption ? b : w ? 0 : b ) , d = s . length ? s . height ( ) : 0 ,
// get bottom of nested sticky headers
e = s . length ? m ? r . data ( "cssStickyHeaderBottom" ) + d : s . offset ( ) . top + d - q . scrollTop ( ) : 0 ,
// in this case FF's offsetTop changes while scrolling, so we get a saved offsetTop before scrolling occurs
// but when the table is inside a wrapper ($attach) we need to continually update the offset top
h = v ? j : k . offset ( ) . top , i = w ? h - ( g . cssStickyHeaders _addCaption ? b : 0 ) : h ,
// Detect nested tables - fixes #724
n = a - i + e + t + ( g . cssStickyHeaders _offset || 0 ) - ( g . cssStickyHeaders _addCaption ? w ? b : 0 : b ) , y = n > 0 && c >= n ? n : 0 ,
// All IE (even IE11) can only transform header cells - fixes #447 thanks to @gakreol!
z = m ? o . children ( ) . children ( ) : o ;
// more crazy IE stuff...
m &&
// I didn't bother testing 3 nested tables deep in IE, because I hate it
f . $table . data ( "cssStickyHeaderBottom" , ( s . length ? d : 0 ) - ( g . cssStickyHeaders _addCaption ? b : 0 ) ) , g . cssStickyHeaders _addCaption && ( z = z . add ( p ) ) , u !== g . cssStickyHeaders _addCaption && ( u = g . cssStickyHeaders _addCaption , u || x ( p , 0 ) ) , x ( z , y ) } ) , k . unbind ( ( "filterEnd" + n ) . replace ( /\s+/g , " " ) ) . bind ( "filterEnd" + n , function ( ) { g . cssStickyHeaders _filteredToTop &&
// scroll top of table into view
b . scrollTo ( 0 , k . position ( ) . top ) } ) } , remove : function ( c , d , e , f ) { if ( ! f ) { var g = d . namespace + "cssstickyheader " ; a ( b ) . unbind ( "scroll resize " . split ( " " ) . join ( g ) . replace ( /\s+/g , " " ) ) , d . $table . unbind ( "filterEnd scroll resize " . split ( " " ) . join ( g ) . replace ( /\s+/g , " " ) ) . add ( d . $table . children ( "thead" ) . children ( ) . children ( ) ) . children ( "thead, caption" ) . css ( { transform : "" , "-ms-transform" : "" , "-webkit-transform" : "" } ) } } } ) } ( jQuery , window ) ;