tablesorter/dist/js/widgets/widget-scroller.min.js

34 lines
5.6 KiB
JavaScript
Raw Normal View History

/*!
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 2/7/2015 (v2.19.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
*/
!function(a,b){"use strict";a.fn.hasScrollBar=function(){return this.get(0).scrollHeight>this.height()};var c=a.tablesorter;c.window_resize=function(){this.resize_timer&&clearTimeout(this.resize_timer),this.resize_timer=setTimeout(function(){a(this).trigger("resizeEnd")},250)},a(function(){var b="<style>.tablesorter-scrollbar-measure { width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px; } .tablesorter-scroller-reset { width: auto !important; } .tablesorter-scroller { text-align: left; overflow: hidden; }.tablesorter-scroller-header { overflow: hidden; }.tablesorter-scroller-header table.tablesorter { margin-bottom: 0; }.tablesorter-scroller-table { overflow-y: scroll; }.tablesorter-scroller-table table.tablesorter { margin-top: 0; overflow: scroll; } .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>";a(b).appendTo("body")}),c.addWidget({id:"scroller",priority:60,options:{scroller_height:300,scroller_jumpToHeader:!0,scroller_upAfterSort:!0,scroller_barWidth:null},init:function(d,e,f){var g=a(b),h=f.namespace+"tsscroller";g.bind("resize"+h,c.window_resize).bind("resizeEnd"+h,function(){a.isFunction(d.config.widgetOptions.scroller_resizeWidth)&&(g.unbind("resize"+h,c.window_resize),d.config.widgetOptions.scroller_resizeWidth(),g.bind("resize"+h,c.window_resize))})},format:function(d,e,f){var g,h,i,j,k,l,m=e.namespace.slice(1)+"tsscroller",n=a(b),o=e.$table;e.isScrolling||(g=f.scroller_height||300,h=o.children("tbody").height(),0!==h&&g>h&&(g=h+10),i=a('<table class="'+o.attr("class")+'" cellpadding=0 cellspacing=0><thead>'+o.find("thead:first").html()+"</thead></table>"),e.$extraTables=e.$extraTables&&e.$extraTables.length?e.$extraTables.add(i):i,o.wrap('<div id="'+m+'" class="tablesorter-scroller" />').before(i).find(".tablesorter-filter-row").addClass("hideme"),l=i.wrap('<div class="tablesorter-scroller-header" style="width:'+o.width()+';" />').find("."+c.css.header),o.wrap('<div class="tablesorter-scroller-table" style="max-height:'+g+"px;width:"+o.width()+';" />'),c.bindEvents(d,l),o.hasClass("hasFilters")&&c.filter.bindSearch(o,i.find("."+c.css.filter)),k=function(){var b=a('<div class="tablesorter-scrollbar-measure">').appendTo("body"),c=b[0],d=c.offsetWidth-c.clientWidth;return b.remove(),d},j=function(){var b,c,e,g,h,j=a('div.tablesorter-scroller[id != "'+m+'"]').hide();o.children("thead").show(),o.children("colgroup.tablesorter-colgroup").remove(),i.children("colgroup").remove(),o.addClass("tablesorter-scroller-reset").children("thead").find(".tablesorter-header-inner").addClass("tablesorter-scroller-reset").end().find(".tablesorter-filter-row").show(),b=o.parent(),b.addClass("tablesorter-scroller-reset"),b.parent().trigger("resize"),c=parseInt(o.css("border-left-width"),10)+parseInt(o.css("border-right-width"),10),h=(f.scroller_barWidth||k())+c,b.width(b.parent().innerWidth()-(b.parent().hasScrollBar()?h:0)),h=b.innerWidth()-(b.hasScrollBar()?h:0),o.width(h),i.width(h),i.parent().width(h),o.closest(".tablesorter-scroller").find(".tablesorter-scroller-reset").removeClass("tablesorter-scroller-reset"),e=i.find("thead").children().children(),o.children("thead").children().children().each(function(b,d){g=a(d).find(".tablesorter-header-inner"),g.length&&(h=parseInt(g.css("min-width").replace("auto","0").replace(/(px|em)/,""),10),g.width()<h?g.width(h):h=g.width(),e.eq(b).parent().width(g.parent().width()-c))}),a.tablesorter.fixColumnWidth(d),e=o.children("colgroup").clone(),e.length&&i.prepend(e),o.children("thead").find(".tablesorter-filter-row").hide(),j.show()},f.scroller_resizeWidth=j,j(),o.find("thead").css("visibility","hidden"),e.isScrolling=!0,h=o.parent().parent().height(),o.parent().bind("scroll",function(){if(f.scroller_jumpToHeader){var b=n.scrollTop()-i.offset().top;0!==a(this).scrollTop()&&h>b&&b>0&&n.