/*! Copyright (C) 2011 T. Connell & Associates, Inc. Dual-licensed under the MIT and GPL licenses THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Resizable scroller widget for the jQuery tablesorter plugin Version 2.0 - modified by Rob Garrison 4/12/2013; updated 3/5/2015 (v2.21.0) Requires jQuery v1.7+ Requires the tablesorter plugin, v2.8+, available at http://mottie.github.com/tablesorter/docs/ Usage: $(function() { $('table.tablesorter').tablesorter({ widgets: ['zebra', 'scroller'], widgetOptions : { scroller_height : 300, // height of scroll window scroller_barWidth : 18, // scroll bar width scroller_jumpToHeader : true, // header snap to browser top when scrolling the tbody } }); }); Website: www.tconnell.com */ /*jshint browser:true, jquery:true, unused:false */ ;(function($, window){ "use strict"; $.fn.hasScrollBar = function(){ return this.get(0).scrollHeight > this.height(); }; var ts = $.tablesorter; ts.window_resize = function(){ if (this.resize_timer) { clearTimeout(this.resize_timer); } this.resize_timer = setTimeout(function(){ $(this).trigger('resizeEnd'); }, 250); }; // Add extra scroller css $(function(){ var s = ''; $(s).appendTo('body'); }); ts.addWidget({ id: 'scroller', priority: 60, // run after the filter widget options: { scroller_height : 300, scroller_jumpToHeader: true, scroller_upAfterSort: true, // bar width is now calculated; set a value to override scroller_barWidth : null }, init: function(table, thisWidget, c, wo){ var $win = $(window), namespace = c.namespace + 'tsscroller'; // Setup window.resizeEnd event $win .bind('resize' + namespace, ts.window_resize) .bind('resizeEnd' + namespace, function() { // init is run before format, so scroller_resizeWidth // won't be defined within the "c" or "wo" parameters if ($.isFunction(table.config.widgetOptions.scroller_resizeWidth)) { // IE calls resize when you modify content, so we have to unbind the resize event // so we don't end up with an infinite loop. we can rebind after we're done. $win.unbind('resize' + namespace, ts.window_resize); table.config.widgetOptions.scroller_resizeWidth(); $win.bind('resize' + namespace, ts.window_resize); } }); }, format: function(table, c, wo) { var maxHt, tbHt, $hdr, $t, resize, getBarWidth, $hCells, $fCells, $tblWrap, $ft = $(), // c.namespace contains a unique tablesorter ID, per table id = c.namespace.slice(1) + 'tsscroller', $win = $(window), $tbl = c.$table; if (!c.isScrolling) { // force developer to set fixedWidth to maintain column widths c.widthFixed = true; maxHt = wo.scroller_height || 300; tbHt = $tbl.children('tbody').height(); if (tbHt !== 0 && maxHt > tbHt) { maxHt = tbHt + 10; } // Table is less than h px $hdr = $('' + $tbl.children('thead')[0].outerHTML + '
'); $t = $tbl.children('tfoot'); if ($t.length) { $ft = $('
') .append( $t.clone(true) ) // maintain any bindings on the tfoot cells .append( $tbl.children('thead')[0].outerHTML ) .wrap('