mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
/*! Widget: scroller - updated 4/18/2017 (v2.28.8) */
|
|
!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,a,c,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,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"),(a=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(a.clone(!0)).wrap('<div class="'+o.scrollerFooter+'"/>')).children("tfoot").eq(0).children("tr").children(),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()),c=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,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(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=((l.hasWidget(s.table,"filter")?"filterEnd":"tablesorter-initialized updateComplete")+" sortEnd pagerComplete columnUpdate ").split(" ").join(m+" "),x.off(m).on("sortEnd filterEnd".split(" ").join(m+" "),function(e){"sortEnd"===e.type&&t.scroller_upAfterSort?n.animate({scrollTop:0},"fast"):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,a,c,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),c=s.$headerIndexed,i=0;i<s.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>',t.scroller_calcWidths[i]=a;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,a=b.innerWidth()-w,u.parent().add(m.parent()).width(a),b.width(a+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,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(" "),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,s=0;s<d;s++)i.eq(s).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,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(c.find("."+o.scrollerTable+" table")).children("thead").children("tr."+o.headerRow)).length,s=0;s<d;s++)for(a=i.eq(s).children(),t=0;t<a.length;t++)a.eq(t).attr("tabindex",t<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,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,a=s.scroller_$fixedColumns.find("."+o.scrollerTable),c=!0,n=!0;r.$table.parent().off(d).on(d,t.throttle(function(){if(!s.scroller_isBusy&&c){n=!1;var r=e(this);a[0].scrollTop=s.scroller_saved[1]=r.scrollTop(),s.scroller_saved[0]=r.scrollLeft(),setTimeout(function(){n=!0},20)}})),a.off(d).on(d,t.throttle(function(){!s.scroller_isBusy&&n&&(c=!1,r.$table.parent()[0].scrollTop=s.scroller_saved[1]=e(this).scrollTop(),setTimeout(function(){c=!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);a.children("table").children("tbody").children("tr").eq(l).add(this).toggleClass(s.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(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,a=s.scroller_$header,c=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 a.parent().add(c.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"),$=l.scroller,y=s.scroller_fixedColumns,W=n.find("tbody td"),S=parseInt(W.css("border-right-width"),10)||1,E=parseInt((W.css("border-spacing")||"").split(/\s/)[0],10)/2||0,z=parseInt(n.css("padding-left"),10)+parseInt(n.css("padding-right"),10)-S,B=s.scroller_calcWidths;for(l.scroller.removeFixed(r,s,!1),b=0;b<y;b++)z+=B[b]+E;for(z=z+2*S-E,$.setWidth(F.add(F.children()),z),$.setWidth(F.children().children("table"),z),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",z).parent().css("width",z+i),F.removeClass(o.scrollerHideElement),b=0;b<y;b++)t=":nth-child("+(b+1)+")",d.children("div").children("table").find("th"+t+", td"+t+", col"+t).addClass(o.scrollerHideColumn);z-=S,t=h.parent().innerWidth()-z,h.width(t),d.children("."+o.scrollerTable).css(p?"right":"left",z),d.children("."+o.scrollerHeader+", ."+o.scrollerFooter).css(p?"right":"left",z+(p&&l.scroller.isSafari?i:0)),a.parent().add(c.parent()).width(t-i),i=(t=l.scroller.hasScrollBar(h,!0))?f:0,!F.find("."+o.scrollerBarSpacer).length&&t?(W=e('<div class="'+o.scrollerBarSpacer+'">').css("height",i+"px"),F.find("."+o.scrollerTable).append(W)):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()),s.scroller_isBusy=!1}},fixHeight:function(e,r){var l,s,t,i,d,a=o.scrollerAddedHeight,c=e.length;for(l=0;l<c;l++)i=e.eq(l),d=r.eq(l),(s=i.height())>(t=d.height())?d.addClass(a).height(s):s<t&&i.addClass(a).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); |