forked from rubynor/table-fixed-header
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-added resize event handling from pixelsonly
based on latest version of table-fixed-header re-added the changes by pixelsonly see rubynor#3 and https://github.com/pixelsonly/table-fixed-header/commit/d77ca6211d991af68a9ec9ea48051e8433c592f5#diff-474733f5a4705e7dca41663f008306cf for details
- Loading branch information
1 parent
9ac4b28
commit dc4df32
Showing
1 changed file
with
59 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,65 @@ | ||
(function($) { | ||
|
||
$.fn.fixedHeader = function (options) { | ||
var config = { | ||
topOffset: 40 | ||
//bgColor: 'white' | ||
}; | ||
if (options){ $.extend(config, options); } | ||
|
||
return this.each( function() { | ||
var o = $(this); | ||
|
||
var $win = $(window) | ||
, $head = $('thead.header', o) | ||
, isFixed = 0; | ||
var headTop = $head.length && $head.offset().top - config.topOffset; | ||
|
||
function processScroll() { | ||
if (!o.is(':visible')) return; | ||
if ($('thead.header-copy').size()) { | ||
$('thead.header-copy').width($head.width()); | ||
var i, scrollTop = $win.scrollTop(); | ||
$.fn.fixedHeader = function(options) { | ||
var config = { topOffset: 0 }; | ||
if (options) { | ||
$.extend(config, options); | ||
} | ||
var t = $head.length && $head.offset().top - config.topOffset; | ||
if (!isFixed && headTop != t) { headTop = t; } | ||
if (scrollTop >= headTop && !isFixed) { | ||
isFixed = 1; | ||
} else if (scrollTop <= headTop && isFixed) { | ||
isFixed = 0; | ||
} | ||
isFixed ? $('thead.header-copy', o).show().offset({ left: $head.offset().left }) | ||
: $('thead.header-copy', o).hide(); | ||
} | ||
$win.on('scroll', processScroll); | ||
|
||
// hack sad times - holdover until rewrite for 2.1 | ||
$head.on('click', function () { | ||
if (!isFixed) setTimeout(function () { $win.scrollTop($win.scrollTop() - 47) }, 10); | ||
}) | ||
|
||
$head.clone(true).removeClass('header').addClass('header-copy header-fixed').css({'position': 'fixed', 'top': config['topOffset']}).appendTo(o); | ||
o.find('thead.header-copy').width($head.width()); | ||
|
||
o.find('thead.header > tr > th').each(function (i, h) { | ||
var w = $(h).width(); | ||
o.find('thead.header-copy> tr > th:eq('+i+')').width(w) | ||
}); | ||
$head.css({ margin:'0 auto', | ||
width: o.width(), | ||
'background-color':config.bgColor }); | ||
processScroll(); | ||
}); | ||
|
||
return this.each(function() { | ||
var o = $(this); | ||
|
||
var $win = $(window), | ||
$head = $('thead.header', o), | ||
isFixed = 0; | ||
var headTop = $head.length && $head.offset().top - config.topOffset; | ||
|
||
function processScroll() { | ||
if (!o.is(':visible')) return; | ||
if ($('thead.header-copy').size()) { | ||
$('thead.header-copy').width($head.width()); | ||
var i, scrollTop = $win.scrollTop(); | ||
} | ||
var t = $head.length && $head.offset().top - config.topOffset; | ||
if (!isFixed && headTop != t) { | ||
headTop = t; | ||
} | ||
if (scrollTop >= headTop && !isFixed) { | ||
isFixed = 1; | ||
} else if (scrollTop <= headTop && isFixed) { | ||
isFixed = 0; | ||
} | ||
isFixed ? $('thead.header-copy', o).show().offset({ left: $head.offset().left }) | ||
: $('thead.header-copy', o).hide(); | ||
} | ||
|
||
function handleResize() { | ||
o.find('thead.header-copy').width($head.width()); | ||
|
||
o.find('thead.header > tr > th').each(function (i, h) { | ||
var w = $(h).width(); | ||
o.find('thead.header-copy> tr > th:eq(' + i + ')').width(w); | ||
}); | ||
$head.css({ | ||
margin: '0 auto', | ||
width: o.width(), | ||
'background-color': config.bgColor | ||
}); | ||
} | ||
|
||
$win.on('resize', handleResize); | ||
$win.on('scroll', processScroll); | ||
|
||
// hack sad times - holdover until rewrite for 2.1 | ||
$head.on('click', function() { | ||
if (!isFixed) setTimeout(function() { $win.scrollTop($win.scrollTop() - 47) }, 10); | ||
}); | ||
|
||
$head.clone(true).removeClass('header').addClass('header-copy header-fixed').css({ 'position': 'fixed', 'top': config['topOffset'] }).appendTo(o); | ||
|
||
handleResize(); | ||
processScroll(); | ||
}); | ||
}; | ||
|
||
})(jQuery); |