mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
StickyHeaders: Check horizontal scrolling. Fixes #1455
This commit is contained in:
parent
f1aa6745e5
commit
b8c47b5077
@ -150,10 +150,14 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getLeftPosition = function() {
|
||||||
|
return $attach.length ?
|
||||||
|
parseInt($attach.css('padding-left'), 10) || 0 :
|
||||||
|
$table.offset().left - parseInt($table.css('margin-left'), 10) - $(window).scrollLeft();
|
||||||
|
},
|
||||||
resizeHeader = function() {
|
resizeHeader = function() {
|
||||||
$stickyWrap.css({
|
$stickyWrap.css({
|
||||||
left : $attach.length ? parseInt($attach.css('padding-left'), 10) || 0 :
|
left : getLeftPosition(),
|
||||||
$table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft(),
|
|
||||||
width: $table.outerWidth()
|
width: $table.outerWidth()
|
||||||
});
|
});
|
||||||
setWidth( $table, $stickyTable );
|
setWidth( $table, $stickyTable );
|
||||||
@ -163,10 +167,10 @@
|
|||||||
if (!$table.is(':visible')) { return; } // fixes #278
|
if (!$table.is(':visible')) { return; } // fixes #278
|
||||||
// Detect nested tables - fixes #724
|
// Detect nested tables - fixes #724
|
||||||
nestedStickyTop = $nestedSticky.length ? $nestedSticky.offset().top - $yScroll.scrollTop() + $nestedSticky.height() : 0;
|
nestedStickyTop = $nestedSticky.length ? $nestedSticky.offset().top - $yScroll.scrollTop() + $nestedSticky.height() : 0;
|
||||||
var offset = $table.offset(),
|
var tmp,
|
||||||
|
offset = $table.offset(),
|
||||||
stickyOffset = getStickyOffset(c, wo),
|
stickyOffset = getStickyOffset(c, wo),
|
||||||
yWindow = $.isWindow( $yScroll[0] ), // $.isWindow needs jQuery 1.4.3
|
yWindow = $.isWindow( $yScroll[0] ), // $.isWindow needs jQuery 1.4.3
|
||||||
xWindow = $.isWindow( $xScroll[0] ),
|
|
||||||
attachTop = $attach.length ?
|
attachTop = $attach.length ?
|
||||||
( yWindow ? $yScroll.scrollTop() : $yScroll.offset().top ) :
|
( yWindow ? $yScroll.scrollTop() : $yScroll.offset().top ) :
|
||||||
$yScroll.scrollTop(),
|
$yScroll.scrollTop(),
|
||||||
@ -175,17 +179,21 @@
|
|||||||
tableHeight = $table.height() - ($stickyWrap.height() + ($tfoot.height() || 0)) - captionHeight,
|
tableHeight = $table.height() - ($stickyWrap.height() + ($tfoot.height() || 0)) - captionHeight,
|
||||||
isVisible = ( scrollTop > offset.top ) && ( scrollTop < offset.top + tableHeight ) ? 'visible' : 'hidden',
|
isVisible = ( scrollTop > offset.top ) && ( scrollTop < offset.top + tableHeight ) ? 'visible' : 'hidden',
|
||||||
state = isVisible === 'visible' ? ts.css.stickyVis : ts.css.stickyHide,
|
state = isVisible === 'visible' ? ts.css.stickyVis : ts.css.stickyHide,
|
||||||
|
needsUpdating = !$stickyWrap.hasClass( state ),
|
||||||
cssSettings = { visibility : isVisible };
|
cssSettings = { visibility : isVisible };
|
||||||
if ($attach.length) {
|
if ($attach.length) {
|
||||||
|
// attached sticky headers always need updating
|
||||||
|
needsUpdating = true;
|
||||||
cssSettings.top = yWindow ? scrollTop - $attach.offset().top : $attach.scrollTop();
|
cssSettings.top = yWindow ? scrollTop - $attach.offset().top : $attach.scrollTop();
|
||||||
}
|
}
|
||||||
if (xWindow) {
|
// adjust when scrolling horizontally - fixes issue #143
|
||||||
// adjust when scrolling horizontally - fixes issue #143
|
tmp = getLeftPosition();
|
||||||
cssSettings.left = $table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft();
|
if (tmp !== parseInt($stickyWrap.css('left'), 10)) {
|
||||||
|
needsUpdating = true;
|
||||||
|
cssSettings.left = tmp;
|
||||||
}
|
}
|
||||||
cssSettings.top = ( cssSettings.top || 0 ) + stickyOffset + nestedStickyTop;
|
cssSettings.top = ( cssSettings.top || 0 ) + stickyOffset + nestedStickyTop;
|
||||||
// attached sticky headers always need updating
|
if (needsUpdating) {
|
||||||
if ( !$stickyWrap.hasClass( state ) || $attach.length ) {
|
|
||||||
$stickyWrap
|
$stickyWrap
|
||||||
.removeClass( ts.css.stickyVis + ' ' + ts.css.stickyHide )
|
.removeClass( ts.css.stickyVis + ' ' + ts.css.stickyHide )
|
||||||
.addClass( state )
|
.addClass( state )
|
||||||
|
Loading…
Reference in New Issue
Block a user