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

2 lines
12 KiB
JavaScript

/*! Widget: scroller - updated 4/2/2015 (v2.21.5) */
!function(a,b){"use strict";var c=a.tablesorter,d=c.css;a.extend(c.css,{scrollerWrap:"tablesorter-scroller",scrollerHeader:"tablesorter-scroller-header",scrollerTable:"tablesorter-scroller-table",scrollerFooter:"tablesorter-scroller-footer",scrollerFixed:"tablesorter-scroller-fixed",scrollerHasFix:"tablesorter-scroller-has-fixed-columns",scrollerReset:"tablesorter-scroller-reset",scrollerRtl:"tablesorter-scroller-rtl"}),c.addWidget({id:"scroller",priority:60,options:{scroller_height:300,scroller_jumpToHeader:!0,scroller_upAfterSort:!0,scroller_fixedColumns:0,scroller_rowHighlight:"hover",scroller_barWidth:null},format:function(a,b,d){b.isScrolling||c.scroller.setup(b,d)},remove:function(a,b,d){c.scroller.remove(b,d)}}),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>."+d.scrollerWrap+"Measure { width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px; }."+d.scrollerReset+" { width: auto !important; min-width: auto !important; max-width: auto !important; }."+d.scrollerWrap+" { position: relative; overflow: hidden; }."+d.scrollerWrap+" * { box-sizing: border-box; }."+d.scrollerHeader+", ."+d.scrollerFooter+" { overflow: hidden; }."+d.scrollerHeader+" table."+d.table+" { margin-bottom: 0; }."+d.scrollerFooter+" table."+d.table+" thead { visibility: hidden, height: 0; overflow: hidden; }."+d.scrollerTable+" { overflow-y: scroll; }."+d.scrollerTable+" table."+d.table+" { border-top: 0; margin-top: 0; margin-bottom: 0; overflow-y: scroll; }."+d.scrollerTable+" ."+(d.filterRow||"tablesorter-filter-row")+",."+d.scrollerFooter+" ."+(d.filterRow||"tablesorter-filter-row")+",."+d.scrollerTable+" tfoot { display: none; }."+d.scrollerTable+" table."+d.table+" thead tr."+d.headerRow+" *, ."+d.scrollerFooter+" table."+d.table+" thead * { line-height: 0; height: 0; border: none; background-image: none; padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; overflow: hidden; }."+d.scrollerFixed+" { pointer-events: none; }."+d.scrollerFixed+" > div { pointer-events: all; }."+d.scrollerWrap+" ."+d.scrollerFixed+" { position: absolute; top: 0; z-index: 1; left: 0 } ."+d.scrollerWrap+" ."+d.scrollerFixed+"."+d.scrollerRtl+" { left: auto; right: 0 } ."+d.scrollerWrap+"."+d.scrollerHasFix+" > ."+d.scrollerTable+" { overflow-x: auto; }."+d.scrollerFixed+" ."+d.scrollerFooter+" { position: absolute; bottom: 0; }."+d.scrollerFixed+" ."+d.scrollerTable+" { position: relative; left: 0; overflow-x: hidden; overflow-y: scroll; -ms-overflow-style: none; }."+d.scrollerFixed+" ."+d.scrollerTable+"::-webkit-scrollbar { display: none; }."+d.scrollerWrap+" ."+d.scrollerFixed+" table { border-right-color: transparent; padding-right: 0; }."+d.scrollerWrap+" ."+d.scrollerFixed+"."+d.scrollerRtl+" table { border-left-color: transparent; padding-left: 0; }</style>";a(b).appendTo("body")}),c.scroller={isFirefox:navigator.userAgent.toLowerCase().indexOf("firefox")>-1,isOldIE:document.all&&!b.atob,hasScrollBar:function(a){return a.get(0).scrollHeight>a.height()},setWidth:function(a,b){a.css({width:b,"min-width":b,"max-width":b})},getBarWidth:function(){var b=a('<div class="'+d.scrollerWrap+'Measure">').appendTo("body"),c=b[0],e=c.offsetWidth-c.clientWidth;return b.remove(),e},setup:function(e,f){var g,h,i,j,k,l,m,n=a(b),o=e.namespace+"tsscroller",p=a(),q=e.namespace.slice(1)+"tsscroller",r=e.$table;e.widthFixed=!0,g=f.scroller_height||300,h=r.children("tbody").height(),0!==h&&g>h&&(g=h+10),f.scroller_$header=i=a('<table class="'+r.attr("class")+'" cellpadding=0 cellspacing=0>'+r.children("thead")[0].outerHTML+"</table>").addClass(e.namespace.slice(1)+"_extra_table"),j=r.children("tfoot"),j.length&&(p=a('<table class="'+r.attr("class")+'" cellpadding=0 cellspacing=0 style="margin-top:0"></table>').addClass(e.namespace.slice(1)+"_extra_table").append(j.clone(!0)).append(r.children("thead")[0].outerHTML).wrap('<div class="'+d.scrollerFooter+'"/>'),l=p.children("tfoot").eq(0).children("tr").children()),f.scroller_$footer=p,r.wrap('<div id="'+q+'" class="'+d.scrollerWrap+'" />').before(i).find("."+d.filterRow).addClass(d.filterRowHide),f.scroller_$container=r.parent(),p.length&&r.after(p.parent()),k=i.wrap('<div class="'+d.scrollerHeader+'" />').find("."+d.header),r.wrap('<div class="'+d.scrollerTable+'" style="max-height:'+g+'px;" />'),m=r.parent(),c.bindEvents(e.table,k),r.hasClass("hasFilters")&&c.filter.bindSearch(r,i.find("."+d.filter)),f.scroller_$container.find("."+d.scrollerFixed).remove(),f.scroller_fixedColumns>0&&c.scroller.setupFixed(e,f),c.scroller.resize(e,f),r.find("thead").css("visibility","hidden"),h=m.parent().height(),m.off("scroll"+o).on("scroll"+o,function(){if(f.scroller_jumpToHeader){var b=n.scrollTop()-i.offset().top;0!==a(this).scrollTop()&&h>b&&b>0&&n.scrollTop(i.offset().top)}i.parent().add(p.parent()).scrollLeft(a(this).scrollLeft())}),r.off("sortEnd"+o+" setFixedColumnSize"+o).on("sortEnd"+o,function(){f.scroller_upAfterSort&&r.parent().animate({scrollTop:0},"fast")}).on("setFixedColumnSize"+o,function(a,b){"undefined"==typeof b||isNaN(b)||(f.scroller_fixedColumns=parseInt(b,10)),f.scroller_$container.find("."+d.scrollerFixed).remove(),b=f.scroller_fixedColumns,b>0&&b<e.columns-1?c.scroller.setupFixed(e,f):f.scroller_$container.removeClass(d.scrollerHasFix)}),n.off("resize resizeEnd ".split(" ").join(o+" ")).on("resize"+o,c.window_resize).on("resizeEnd"+o,function(){n.off("resize"+o,c.window_resize),c.scroller.resize(e,f),n.on("resize"+o,c.window_resize)}),e.isScrolling=!0},resize:function(e,f){var g,h,i,j,k,l,m,n,o=e.$table,p=o.parent(),q=f.scroller_$header,r=f.scroller_$footer,s=e.namespace.slice(1)+"tsscroller",t=a("div."+d.scrollerWrap+'[id != "'+s+'"]').hide();for(o.children("thead").show(),o.add(q).add(r).children("colgroup").remove(),o.addClass(d.scrollerReset).children("thead").find("."+d.headerIn).addClass(d.scrollerReset).end().find("."+d.filterRow).show(),p.addClass(d.scrollerReset),h=parseInt(o.css("border-left-width"),10),f.scroller_barSetWidth=(f.scroller_barWidth||c.scroller.getBarWidth()||18)+h,p.width(p.parent().innerWidth()-(c.scroller.hasScrollBar(p.parent())?f.scroller_barSetWidth:0)),i=p.innerWidth()-(c.scroller.hasScrollBar(p)?f.scroller_barSetWidth:0)+h,q.parent().add(r.parent()).width(i),j=q.children("thead").children().children("th, td").filter(":visible"),k=o.children("tbody").eq(0).children().eq(0).children("th, td").filter(":visible"),l=r.children("tfoot").children().children("th, td").filter(":visible"),c.scroller.setWidth(j.add(k).add(l),""),m=o.children("thead").children().eq(0).children("th, td"),g=0;g<m.length;g++)n=m.eq(g),"border-box"===n.css("box-sizing")?i=n.outerWidth():"collapse"===j.eq(g).css("border-collapse")?n.length&&b.getComputedStyle?i=parseFloat(b.getComputedStyle(n[0],null).width):(h=parseFloat(n.css("border-width"))||0,i=n.outerWidth()-parseFloat(n.css("padding-left"))-parseFloat(n.css("padding-right"))-h):i=n.width(),c.scroller.setWidth(j.eq(g).add(k.eq(g)).add(l.eq(g)),i);f.scroller_$container.find("."+d.scrollerReset).removeClass(d.scrollerReset),c.fixColumnWidth(e.table),j=o.children("colgroup"),j.length&&(k=j[0].outerHTML,q.prepend(k),r.length&&r.prepend(k)),f.scroller_fixedColumns>0&&c.scroller.updateFixed(e,f,!0),o.children("thead").find("."+d.filterRow).hide(),t.show()},setupFixed:function(b,e){var f,g,h,i,j,k,l,m,n=b.$table,o=b.namespace+"tsscrollerFixed",p=e.scroller_$container,q=e.scroller_fixedColumns;for(k=p.addClass(d.scrollerHasFix).clone().addClass(d.scrollerFixed).removeClass(d.scrollerWrap).attr("id",""),l=k.find("."+d.scrollerTable),l.find("table").addClass(b.namespace.slice(1)+"_extra_table").attr("id",""),m=l.find("tbody"),e.scroller_$fixedColumns=k,n.hasClass(d.scrollerRtl)&&k.addClass(d.scrollerRtl),h=k.find("tr"),i=h.length,f=0;i>f;f++)h.eq(f).children(":gt("+(q-1)+")").remove();if(k.hide().prependTo(p),b.$table.hasClass("hasFilters"))for(c.filter.bindSearch(n,k.find("."+d.filter)),h=p.children("."+d.scrollerHeader).find("."+d.filter),i=h.length,f=0;i>f;f++)h.eq(f).hasClass(d.filterDisabled||"disabled")||h.eq(f).prop("disabled",q>f);for(b.$table.add("."+d.scrollerFooter+" table").children("thead").children("tr."+d.headerRow).children().attr("tabindex",-1),h=e.scroller_$header.add(k.find("."+d.scrollerTable+" table")).children("thead").children("tr."+d.headerRow),i=h.length,f=0;i>f;f++)for(j=h.eq(f).children(),g=0;g<j.length;g++)j.eq(g).attr("tabindex",q>g?-1:0);c.bindEvents(b.table,k.find("."+d.header)),j="tablesorter-initialized sortEnd filterEnd ".split(" ").join(o+" "),b.$table.off(j).on(j,function(){c.scroller.updateFixed(b,e,!1)}).parent().off("scroll"+o).on("scroll"+o,function(){l.scrollTop(a(this).scrollTop())}),l.off("scroll"+o).on("scroll"+o,function(){b.$table.parent().scrollTop(l.scrollTop())}).scroll(),""!==e.scroller_rowHighlight&&(j="mouseover mouseleave ".split(" ").join(o+" "),b.$table.off(j,"tr").on(j,"tr",function(b){var c=a(this).index();m.children().eq(c).add(this).toggleClass(e.scroller_rowHighlight,"mouseover"===b.type)}),l.find("table").off(j,"tr").on(j,"tr",function(c){var d=a(this).index();b.$tbodies.children().eq(d).add(this).toggleClass(e.scroller_rowHighlight,"mouseover"===c.type)})),(c.scroller.isFirefox||c.scroller.isOldIE)&&l.wrap('<div class="scroller-scrollbar-hack" style="overflow:hidden;">'),c.scroller.updateFixed(b,e,!0)},updateFixed:function(b,e){if(b.isScrolling){b.$table.parent().width(e.scroller_$container.width());var f,g,h,i,j,k,l,m,n=b.$table,o=e.scroller_$container,p=e.scroller_$container.children("."+d.scrollerTable).children("table").children("tbody"),q=e.scroller_$header.children("thead").children("."+d.headerRow),r=e.scroller_$fixedColumns.hide(),s=r.find("."+d.scrollerTable).children("table"),t=s.children("tbody"),u=r.find("."+d.scrollerHeader).children("table").children("thead"),v=c.scroller,w=e.scroller_barSetWidth,x=e.scroller_fixedColumns,y=n.find("tbody td"),z=parseInt(y.css("border-right-width"),10)||1,A=parseInt(y.css("border-bottom-width"),10)||1,B=parseInt(y.css("border-spacing").split(/\s/)[0],10)/2||0,C=parseInt(n.css("padding-left"),10)+parseInt(n.css("padding-right"),10)-z;for(y=u.children("."+d.headerRow),f=0;f<y.length;f++)y.eq(f).height(q.eq(f).outerHeight());if(q=(b.filteredRows>0?b.$tbodies:n.children("thead")).children("tr:visible"),m=q.children(":lt("+x+")").map(function(){return C+=a(this).outerWidth()+B,a(this).outerWidth()}).get(),v.setWidth(r.add(r.children()),C+2*z-B),v.setWidth(r.find("table"),C+z),r.height(o.height()),e.scroller_$footer.length)for(y=o.children("."+d.scrollerFooter).find("tfoot tr"),q=r.find("."+d.scrollerFooter+" tfoot tr"),f=0;f<q.length;f++)q.eq(f).height(y.eq(f).height());for(r.find("."+d.scrollerTable).height(n.parent().height()-w+A),g=0;g<b.$tbodies.length;g++)if(i=p.eq(g),i.length){for(q=i.children(),l=q.length,k=c.processTbody(s,t.eq(g),!0),k.empty(),h=0;l>h;h++)j=a(q[h].outerHTML),j.children("td, th").slice(x).remove(),j.children().eq(0).height(q.eq(h).outerHeight()-(v.isFirefox?2*A:0)),0===h&&v.setWidth(j.children().eq(0),m[0]),k.append(j);for(y=r.find("thead").children("tr."+d.headerRow),f=0;x>f;f++)v.setWidth(y.children(":eq("+f+")"),m[f]);c.processTbody(s,k,!1)}(v.isFirefox||v.isOldIE)&&s.parent().css({width:C+w+z}),r.show()}},remove:function(c,e){var f=e.scroller_$container,g=c.namespace+"tsscroller";c.$table.off(g).insertBefore(f).find("thead").show().css("visibility","visible").children("tr."+d.headerRow+" > *").attr("tabindex",0).end().find("."+d.filterRow).show().removeClass(d.filterRowHide),f.remove(),a(b).off(g),c.isScrolling=!1}}}(jQuery,window);