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

2 lines
14 KiB
JavaScript

/*! Widget: scroller - updated 5/17/2015 (v2.22.0) */
!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",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",scrollerReset:"tablesorter-scroller-reset",scrollerRtl:"ts-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_addFixedOverlay:!1,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(){c.timer_resize&&clearTimeout(c.timer_resize),c.timer_resize=setTimeout(function(){a(b).trigger("resizeEnd")},250)},a(function(){var b="<style>."+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+" { position: relative; overflow: hidden; }."+d.scrollerHeader+" table."+d.table+" { margin-bottom: 0; }."+d.scrollerTable+" { position: relative; overflow: auto; }."+d.scrollerTable+" table."+d.table+" { border-top: 0; margin-top: 0; margin-bottom: 0; overflow: hidden; }."+d.scrollerTable+" tfoot, ."+d.scrollerHideElement+", ."+d.scrollerHideColumn+" { display: none; }."+d.scrollerFixed+", ."+d.scrollerFixed+" ."+d.scrollerFixedPanel+" { 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: auto; }."+d.scrollerFixed+" ."+d.scrollerFooter+" { position: absolute; bottom: 0; }."+d.scrollerFixed+" ."+d.scrollerTable+" { position: relative; left: 0; overflow: auto; -ms-overflow-style: none; }."+d.scrollerFixed+" ."+d.scrollerTable+"::-webkit-scrollbar { display: none; }."+d.scrollerWrap+" ."+d.scrollerFixedPanel+" { position: absolute; top: 0; bottom: 0; z-index: 2; left: 0; right: 0; } </style>";a(b).appendTo("body")}),c.scroller={isFirefox:navigator.userAgent.toLowerCase().indexOf("firefox")>-1,isOldIE:document.all&&!b.atob,isSafari:navigator.userAgent.toLowerCase().indexOf("safari")>-1&&-1===navigator.userAgent.toLowerCase().indexOf("chrome"),hasScrollBar:function(a,b){return b?a.get(0).scrollWidth>a.width():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>").css({position:"absolute",top:"-9999px",left:0,width:"100px",height:"100px",overflow:"scroll",visibility:"hidden"}).appendTo("body"),c=b[0],d=c.offsetWidth-c.clientWidth;return b.remove(),d},setup:function(e,f){var g,h,i,j,k,l,m,n,o=a(b),p=e.namespace+"tsscroller",q=a(),r=e.namespace.slice(1)+"tsscroller",s=e.$table;f.scroller_calcWidths=[],f.scroller_isBusy=!0,f.scroller_barSetWidth=null!==f.scroller_barWidth?f.scroller_barWidth:c.scroller.getBarWidth()||15,g=f.scroller_height||300,i=a('<table class="'+s.attr("class")+'" cellpadding=0 cellspacing=0>'+s.children("thead")[0].outerHTML+"</table>"),f.scroller_$header=i.addClass(e.namespace.slice(1)+"_extra_table"),j=s.children("tfoot"),j.length&&(q=a('<table class="'+s.attr("class")+'" cellpadding=0 cellspacing=0 style="margin-top:0"></table>').addClass(e.namespace.slice(1)+"_extra_table").append(j.clone(!0)).wrap('<div class="'+d.scrollerFooter+'"/>'),l=q.children("tfoot").eq(0).children("tr").children()),f.scroller_$footer=q,s.wrap('<div id="'+r+'" class="'+d.scrollerWrap+'" />').before(i).find("."+d.filterRow).addClass(d.filterRowHide),f.scroller_$container=s.parent(),q.length&&s.after(q.parent()),k=i.wrap('<div class="'+d.scrollerHeader+'" />').find("."+d.header),s.wrap('<div class="'+d.scrollerTable+'" style="max-height:'+g+'px;" />'),m=s.parent(),c.bindEvents(e.table,k),s.hasClass("hasFilters")&&c.filter.bindSearch(s,i.find("."+d.filter)),s.find("thead").addClass(d.scrollerHideElement),h=m.parent().height(),m.off("scroll"+p).on("scroll"+p,function(){if(f.scroller_jumpToHeader){var b=o.scrollTop()-i.offset().top;0!==a(this).scrollTop()&&h>b&&b>0&&o.scrollTop(i.offset().top)}i.parent().add(q.parent()).scrollLeft(a(this).scrollLeft())}),n="sortEnd setFixedColumnSize updateComplete pagerComplete pagerInitialized columnUpdate ".split(" ").join(p+" "),s.off(n).on("sortEnd"+p,function(){f.scroller_upAfterSort&&s.parent().animate({scrollTop:0},"fast")}).on("setFixedColumnSize"+p,function(a,b){var g=f.scroller_$container;"undefined"==typeof b||isNaN(b)||(f.scroller_fixedColumns=parseInt(b,10)),c.scroller.removeFixed(e,f),b=f.scroller_fixedColumns,b>0&&b<e.columns-1?c.scroller.updateFixed(e,f):g.hasClass(d.scrollerHasFix)&&(g.removeClass(d.scrollerHasFix),c.scroller.resize(e,f))}).on("updateComplete pagerComplete columnUpdate ".split(" ").join(p+" "),function(a){c.hasWidget("pager")&&"updateComplete"===a.type||c.scroller.resize(e,f)}),o.off("resize resizeEnd ".split(" ").join(p+" ")).on("resize"+p,c.window_resize).on("resizeEnd"+p,function(){o.off("resize"+p,c.window_resize),c.scroller.resize(e,f),o.on("resize"+p,c.window_resize),m.trigger("scroll"+p)}),e.isScrolling=!0,c.scroller.updateFixed(e,f)},resize:function(e,f){var g,h,i,j,k,l,m,n,o,p=c.scroller,q=e.$table,r=q.parent(),s=f.scroller_$header,t=f.scroller_$footer,u=e.namespace.slice(1)+"tsscroller",v=a("div."+d.scrollerWrap+'[id!="'+u+'"]').addClass(d.scrollerHideElement);for(f.scroller_calcWidths=[],p.removeFixed(e,f),q.find("."+d.scrollerHideElement).removeClass(d.scrollerHideElement),q.addClass(d.scrollerReset).children("thead").find("."+d.headerIn).addClass(d.scrollerReset),r.addClass(d.scrollerReset),h=parseInt(q.css("border-left-width"),10),j=s.children("thead").children("tr").not("."+e.cssIgnoreRow).children("th, td").filter(":visible"),k=e.$tbodies.eq(0).children("tr").not("."+e.cssChildRow).eq(0).children("th, td").filter(":visible"),l=t.children("tfoot").children("tr").children("th, td").filter(":visible"),p.setWidth(j.add(k).add(l),""),m=e.$headerIndexed,g=0;g<m.length;g++)n=m[g],i="border-box"===n.css("box-sizing")?n.outerWidth():"collapse"===j.eq(g).css("border-collapse")?n.length&&b.getComputedStyle?parseFloat(b.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(),o=j.eq(g).add(k.eq(g)).add(l.eq(g)),p.setWidth(o,i),f.scroller_calcWidths[g]=i;o=r.parent().innerWidth()-(p.hasScrollBar(r)?f.scroller_barSetWidth:0),r.width(o),o=(p.hasScrollBar(r)?f.scroller_barSetWidth:0)+h,i=r.innerWidth()-o,s.parent().add(t.parent()).width(i),r.width(i+o),f.scroller_$container.find("."+d.scrollerReset).removeClass(d.scrollerReset),q.children("thead").addClass(d.scrollerHideElement),p.updateFixed(e,f),v.removeClass(d.scrollerHideElement)},setupFixed:function(a,b){var e,f,g,h,i,j,k,l,m=a.$table,n=b.scroller_$container,o=b.scroller_fixedColumns;for(j=n.addClass(d.scrollerHasFix).clone().addClass(d.scrollerFixed).removeClass(d.scrollerWrap).attr("id",""),b.scroller_addFixedOverlay&&j.append('<div class="'+d.scrollerFixedPanel+'">'),k=j.find("."+d.scrollerTable),l=k.children("table").children("tbody"),k.children("table").addClass(a.namespace.slice(1)+"_extra_table").attr("id","").children("thead, tfoot").remove(),b.scroller_$fixedColumns=j,m.hasClass(d.scrollerRtl)&&j.addClass(d.scrollerRtl),g=j.find("tr"),h=g.length,e=0;h>e;e++)g.eq(e).children(":gt("+(o-1)+")").remove();if(j.addClass(d.scrollerHideElement).prependTo(n),a.$table.hasClass("hasFilters"))for(g=j.find("."+d.filter).not("."+d.filterDisabled).prop("disabled",!1),c.filter.bindSearch(m,j.find("."+d.filter)),g=n.children("."+d.scrollerHeader).find("."+d.filter),h=g.length,e=0;h>e;e++)g.eq(e).hasClass(d.filterDisabled||"disabled")||g.eq(e).prop("disabled",o>e);for(a.$table.add("."+d.scrollerFooter+" table").children("thead").children("tr."+d.headerRow).children().attr("tabindex",-1),g=b.scroller_$header.add(j.find("."+d.scrollerTable+" table")).children("thead").children("tr."+d.headerRow),h=g.length,e=0;h>e;e++)for(i=g.eq(e).children(),f=0;f<i.length;f++)i.eq(f).attr("tabindex",o>f?-1:0);c.bindEvents(a.table,j.find("."+d.header)),c.scroller.bindFixedColumnEvents(a,b),(c.scroller.isFirefox||c.scroller.isOldIE)&&k.wrap('<div class="'+d.scrollerHack+'" style="overflow:hidden;">')},bindFixedColumnEvents:function(b,e){var f=c.scroller,g=b.namespace+"tsscrollerFixed",h=((c.hasWidget(b.table,"filter")?"filterEnd":"tablesorter-initialized")+" sortEnd ").split(" ").join(g+" "),i="scroll"+g,j=e.scroller_$fixedColumns.find("."+d.scrollerTable),k=!0,l=!0;b.$table.off(h).on(h,function(){f.updateFixed(b,e,!1),f.resize(b,e)}).parent().off(i).on(i,function(){e.scroller_isBusy||(k||!f.isFirefox)&&(l=!1,j[0].scrollTop=a(this).scrollTop(),setTimeout(function(){l=!0},20))}),j.off(i).on(i,function(){(l||!f.isFirefox)&&(k=!1,b.$table.parent()[0].scrollTop=a(this).scrollTop(),setTimeout(function(){k=!0},20))}).scroll(),""!==e.scroller_rowHighlight&&(h="mouseover mouseleave ".split(" ").join(g+" "),b.$table.off(h,"tbody > tr").on(h,"tbody > tr",function(a){var c=b.$table.children("tbody").children("tr").index(this);j.children("table").children("tbody").children("tr").eq(c).add(this).toggleClass(e.scroller_rowHighlight,"mouseover"===a.type)}),j.find("table").off(h,"tbody > tr").on(h,"tbody > tr",function(a){var c=j.children("table").children("tbody").children("tr"),d=c.index(this);b.$table.children("tbody").children("tr").eq(d).add(this).toggleClass(e.scroller_rowHighlight,"mouseover"===a.type)}))},updateFixed:function(b,e){var f=e.scroller_$container;if(0===e.scroller_fixedColumns)return e.scroller_isBusy=!1,void c.scroller.removeFixed(b,e);if(b.isScrolling){e.scroller_isBusy=!0,f.find("."+d.scrollerFixed).length||c.scroller.setupFixed(b,e);var g,h,i,j,k,l,m,n,o,p,q,r,s,t=b.$table,u=t.parent(),v=e.scroller_$header,w=e.scroller_$footer,x=e.scroller_$container.children("."+d.scrollerTable).children("table").children("tbody"),y=e.scroller_$header.children("thead").children("."+d.headerRow),z=e.scroller_$fixedColumns.addClass(d.scrollerHideElement),A=z.find("."+d.scrollerTable).children("table"),B=A.children("tbody"),C=c.scroller,D=e.scroller_barSetWidth,E=e.scroller_fixedColumns,F=t.hasClass(d.scrollerRtl),G=t.find("tbody td"),H=parseInt(G.css("border-right-width"),10)||1,I=parseInt((G.css("border-spacing")||"").split(/\s/)[0],10)/2||0,J=parseInt(t.css("padding-left"),10)+parseInt(t.css("padding-right"),10)-H,K=e.scroller_calcWidths;for(c.scroller.removeFixed(b,e,!1),g=0;E>g;g++)J+=K[g]+I;for(J=J+2*H-I,C.setWidth(z.add(z.children()),J),C.setWidth(z.children().children("table"),J),t.find("."+d.scrollerSpacerRow).remove(),s='<tr class="'+d.scrollerSpacerRow+" "+b.selectorRemove.slice(1)+'">',g=0;g<b.columns;g++)s+='<td style="padding:0; margin:0;height:0;max-height:0;min-height:0;width:'+K[g]+"px;min-width:"+K[g]+"px;max-width:"+K[g]+'px"></td>';for(b.$tbodies.eq(0).prepend(s+="</tr>"),h=0;h<b.$tbodies.length;h++)if(j=x.eq(h),j.length){for(y=j.children(),p=y.length,l=c.processTbody(A,B.eq(h),!0),l.empty(),i=0;p>i;i++)k=a(y[i].outerHTML),k.children("td, th").slice(E).remove(),l.append(k);for(m=z.find("thead").children("tr."+d.headerRow).children(),n=z.find(d.scrollerSpacerRow).children(),o=z.find("tfoot").children("tr").eq(0).children(),k=v.children("thead").children("tr").children("td, th"),y=w.children("tfoot").children("tr").children("td, th"),g=0;g<b.columns;g++)E>g&&(G=m.eq(g).add(n.eq(g)).add(o.eq(g)),C.setWidth(G,K[g])),G=k.eq(g).add(y.eq(g)),C.setWidth(G,K[g]);c.processTbody(A,l,!1)}for(r=c.scroller.hasScrollBar(u)?D:0,(C.isFirefox||C.isOldIE)&&A.css("width",J).parent().css("width",J+r),z.removeClass(d.scrollerHideElement),g=0;E>g;g++)f.children("div").children("table").find("th:nth-child("+(g+1)+"), td:nth-child("+(g+1)+")").addClass(d.scrollerHideColumn);J-=H,q=u.parent().innerWidth()-J,u.width(q),f.children("."+d.scrollerTable).css(F?"right":"left",J),f.children("."+d.scrollerHeader+", ."+d.scrollerFooter).css(F?"right":"left",J+(F&&c.scroller.isSafari?r:0)),v.parent().add(w.parent()).width(q-r),q=c.scroller.hasScrollBar(u,!0),r=q?D:0,!z.find("."+d.scrollerBarSpacer).length&&q?(G=a('<div class="'+d.scrollerBarSpacer+'">').css("height",r+"px"),z.find("."+d.scrollerTable).append(G)):q||z.find("."+d.scrollerBarSpacer).remove(),c.scroller.updateRowHeight(b,e),z.height(f.height()),z.removeClass(d.scrollerHideElement),e.scroller_isBusy=!1}},fixHeight:function(a,b){var c,e,f,g,h,i=a.length;for(c=0;i>c;c++)g=a.eq(c),h=b.eq(c),e=g.height(),f=h.height(),e>f?h.addClass(d.scrollerAddedHeight).height(e):f>e&&g.addClass(d.scrollerAddedHeight).height(f)},updateRowHeight:function(a,b){var e,f,g=b.scroller_$fixedColumns;b.scroller_$container.find("."+d.scrollerAddedHeight).removeClass(d.scrollerAddedHeight).height(""),e=b.scroller_$header.children("thead").children("tr"),f=g.children("."+d.scrollerHeader).children("table").children("thead").children("tr"),c.scroller.fixHeight(e,f),e=b.scroller_$footer.children("tfoot").children("tr"),f=g.children("."+d.scrollerFooter).children("table").children("tfoot").children("tr"),c.scroller.fixHeight(e,f),(c.scroller.isFirefox||c.scroller.isOldIE)&&(g=g.find("."+d.scrollerHack)),e=a.$table.children("tbody").children("tr"),f=g.children("."+d.scrollerTable).children("table").children("tbody").children("tr"),c.scroller.fixHeight(e,f)},removeFixed:function(a,b,c){var e=a.$table,f=b.scroller_$container,g=e.hasClass(d.scrollerRtl);(c||"undefined"==typeof c)&&f.find("."+d.scrollerFixed).remove(),f.find("."+d.scrollerHideColumn).removeClass(d.scrollerHideColumn),f.children(":not(."+d.scrollerFixed+")").css(g?"right":"left",0)},remove:function(c,e){var f=e.scroller_$container,g=c.namespace+"tsscroller";c.$table.off(g).insertBefore(f).find("thead").removeClass(d.scrollerHideElement).children("tr."+d.headerRow).children().attr("tabindex",0).end().find("."+d.filterRow).removeClass(d.scrollerHideElement+" "+d.filterRowHide),c.$table.find("."+d.filter).not("."+d.filterDisabled).prop("disabled",!1),f.remove(),a(b).off(g),c.isScrolling=!1}}}(jQuery,window);