mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
/*! Widget: scroller - updated 2018-05-07 (v2.30.4) */
|
|
!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(s,t){var i,d,c,a,n,h,f,p,b=e(r),u=l.scroller,m=s.namespace+"tsscroller",g=e(),v=s.namespace.slice(1)+"tsscroller",x=s.$table;s.widthFixed=!0,t.scroller_calcWidths=[],t.scroller_saved=[0,0],t.scroller_isBusy=!0,t.scroller_scrollTimer=null,null!==t.scroller_barWidth?t.scroller_barSetWidth=t.scroller_barWidth:(p=u.getBarWidth(),t.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>"),t.scroller_$header=d.addClass(s.namespace.slice(1)+"_extra_table"),(c=x.children("tfoot")).length&&(g=e('<table class="'+x.attr("class")+'" cellpadding=0 cellspacing=0 style="margin-top:0"></table>').addClass(s.namespace.slice(1)+"_extra_table").append(c.clone(!0)).wrap('<div class="'+o.scrollerFooter+'"/>')),t.scroller_$footer=g,x.wrap('<div id="'+v+'" class="'+o.scrollerWrap+'" />').before(d).find("."+o.filterRow).addClass(o.filterRowHide),t.scroller_$container=x.parent(),g.length&&x.after(g.parent()),a=d.wrap('<div class="'+o.scrollerHeader+'" />').find("."+o.header),x.wrap('<div class="'+o.scrollerTable+(t.scroller_height>0?'" style="max-height:'+t.scroller_height+'px;">':'">')),n=x.parent(),l.bindEvents(s.table,a),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(clearTimeout(t.scroller_scrollTimer),t.scroller_scrollTimer=setTimeout(function(){t.scroller_saved[0]=n.scrollLeft(),t.scroller_saved[1]=n.scrollTop()},300),t.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(s.table,"filter")?"filterEnd filterInit":"tablesorter-initialized updateComplete")+" sortEnd pagerComplete columnUpdate ").split(" ").join(m+" "),x.off(m).on("sortStart"+m,function(){clearTimeout(t.scroller_scrollTimer),t.scroller_isBusy=!0}).on("sortEnd filterEnd".split(" ").join(m+" "),function(e){"sortEnd"===e.type&&t.scroller_upAfterSort?n.scrollLeft(t.scroller_saved[0]).animate({scrollTop:0},"fast",function(){t.scroller_isBusy=!1}):t.scroller_fixedColumns&&setTimeout(function(){n.scrollTop(t.scroller_saved[1]).scrollLeft(t.scroller_saved[0]),u.updateFixed(s,t)},0)}).on("setFixedColumnSize"+m,function(e,r){var l=t.scroller_$container;void 0===r||isNaN(r)||(t.scroller_fixedColumns=parseInt(r,10)),u.removeFixed(s,t),(r=t.scroller_fixedColumns)>0&&r<s.columns-1?u.updateFixed(s,t):l.hasClass(o.scrollerHasFix)&&(l.removeClass(o.scrollerHasFix),u.resize(s,t))}).on(h,function(e){l.hasWidget("pager")&&"updateComplete"===e.type||(t.scroller_fixedColumns>0&&u.updateFixed(s,t),u.resize(s,t))}),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(s,t),b.on("resize"+m,l.window_resize),n.trigger("scroll"+m)}),s.isScrolling=!0,u.updateFixed(s,t),s.table.hasInitialized&&s.isScrolling&&setTimeout(function(){l.scroller.resize(s,t)},50)},resize:function(s,t){if(!t.scroller_isBusy){var i,d,c,a,n,h=l.scroller,f=t.scroller_$container,p=s.$table,b=p.parent(),u=t.scroller_$header,m=t.scroller_$footer,g=e(r),v=[g.scrollLeft(),g.scrollTop()],x=s.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+" "+s.selectorRemove.slice(1)+'" style="'+w+'">';for(t.scroller_calcWidths=[],h.removeFixed(s,t),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),a=s.$headerIndexed,i=0;i<s.columns;i++)C+='<td data-column="'+i+'" style="'+w+"width:"+(c="border-box"===(n=a[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:"+c+"px;max-width:"+c+'px"></td>',t.scroller_calcWidths[i]=c;C+="</tr>",s.$tbodies.eq(0).append(C),u.children("thead").append(C),m.children("tfoot").append(C),l.fixColumnWidth(s.table),C=s.$table.children("colgroup")[0].outerHTML,u.append(C),m.append(C),w=b.parent().innerWidth()-(h.hasScrollBar(b)?t.scroller_barSetWidth:0),b.width(w),w=(h.hasScrollBar(b)?t.scroller_barSetWidth:0)+d,c=b.innerWidth()-w,u.parent().add(m.parent()).width(c),b.width(c+w),p.children("thead, caption").addClass(o.scrollerHideElement),h.updateFixed(s,t),_.removeClass(o.scrollerHideElement),b.scrollTop(t.scroller_saved[1]),t.scroller_$container.find("."+o.scrollerFixed).find("."+o.scrollerTable).scrollTop(t.scroller_saved[1]),g.scrollLeft(v[0]),g.scrollTop(v[1]),setTimeout(function(){s.$table.triggerHandler("resizableUpdate"),s.$table.triggerHandler("scrollerComplete")},100)}},setupFixed:function(e,r){var s,t,i,d,c,a,n,h=e.$table,f=r.scroller_$container,p=r.scroller_fixedColumns;for((a=f.addClass(o.scrollerHasFix).clone().addClass(o.scrollerFixed).removeClass(o.scrollerWrap).attr("id","")).find("caption").html(" "),r.scroller_addFixedOverlay&&a.append('<div class="'+o.scrollerFixedPanel+'">'),(n=a.find("."+o.scrollerTable)).children("table").addClass(e.namespace.slice(1)+"_extra_table").attr("id","").children("thead, tfoot").remove(),r.scroller_$fixedColumns=a,h.hasClass(o.scrollerRtl)&&a.addClass(o.scrollerRtl),d=(i=a.find("tr")).length,s=0;s<d;s++)i.eq(s).children(":gt("+(p-1)+")").remove();if(a.addClass(o.scrollerHideElement).prependTo(f),e.$table.hasClass("hasFilters"))for(i=a.find("."+o.filter).not("."+o.filterDisabled).prop("disabled",!1),l.filter.bindSearch(h,a.find("."+o.filter)),d=(i=f.children("."+o.scrollerHeader).find("."+o.filter)).length,s=0;s<d;s++)i.eq(s).hasClass(o.filterDisabled||"disabled")||i.eq(s).prop("disabled",s<p);for(e.$table.add("."+o.scrollerFooter+" table").children("thead").children("tr."+o.headerRow).children().attr("tabindex",-1),d=(i=r.scroller_$header.add(a.find("."+o.scrollerTable+" table")).children("thead").children("tr."+o.headerRow)).length,s=0;s<d;s++)for(c=i.eq(s).children(),t=0;t<c.length;t++)c.eq(t).attr("tabindex",t<p?-1:0);l.bindEvents(e.table,a.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,s;return function(){var t=l||this,i=+new Date,d=arguments;o&&i<o+r?(clearTimeout(s),s=setTimeout(function(){o=i,e.apply(t,d)},r)):(o=i,e.apply(t,d))}},bindFixedColumnEvents:function(r,s){var t=l.scroller,i=r.namespace+"tsscrollerFixed",d="scroll"+i,c=s.scroller_$fixedColumns.find("."+o.scrollerTable),a=!0,n=!0;r.$table.parent().off(d).on(d,t.throttle(function(){if(!s.scroller_isBusy&&a){n=!1;var r=e(this);c[0].scrollTop=s.scroller_saved[1]=r.scrollTop(),s.scroller_saved[0]=r.scrollLeft(),setTimeout(function(){n=!0},20)}})),c.off(d).on(d,t.throttle(function(){!s.scroller_isBusy&&n&&(a=!1,r.$table.parent()[0].scrollTop=s.scroller_saved[1]=e(this).scrollTop(),setTimeout(function(){a=!0},20))})).scroll(),""!==s.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);c.children("table").children("tbody").children("tr").eq(l).add(this).toggleClass(s.scroller_rowHighlight,"mouseover"===e.type)}),c.find("table").off(d,"tbody > tr").on(d,"tbody > tr",function(e){var l=c.children("table").children("tbody").children("tr").index(this);r.$table.children("tbody").children("tr").eq(l).add(this).toggleClass(s.scroller_rowHighlight,"mouseover"===e.type)}))},adjustWidth:function(e,r,s,t,i){var d=r.scroller_$container;d.children("."+o.scrollerTable).css(i?"right":"left",s),d.children("."+o.scrollerHeader+", ."+o.scrollerFooter).css(i?"right":"left",s+(i&&l.scroller.isSafari?t:0))},updateFixed:function(r,s){var t,i,d=s.scroller_$container,c=s.scroller_$header,a=s.scroller_$footer,n=r.$table,h=n.parent(),f=s.scroller_barSetWidth,p=n.hasClass(o.scrollerRtl);if(0===s.scroller_fixedColumns)return s.scroller_isBusy=!1,l.scroller.removeFixed(r,s),t=d.width(),h.width(t),i=l.scroller.hasScrollBar(h)?f:0,void c.parent().add(a.parent()).width(t-i);if(r.isScrolling){s.scroller_isBusy=!0,d.find("."+o.scrollerFixed).length||l.scroller.setupFixed(r,s);var b,u,m,g,v,x,_,w=s.scroller_$container.children("."+o.scrollerTable).children("table").children("tbody"),C=s.scroller_$header.children("thead").children("."+o.headerRow),F=s.scroller_$fixedColumns.addClass(o.scrollerHideElement),H=F.find("."+o.scrollerTable).children("table"),T=H.children("tbody"),y=l.scroller,$=s.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=s.scroller_calcWidths;for(l.scroller.removeFixed(r,s,!1),b=0;b<$;b++)B+=R[b]+z;for(B+=2*E,y.setWidth(F.add(F.children()),B),y.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($).remove(),x.append(v);l.processTbody(H,x,!1)}for(i=l.scroller.hasScrollBar(h)?f:0,(y.isFirefox||y.isOldIE)&&H.css("width",B).parent().css("width",B+i),b=0;b<$;b++)t=":nth-child("+(b+1)+")",d.children("div").children("table").find("th"+t+", td"+t+", col"+t).addClass(o.scrollerHideColumn);F.removeClass(o.scrollerHideElement).find("colgroup").each(function(){e(this).find("col:gt("+($-1)+")").addClass(o.scrollerHideElement)}),B-=E,t=h.parent().innerWidth()-B,h.width(t),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)),c.parent().add(a.parent()).width(t-i),i=(t=l.scroller.hasScrollBar(h,!0))?f:0,!F.find("."+o.scrollerBarSpacer).length&&t?(S=e('<div class="'+o.scrollerBarSpacer+'">').css("height",i+"px"),F.find("."+o.scrollerTable).append(S)):t||F.find("."+o.scrollerBarSpacer).remove(),l.scroller.updateRowHeight(r,s),F.height(d.height()),F.removeClass(o.scrollerHideElement),F.find("caption").height(s.scroller_$header.find("caption").height()),h.scroll(),setTimeout(function(){s.scroller_isBusy=!1},0)}},fixHeight:function(e,r){var l,s,t,i,d,c=o.scrollerAddedHeight,a=e.length;for(l=0;l<a;l++)i=e.eq(l),d=r.eq(l),(s=i.height())>(t=d.height())?d.addClass(c).height(s):s<t&&i.addClass(c).height(t)},updateRowHeight:function(e,r){var s,t,i=r.scroller_$fixedColumns;r.scroller_$container.find("."+o.scrollerAddedHeight).removeClass(o.scrollerAddedHeight).height(""),s=r.scroller_$header.children("thead").children("tr"),t=i.children("."+o.scrollerHeader).children("table").children("thead").children("tr"),l.scroller.fixHeight(s,t),s=r.scroller_$footer.children("tfoot").children("tr"),t=i.children("."+o.scrollerFooter).children("table").children("tfoot").children("tr"),l.scroller.fixHeight(s,t),(l.scroller.isFirefox||l.scroller.isOldIE)&&(i=i.find("."+o.scrollerHack)),s=e.$table.children("tbody").children("tr"),t=i.children("."+o.scrollerTable).children("table").children("tbody").children("tr"),l.scroller.fixHeight(s,t)},removeFixed:function(e,r,l){var s=e.$table,t=r.scroller_$container,i=s.hasClass(o.scrollerRtl);(l||void 0===l)&&t.find("."+o.scrollerFixed).remove(),t.find("."+o.scrollerHideColumn).removeClass(o.scrollerHideColumn),t.children(":not(."+o.scrollerFixed+")").css(i?"right":"left",0)},remove:function(l,s){var t=s.scroller_$container,i=l.namespace+"tsscroller";l.$table.off(i),e(r).off(i),t&&(l.$table.insertBefore(t).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),t.remove(),l.isScrolling=!1)}}}(jQuery,window); |