2013-04-08 05:40:39 +00:00
|
|
|
/*!
|
|
|
|
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
|
|
|
|
|
2015-02-07 06:46:44 +00:00
|
|
|
Version 2.0 - modified by Rob Garrison 4/12/2013; updated 2/7/2015 (v2.19.0)
|
2014-04-18 16:11:05 +00:00
|
|
|
Requires jQuery v1.7+
|
|
|
|
Requires the tablesorter plugin, v2.8+, available at http://mottie.github.com/tablesorter/docs/
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
|
|
$('table.tablesorter').tablesorter({
|
|
|
|
widgets: ['zebra', 'scroller'],
|
|
|
|
widgetOptions : {
|
|
|
|
scroller_height : 300, // height of scroll window
|
2014-06-18 19:41:21 +00:00
|
|
|
scroller_barWidth : 18, // scroll bar width
|
2013-04-08 05:40:39 +00:00
|
|
|
scroller_jumpToHeader : true, // header snap to browser top when scrolling the tbody
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Website: www.tconnell.com
|
|
|
|
*/
|
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
2015-01-14 19:19:02 +00:00
|
|
|
;(function($, window){
|
2013-04-08 05:40:39 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.fn.hasScrollBar = function(){
|
|
|
|
return this.get(0).scrollHeight > this.height();
|
|
|
|
};
|
2013-10-08 17:41:44 +00:00
|
|
|
var ts = $.tablesorter;
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2013-10-08 17:41:44 +00:00
|
|
|
ts.window_resize = function(){
|
2013-04-08 05:40:39 +00:00
|
|
|
if (this.resize_timer) {
|
2014-10-02 17:10:21 +00:00
|
|
|
clearTimeout(this.resize_timer);
|
2013-04-08 05:40:39 +00:00
|
|
|
}
|
|
|
|
this.resize_timer = setTimeout(function(){
|
|
|
|
$(this).trigger('resizeEnd');
|
|
|
|
}, 250);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add extra scroller css
|
|
|
|
$(function(){
|
|
|
|
var s = '<style>' +
|
2015-01-14 19:19:02 +00:00
|
|
|
'.tablesorter-scrollbar-measure { width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px; } ' +
|
2014-06-18 19:37:24 +00:00
|
|
|
'.tablesorter-scroller-reset { width: auto !important; } ' +
|
|
|
|
'.tablesorter-scroller { text-align: left; overflow: hidden; }' +
|
|
|
|
'.tablesorter-scroller-header { overflow: hidden; }' +
|
2013-04-08 05:40:39 +00:00
|
|
|
'.tablesorter-scroller-header table.tablesorter { margin-bottom: 0; }' +
|
2014-06-18 19:37:24 +00:00
|
|
|
'.tablesorter-scroller-table { overflow-y: scroll; }' +
|
|
|
|
'.tablesorter-scroller-table table.tablesorter { margin-top: 0; overflow: scroll; } ' +
|
2013-04-08 05:40:39 +00:00
|
|
|
'.tablesorter-scroller-table .tablesorter-filter-row, .tablesorter-scroller-table tfoot { display: none; }' +
|
|
|
|
'.tablesorter-scroller-table table.tablesorter thead tr.tablesorter-headerRow * {' +
|
|
|
|
'line-height:0;height:0;border:none;background-image:none;padding-top:0;padding-bottom:0;margin-top:0;margin-bottom:0;overflow:hidden;' +
|
|
|
|
'}</style>';
|
|
|
|
$(s).appendTo('body');
|
|
|
|
});
|
|
|
|
|
2013-10-08 17:41:44 +00:00
|
|
|
ts.addWidget({
|
2013-04-08 05:40:39 +00:00
|
|
|
id: 'scroller',
|
|
|
|
priority: 60, // run after the filter widget
|
|
|
|
options: {
|
|
|
|
scroller_height : 300,
|
|
|
|
scroller_jumpToHeader: true,
|
2015-01-14 19:19:02 +00:00
|
|
|
scroller_upAfterSort: true,
|
|
|
|
// bar width is now calculated; set a value to override
|
|
|
|
scroller_barWidth : null
|
2013-04-08 05:40:39 +00:00
|
|
|
},
|
|
|
|
init: function(table, thisWidget, c, wo){
|
2014-10-02 17:10:21 +00:00
|
|
|
var $win = $(window),
|
|
|
|
namespace = c.namespace + 'tsscroller';
|
2014-06-18 19:37:24 +00:00
|
|
|
// Setup window.resizeEnd event
|
2013-04-08 05:40:39 +00:00
|
|
|
$win
|
2014-10-02 17:10:21 +00:00
|
|
|
.bind('resize' + namespace, ts.window_resize)
|
|
|
|
.bind('resizeEnd' + namespace, function() {
|
2013-04-08 05:40:39 +00:00
|
|
|
// init is run before format, so scroller_resizeWidth
|
|
|
|
// won't be defined within the "c" or "wo" parameters
|
2015-01-14 19:19:02 +00:00
|
|
|
if ($.isFunction(table.config.widgetOptions.scroller_resizeWidth)) {
|
2014-06-18 19:37:24 +00:00
|
|
|
// 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.
|
2014-10-02 17:10:21 +00:00
|
|
|
$win.unbind('resize' + namespace, ts.window_resize);
|
2013-04-08 05:40:39 +00:00
|
|
|
table.config.widgetOptions.scroller_resizeWidth();
|
2014-10-02 17:10:21 +00:00
|
|
|
$win.bind('resize' + namespace, ts.window_resize);
|
2013-04-08 05:40:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
format: function(table, c, wo) {
|
2015-01-14 19:19:02 +00:00
|
|
|
var maxHt, tbHt, $hdr, resize, getBarWidth, $cells,
|
2014-10-02 17:10:21 +00:00
|
|
|
// c.namespace contains a unique tablesorter ID, per table
|
|
|
|
id = c.namespace.slice(1) + 'tsscroller',
|
2013-04-08 05:40:39 +00:00
|
|
|
$win = $(window),
|
2014-04-21 00:39:59 +00:00
|
|
|
$tbl = c.$table;
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
if (!c.isScrolling) {
|
2015-01-14 19:19:02 +00:00
|
|
|
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 = $('<table class="' + $tbl.attr('class') + '" cellpadding=0 cellspacing=0>' +
|
|
|
|
'<thead>' + $tbl.find('thead:first').html() + '</thead>' +
|
|
|
|
'</table>');
|
|
|
|
if (c.$extraTables && c.$extraTables.length) {
|
|
|
|
c.$extraTables = c.$extraTables.add($hdr);
|
|
|
|
} else {
|
|
|
|
c.$extraTables = $hdr;
|
|
|
|
}
|
2013-04-08 05:40:39 +00:00
|
|
|
$tbl
|
2014-06-18 19:37:24 +00:00
|
|
|
.wrap('<div id="' + id + '" class="tablesorter-scroller" />')
|
2013-04-08 05:40:39 +00:00
|
|
|
.before($hdr)
|
2015-01-14 19:19:02 +00:00
|
|
|
// shrink filter row but don't completely hide it because the inputs/selectors may distort the columns
|
2013-04-08 05:40:39 +00:00
|
|
|
.find('.tablesorter-filter-row').addClass('hideme');
|
|
|
|
|
|
|
|
$cells = $hdr
|
|
|
|
.wrap('<div class="tablesorter-scroller-header" style="width:' + $tbl.width() + ';" />')
|
2014-04-18 16:11:05 +00:00
|
|
|
.find('.' + ts.css.header);
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
// use max-height, so the height resizes dynamically while filtering
|
|
|
|
$tbl.wrap('<div class="tablesorter-scroller-table" style="max-height:' + maxHt + 'px;width:' + $tbl.width() + ';" />');
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
// make scroller header sortable
|
2014-04-18 16:11:05 +00:00
|
|
|
ts.bindEvents(table, $cells);
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
// look for filter widget
|
2014-04-18 16:11:05 +00:00
|
|
|
if ($tbl.hasClass('hasFilters')) {
|
2014-05-21 01:49:19 +00:00
|
|
|
ts.filter.bindSearch( $tbl, $hdr.find('.' + ts.css.filter) );
|
2014-04-18 16:11:05 +00:00
|
|
|
}
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
// modified from http://davidwalsh.name/detect-scrollbar-width
|
|
|
|
getBarWidth = function(){
|
|
|
|
var $scrollDiv = $('<div class="tablesorter-scrollbar-measure">').appendTo('body'),
|
|
|
|
div = $scrollDiv[0],
|
|
|
|
barWidth = div.offsetWidth - div.clientWidth;
|
|
|
|
$scrollDiv.remove();
|
|
|
|
return barWidth;
|
|
|
|
};
|
|
|
|
|
2013-04-08 05:40:39 +00:00
|
|
|
resize = function(){
|
2014-06-18 19:37:24 +00:00
|
|
|
var d, b, $h, $th, w,
|
|
|
|
// Hide other scrollers so we can resize
|
2015-01-14 19:19:02 +00:00
|
|
|
$div = $('div.tablesorter-scroller[id != "' + id + '"]').hide();
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
$tbl.children('thead').show();
|
|
|
|
// only remove colgroup if it was added by the plugin
|
2015-02-07 06:46:44 +00:00
|
|
|
// the $.tablesorter.fixColumnWidth() function already does this (v2.19.0)
|
2015-01-14 19:19:02 +00:00
|
|
|
// but we need to get "accurate" resized measurements here - see issue #680
|
|
|
|
$tbl.children('colgroup.tablesorter-colgroup').remove();
|
|
|
|
$hdr.children('colgroup').remove();
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2014-06-18 19:37:24 +00:00
|
|
|
// Reset sizes so parent can resize.
|
2013-04-08 05:40:39 +00:00
|
|
|
$tbl
|
2014-06-18 19:37:24 +00:00
|
|
|
.addClass('tablesorter-scroller-reset')
|
2015-01-14 19:19:02 +00:00
|
|
|
.children('thead')
|
|
|
|
.find('.tablesorter-header-inner').addClass('tablesorter-scroller-reset').end()
|
|
|
|
.find('.tablesorter-filter-row').show();
|
2013-04-08 05:40:39 +00:00
|
|
|
d = $tbl.parent();
|
2014-06-18 19:37:24 +00:00
|
|
|
d.addClass('tablesorter-scroller-reset');
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
d.parent().trigger('resize');
|
2014-06-18 19:37:24 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
// include left & right border widths
|
|
|
|
b = parseInt( $tbl.css('border-left-width'), 10 ) + parseInt( $tbl.css('border-right-width'), 10 );
|
|
|
|
|
2013-04-08 05:40:39 +00:00
|
|
|
// Shrink a bit to accommodate scrollbar
|
2015-01-14 19:19:02 +00:00
|
|
|
w = ( wo.scroller_barWidth || getBarWidth() ) + b;
|
|
|
|
|
|
|
|
d.width( d.parent().innerWidth() - ( d.parent().hasScrollBar() ? w : 0 ) );
|
|
|
|
w = d.innerWidth() - ( d.hasScrollBar() ? w : 0 );
|
2014-06-18 19:37:24 +00:00
|
|
|
$tbl.width( w );
|
|
|
|
$hdr.width( w );
|
|
|
|
$hdr.parent().width( w );
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
$tbl
|
|
|
|
.closest('.tablesorter-scroller')
|
|
|
|
.find('.tablesorter-scroller-reset')
|
|
|
|
.removeClass('tablesorter-scroller-reset');
|
2014-06-18 19:26:59 +00:00
|
|
|
|
2014-06-18 19:37:24 +00:00
|
|
|
$h = $hdr.find('thead').children().children();
|
|
|
|
|
|
|
|
// adjust cloned header to match original table width - includes wrappers, headers, and header inner div
|
2015-01-14 19:19:02 +00:00
|
|
|
$tbl.children('thead').children().children().each(function(i, c){
|
2014-06-18 19:37:24 +00:00
|
|
|
$th = $(c).find('.tablesorter-header-inner');
|
|
|
|
if ($th.length) {
|
|
|
|
// I have no idea why this is in here anymore LOL
|
|
|
|
w = parseInt( $th.css('min-width').replace('auto', '0').replace(/(px|em)/, ''), 10 );
|
|
|
|
if ( $th.width() < w ) {
|
|
|
|
$th.width(w);
|
|
|
|
} else {
|
|
|
|
w = $th.width();
|
|
|
|
}
|
2015-01-14 19:19:02 +00:00
|
|
|
|
2014-06-18 19:37:24 +00:00
|
|
|
$h.eq(i)
|
|
|
|
.parent()
|
2014-06-18 21:07:29 +00:00
|
|
|
.width( $th.parent().width() - b );
|
2013-04-08 05:40:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
// refresh colgroup & copy to cloned header
|
|
|
|
$.tablesorter.fixColumnWidth( table );
|
|
|
|
$h = $tbl.children('colgroup').clone();
|
|
|
|
if ($h.length) {
|
|
|
|
$hdr.prepend($h);
|
|
|
|
}
|
|
|
|
|
|
|
|
// hide filter row because filterEnd event fires
|
|
|
|
$tbl.children('thead').find('.tablesorter-filter-row').hide();
|
|
|
|
|
2013-04-08 05:40:39 +00:00
|
|
|
$div.show();
|
|
|
|
};
|
|
|
|
|
2014-06-18 19:37:24 +00:00
|
|
|
// Expose to external calls
|
2013-04-08 05:40:39 +00:00
|
|
|
wo.scroller_resizeWidth = resize;
|
|
|
|
|
|
|
|
resize();
|
|
|
|
|
|
|
|
$tbl.find('thead').css('visibility', 'hidden');
|
|
|
|
c.isScrolling = true;
|
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
tbHt = $tbl.parent().parent().height();
|
2014-06-18 19:37:24 +00:00
|
|
|
|
2013-04-08 05:40:39 +00:00
|
|
|
// The header will always jump into view if scrolling the table body
|
|
|
|
$tbl.parent().bind('scroll', function(){
|
|
|
|
if (wo.scroller_jumpToHeader) {
|
|
|
|
var pos = $win.scrollTop() - $hdr.offset().top;
|
2015-01-14 19:19:02 +00:00
|
|
|
if ($(this).scrollTop() !== 0 && pos < tbHt && pos > 0) {
|
2013-04-08 05:40:39 +00:00
|
|
|
$win.scrollTop( $hdr.offset().top );
|
|
|
|
}
|
|
|
|
}
|
2014-06-18 19:37:24 +00:00
|
|
|
$hdr.parent().scrollLeft( $(this).scrollLeft() );
|
2013-04-08 05:40:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-18 19:37:24 +00:00
|
|
|
// Sorting, so scroll to top
|
2014-06-26 17:09:59 +00:00
|
|
|
if (wo.scroller_upAfterSort) {
|
|
|
|
$tbl.parent().animate({ scrollTop: 0 }, 'fast');
|
|
|
|
}
|
2013-04-08 05:40:39 +00:00
|
|
|
|
|
|
|
},
|
2014-10-02 17:10:21 +00:00
|
|
|
remove : function(table, c){
|
|
|
|
var $table = c.$table,
|
|
|
|
namespace = c.namespace + 'tsscroller';
|
2014-04-18 16:11:05 +00:00
|
|
|
$table.closest('.tablesorter-scroller').find('.tablesorter-scroller-header').remove();
|
|
|
|
$table
|
|
|
|
.unwrap()
|
|
|
|
.find('.tablesorter-filter-row').removeClass('hideme').end()
|
|
|
|
.find('thead').show().css('visibility', 'visible');
|
2014-10-02 17:10:21 +00:00
|
|
|
$(window).unbind('resize' + namespace + ' resizeEnd' + namespace);
|
2014-04-18 16:11:05 +00:00
|
|
|
c.isScrolling = false;
|
2013-04-08 05:40:39 +00:00
|
|
|
}
|
2014-04-18 16:11:05 +00:00
|
|
|
});
|
2013-04-08 05:40:39 +00:00
|
|
|
|
2015-01-14 19:19:02 +00:00
|
|
|
})(jQuery, window);
|