tablesorter/dist/js/widgets/widget-scroller.min.js
Rob Garrison e542aebf1c 2.29.6
2018-02-25 13:04:11 -06:00

2 lines
15 KiB
JavaScript

/*! Widget: scroller - updated 12/13/2017 (v2.29.1) */
!function(e,r){"use strict";var l=e.tablesorter,o=l.css;e.extend(l.css,{scrollerWrap:"tablesorter-scroller",scrollerHeader:"tablesorter-scroller-header",scrollerTable:"tablesorter-scroller-table",scrollerFooter:"tablesorter-scroller-footer",scrollerFixed:"tablesorter-scroller-fixed",scrollerFixedPanel:"tablesorter-scroller-fixed-panel",scrollerHasFix:"tablesorter-scroller-has-fixed-columns",scrollerHideColumn:"tablesorter-scroller-hidden-column",scrollerHideElement:"tablesorter-scroller-hidden",scrollerSpacerRow:"tablesorter-scroller-spacer",scrollerBarSpacer:"tablesorter-scroller-bar-spacer",scrollerAddedHeight:"tablesorter-scroller-added-height",scrollerHack:"tablesorter-scroller-scrollbar-hack",scrollerRtl:"ts-scroller-rtl"}),l.addWidget({id:"scroller",priority:60,options:{scroller_height:300,scroller_jumpToHeader:!0,scroller_upAfterSort:!0,scroller_fixedColumns:0,scroller_rowHighlight:"hover",scroller_addFixedOverlay:!1,scroller_barWidth:null},format:function(e,r,o){r.isScrolling?l.scroller.resize(r,o):l.scroller.setup(r,o)},remove:function(e,r,o){l.scroller.remove(r,o)}}),l.window_resize=function(){l.timer_resize&&clearTimeout(l.timer_resize),l.timer_resize=setTimeout(function(){e(r).trigger("resizeEnd")},250)},e(function(){var r="<style>."+o.scrollerWrap+" { position: relative; overflow: hidden; }."+o.scrollerWrap+" * { box-sizing: border-box; }."+o.scrollerHeader+", ."+o.scrollerFooter+" { position: relative; overflow: hidden; }."+o.scrollerHeader+" table."+o.table+" { margin-bottom: 0; }."+o.scrollerTable+" { position: relative; overflow: auto; }."+o.scrollerTable+" table."+o.table+" { border-top: 0; margin-top: 0; margin-bottom: 0; overflow: hidden; max-width: initial; }."+o.scrollerTable+" tfoot, ."+o.scrollerHideElement+", ."+o.scrollerHideColumn+" { display: none; }."+o.scrollerFixed+", ."+o.scrollerFixed+" ."+o.scrollerFixedPanel+" { pointer-events: none; }."+o.scrollerFixed+" > div { pointer-events: all; }."+o.scrollerWrap+" ."+o.scrollerFixed+" { position: absolute; top: 0; z-index: 1; left: 0 } ."+o.scrollerWrap+" ."+o.scrollerFixed+"."+o.scrollerRtl+" { left: auto; right: 0 } ."+o.scrollerWrap+"."+o.scrollerHasFix+" > ."+o.scrollerTable+" { overflow: auto; }."+o.scrollerFixed+" ."+o.scrollerFooter+" { position: absolute; bottom: 0; }."+o.scrollerFixed+" ."+o.scrollerTable+" { position: relative; left: 0; overflow: auto; -ms-overflow-style: none; }."+o.scrollerFixed+" ."+o.scrollerTable+"::-webkit-scrollbar { display: none; }."+o.scrollerWrap+" ."+o.scrollerFixedPanel+" { position: absolute; top: 0; bottom: 0; z-index: 2; left: 0; right: 0; } </style>";e("head").append(r)}),l.scroller={isFirefox:navigator.userAgent.toLowerCase().indexOf("firefox")>-1,isOldIE:document.all&&!r.atob,isIE:document.all&&!r.atob||navigator.appVersion.indexOf("Trident/")>0,isSafari:navigator.userAgent.toLowerCase().indexOf("safari")>-1&&-1===navigator.userAgent.toLowerCase().indexOf("chrome"),hasScrollBar:function(e,r){return r?e.get(0).scrollWidth>e.width():e.get(0).scrollHeight>e.height()},setWidth:function(e,r){e.css({width:r,"min-width":r,"max-width":r})},getBarWidth:function(){var r=e("<div>").css({position:"absolute",top:"-9999px",left:0,width:"100px",height:"100px",overflow:"scroll",visibility:"hidden"}).appendTo("body"),l=r[0],o=l.offsetWidth-l.clientWidth;return r.remove(),o},setup:function(t,s){var i,d,a,c,n,h,f,p,b=e(r),u=l.scroller,m=t.namespace+"tsscroller",g=e(),v=t.namespace.slice(1)+"tsscroller",x=t.$table;t.widthFixed=!0,s.scroller_calcWidths=[],s.scroller_saved=[0,0],s.scroller_isBusy=!0,null!==s.scroller_barWidth?s.scroller_barSetWidth=s.scroller_barWidth:(p=u.getBarWidth(),s.scroller_barSetWidth=null!==p?p:15),f=x.children("caption"),d=e('<table class="'+x.attr("class")+'" cellpadding=0 cellspacing=0>'+(f.length?f[0].outerHTML:"")+x.children("thead")[0].outerHTML+"</table>"),s.scroller_$header=d.addClass(t.namespace.slice(1)+"_extra_table"),(a=x.children("tfoot")).length&&(g=e('<table class="'+x.attr("class")+'" cellpadding=0 cellspacing=0 style="margin-top:0"></table>').addClass(t.namespace.slice(1)+"_extra_table").append(a.clone(!0)).wrap('<div class="'+o.scrollerFooter+'"/>')).children("tfoot").eq(0).children("tr").children(),s.scroller_$footer=g,x.wrap('<div id="'+v+'" class="'+o.scrollerWrap+'" />').before(d).find("."+o.filterRow).addClass(o.filterRowHide),s.scroller_$container=x.parent(),g.length&&x.after(g.parent()),c=d.wrap('<div class="'+o.scrollerHeader+'" />').find("."+o.header),x.wrap('<div class="'+o.scrollerTable+(s.scroller_height>0?'" style="max-height:'+s.scroller_height+'px;">':'">')),n=x.parent(),l.bindEvents(t.table,c),x.hasClass("hasFilters")&&l.filter.bindSearch(x,d.find("."+o.filter)),x.children("thead, caption").addClass(o.scrollerHideElement),i=n.parent().height(),n.off("scroll"+m).on("scroll"+m,function(){if(s.scroller_saved[0]=n.scrollLeft(),s.scroller_saved[1]=n.scrollTop(),s.scroller_jumpToHeader){var r=b.scrollTop()-d.offset().top;0!==e(this).scrollTop()&&r<i&&r>0&&b.scrollTop(d.offset().top)}d.parent().add(g.parent()).scrollLeft(e(this).scrollLeft())}),h=((f=l.hasWidget(t.table,"filter")?"filterEnd filterInit":"tablesorter-initialized updateComplete")+" sortEnd pagerComplete columnUpdate ").split(" ").join(m+" "),x.off(m).on("sortEnd filterEnd".split(" ").join(m+" "),function(e){"sortEnd"===e.type&&s.scroller_upAfterSort?n.animate({scrollTop:0},"fast"):s.scroller_fixedColumns&&setTimeout(function(){n.scrollTop(s.scroller_saved[1]).scrollLeft(s.scroller_saved[0]),u.updateFixed(t,s)},0)}).on("setFixedColumnSize"+m,function(e,r){var l=s.scroller_$container;void 0===r||isNaN(r)||(s.scroller_fixedColumns=parseInt(r,10)),u.removeFixed(t,s),(r=s.scroller_fixedColumns)>0&&r<t.columns-1?u.updateFixed(t,s):l.hasClass(o.scrollerHasFix)&&(l.removeClass(o.scrollerHasFix),u.resize(t,s))}).on(h,function(e){l.hasWidget("pager")&&"updateComplete"===e.type||(s.scroller_fixedColumns>0&&u.updateFixed(t,s),u.resize(t,s))}),b.off("resize resizeEnd ".split(" ").join(m+" ")).on("resize"+m,l.window_resize).on("resizeEnd"+m,function(){b.off("resize"+m,l.window_resize),u.resize(t,s),b.on("resize"+m,l.window_resize),n.trigger("scroll"+m)}),t.isScrolling=!0,u.updateFixed(t,s),t.table.hasInitialized&&t.isScrolling&&setTimeout(function(){l.scroller.resize(t,s)},50)},resize:function(t,s){if(!s.scroller_isBusy){var i,d,a,c,n,h=l.scroller,f=s.scroller_$container,p=t.$table,b=p.parent(),u=s.scroller_$header,m=s.scroller_$footer,g=e(r),v=[g.scrollLeft(),g.scrollTop()],x=t.namespace.slice(1)+"tsscroller",_=e("div."+o.scrollerWrap+'[id!="'+x+'"]').addClass(o.scrollerHideElement),w="padding:0;margin:0;border:0;height:0;max-height:0;min-height:0;",C='<tr class="'+o.scrollerSpacerRow+" "+t.selectorRemove.slice(1)+'" style="'+w+'">';for(s.scroller_calcWidths=[],h.removeFixed(t,s),f.find("."+o.scrollerSpacerRow).remove(),f.find("."+l.css.colgroup).remove(),p.find("."+o.scrollerHideElement).removeClass(o.scrollerHideElement),d=parseInt(p.css("border-left-width"),10),c=t.$headerIndexed,i=0;i<t.columns;i++)C+='<td data-column="'+i+'" style="'+w+"width:"+(a="border-box"===(n=c[i]).css("box-sizing")?n.outerWidth():"collapse"===n.css("border-collapse")?n.length&&r.getComputedStyle?parseFloat(r.getComputedStyle(n[0],null).width):n.outerWidth()-parseFloat(n.css("padding-left"))-parseFloat(n.css("padding-right"))-(parseFloat(n.css("border-width"))||0):n.width())+"px;min-width:"+a+"px;max-width:"+a+'px"></td>',s.scroller_calcWidths[i]=a;C+="</tr>",t.$tbodies.eq(0).append(C),u.children("thead").append(C),m.children("tfoot").append(C),l.fixColumnWidth(t.table),C=t.$table.children("colgroup")[0].outerHTML,u.append(C),m.append(C),w=b.parent().innerWidth()-(h.hasScrollBar(b)?s.scroller_barSetWidth:0),b.width(w),w=(h.hasScrollBar(b)?s.scroller_barSetWidth:0)+d,a=b.innerWidth()-w,u.parent().add(m.parent()).width(a),b.width(a+w),p.children("thead, caption").addClass(o.scrollerHideElement),h.updateFixed(t,s),_.removeClass(o.scrollerHideElement),b.scrollTop(s.scroller_saved[1]),s.scroller_$container.find("."+o.scrollerFixed).find("."+o.scrollerTable).scrollTop(s.scroller_saved[1]),g.scrollLeft(v[0]),g.scrollTop(v[1]),setTimeout(function(){t.$table.triggerHandler("resizableUpdate"),t.$table.triggerHandler("scrollerComplete")},100)}},setupFixed:function(e,r){var t,s,i,d,a,c,n,h=e.$table,f=r.scroller_$container,p=r.scroller_fixedColumns;for((c=f.addClass(o.scrollerHasFix).clone().addClass(o.scrollerFixed).removeClass(o.scrollerWrap).attr("id","")).find("caption").html("&nbsp;"),r.scroller_addFixedOverlay&&c.append('<div class="'+o.scrollerFixedPanel+'">'),(n=c.find("."+o.scrollerTable)).children("table").addClass(e.namespace.slice(1)+"_extra_table").attr("id","").children("thead, tfoot").remove(),r.scroller_$fixedColumns=c,h.hasClass(o.scrollerRtl)&&c.addClass(o.scrollerRtl),d=(i=c.find("tr")).length,t=0;t<d;t++)i.eq(t).children(":gt("+(p-1)+")").remove();if(c.addClass(o.scrollerHideElement).prependTo(f),e.$table.hasClass("hasFilters"))for(i=c.find("."+o.filter).not("."+o.filterDisabled).prop("disabled",!1),l.filter.bindSearch(h,c.find("."+o.filter)),d=(i=f.children("."+o.scrollerHeader).find("."+o.filter)).length,t=0;t<d;t++)i.eq(t).hasClass(o.filterDisabled||"disabled")||i.eq(t).prop("disabled",t<p);for(e.$table.add("."+o.scrollerFooter+" table").children("thead").children("tr."+o.headerRow).children().attr("tabindex",-1),d=(i=r.scroller_$header.add(c.find("."+o.scrollerTable+" table")).children("thead").children("tr."+o.headerRow)).length,t=0;t<d;t++)for(a=i.eq(t).children(),s=0;s<a.length;s++)a.eq(s).attr("tabindex",s<p?-1:0);l.bindEvents(e.table,c.find("."+o.header)),l.scroller.bindFixedColumnEvents(e,r),(l.scroller.isFirefox||l.scroller.isOldIE)&&n.wrap('<div class="'+o.scrollerHack+'" style="overflow:hidden;">')},throttle:function(e,r,l){r=r||50;var o,t;return function(){var s=l||this,i=+new Date,d=arguments;o&&i<o+r?(clearTimeout(t),t=setTimeout(function(){o=i,e.apply(s,d)},r)):(o=i,e.apply(s,d))}},bindFixedColumnEvents:function(r,t){var s=l.scroller,i=r.namespace+"tsscrollerFixed",d="scroll"+i,a=t.scroller_$fixedColumns.find("."+o.scrollerTable),c=!0,n=!0;r.$table.parent().off(d).on(d,s.throttle(function(){if(!t.scroller_isBusy&&c){n=!1;var r=e(this);a[0].scrollTop=t.scroller_saved[1]=r.scrollTop(),t.scroller_saved[0]=r.scrollLeft(),setTimeout(function(){n=!0},20)}})),a.off(d).on(d,s.throttle(function(){!t.scroller_isBusy&&n&&(c=!1,r.$table.parent()[0].scrollTop=t.scroller_saved[1]=e(this).scrollTop(),setTimeout(function(){c=!0},20))})).scroll(),""!==t.scroller_rowHighlight&&(d="mouseover mouseleave ".split(" ").join(i+" "),r.$table.off(d,"tbody > tr").on(d,"tbody > tr",function(e){var l=r.$table.children("tbody").children("tr").index(this);a.children("table").children("tbody").children("tr").eq(l).add(this).toggleClass(t.scroller_rowHighlight,"mouseover"===e.type)}),a.find("table").off(d,"tbody > tr").on(d,"tbody > tr",function(e){var l=a.children("table").children("tbody").children("tr").index(this);r.$table.children("tbody").children("tr").eq(l).add(this).toggleClass(t.scroller_rowHighlight,"mouseover"===e.type)}))},adjustWidth:function(e,r,t,s,i){var d=r.scroller_$container;d.children("."+o.scrollerTable).css(i?"right":"left",t),d.children("."+o.scrollerHeader+", ."+o.scrollerFooter).css(i?"right":"left",t+(i&&l.scroller.isSafari?s:0))},updateFixed:function(r,t){var s,i,d=t.scroller_$container,a=t.scroller_$header,c=t.scroller_$footer,n=r.$table,h=n.parent(),f=t.scroller_barSetWidth,p=n.hasClass(o.scrollerRtl);if(0===t.scroller_fixedColumns)return t.scroller_isBusy=!1,l.scroller.removeFixed(r,t),s=d.width(),h.width(s),i=l.scroller.hasScrollBar(h)?f:0,void a.parent().add(c.parent()).width(s-i);if(r.isScrolling){t.scroller_isBusy=!0,d.find("."+o.scrollerFixed).length||l.scroller.setupFixed(r,t);var b,u,m,g,v,x,_,w=t.scroller_$container.children("."+o.scrollerTable).children("table").children("tbody"),C=t.scroller_$header.children("thead").children("."+o.headerRow),F=t.scroller_$fixedColumns.addClass(o.scrollerHideElement),H=F.find("."+o.scrollerTable).children("table"),T=H.children("tbody"),$=l.scroller,y=t.scroller_fixedColumns,W=function(e,r,l){return parseInt(e.css(r)||"",10)||l||0},S=n.find("tbody td"),E=W(S,"border-right-width",1),z=W(S,"border-spacing",0),B=W(n,"padding-left")+W(n,"padding-right")+2*W(n,"border-left-width",1)+W(n,"border-right-width",1)-E+z/2,R=t.scroller_calcWidths;for(l.scroller.removeFixed(r,t,!1),b=0;b<y;b++)B+=R[b]+z;for(B+=2*E,$.setWidth(F.add(F.children()),B),$.setWidth(F.children().children("table"),B),u=0;u<r.$tbodies.length;u++)if((g=w.eq(u)).length){for(_=(C=g.children()).length,(x=l.processTbody(H,T.eq(u),!0)).empty(),m=0;m<_;m++)(v=e(C[m].outerHTML)).children("td, th").slice(y).remove(),x.append(v);l.processTbody(H,x,!1)}for(i=l.scroller.hasScrollBar(h)?f:0,($.isFirefox||$.isOldIE)&&H.css("width",B).parent().css("width",B+i),b=0;b<y;b++)s=":nth-child("+(b+1)+")",d.children("div").children("table").find("th"+s+", td"+s+", col"+s).addClass(o.scrollerHideColumn);F.removeClass(o.scrollerHideElement).find("colgroup").each(function(){e(this).find("col:gt("+(y-1)+")").addClass(o.scrollerHideElement)}),B-=E,s=h.parent().innerWidth()-B,h.width(s),d.children("."+o.scrollerTable).css(p?"right":"left",B),d.children("."+o.scrollerHeader+", ."+o.scrollerFooter).css(p?"right":"left",B+(p&&l.scroller.isSafari?i:0)),a.parent().add(c.parent()).width(s-i),i=(s=l.scroller.hasScrollBar(h,!0))?f:0,!F.find("."+o.scrollerBarSpacer).length&&s?(S=e('<div class="'+o.scrollerBarSpacer+'">').css("height",i+"px"),F.find("."+o.scrollerTable).append(S)):s||F.find("."+o.scrollerBarSpacer).remove(),l.scroller.updateRowHeight(r,t),F.height(d.height()),F.removeClass(o.scrollerHideElement),F.find("caption").height(t.scroller_$header.find("caption").height()),h.scroll(),t.scroller_isBusy=!1}},fixHeight:function(e,r){var l,t,s,i,d,a=o.scrollerAddedHeight,c=e.length;for(l=0;l<c;l++)i=e.eq(l),d=r.eq(l),(t=i.height())>(s=d.height())?d.addClass(a).height(t):t<s&&i.addClass(a).height(s)},updateRowHeight:function(e,r){var t,s,i=r.scroller_$fixedColumns;r.scroller_$container.find("."+o.scrollerAddedHeight).removeClass(o.scrollerAddedHeight).height(""),t=r.scroller_$header.children("thead").children("tr"),s=i.children("."+o.scrollerHeader).children("table").children("thead").children("tr"),l.scroller.fixHeight(t,s),t=r.scroller_$footer.children("tfoot").children("tr"),s=i.children("."+o.scrollerFooter).children("table").children("tfoot").children("tr"),l.scroller.fixHeight(t,s),(l.scroller.isFirefox||l.scroller.isOldIE)&&(i=i.find("."+o.scrollerHack)),t=e.$table.children("tbody").children("tr"),s=i.children("."+o.scrollerTable).children("table").children("tbody").children("tr"),l.scroller.fixHeight(t,s)},removeFixed:function(e,r,l){var t=e.$table,s=r.scroller_$container,i=t.hasClass(o.scrollerRtl);(l||void 0===l)&&s.find("."+o.scrollerFixed).remove(),s.find("."+o.scrollerHideColumn).removeClass(o.scrollerHideColumn),s.children(":not(."+o.scrollerFixed+")").css(i?"right":"left",0)},remove:function(l,t){var s=t.scroller_$container,i=l.namespace+"tsscroller";l.$table.off(i),e(r).off(i),s&&(l.$table.insertBefore(s).find("thead").removeClass(o.scrollerHideElement).children("tr."+o.headerRow).children().attr("tabindex",0).end().find("."+o.filterRow).removeClass(o.scrollerHideElement+" "+o.filterRowHide),l.$table.find("."+o.filter).not("."+o.filterDisabled).prop("disabled",!1),s.remove(),l.isScrolling=!1)}}}(jQuery,window);