tablesorter/dist/js/widgets/widget-scroller.min.js
2015-05-30 15:07:37 -05:00

2 lines
15 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: hidden; -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_barSetWidth=null!==f.scroller_barWidth?f.scroller_barWidth:c.scroller.getBarWidth()||15,g=f.scroller_height||300,h=0,s.children("tbody").map(function(){h+=a(this).outerHeight()}),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 pagerInitialized columnUpdate ".split(" ").join(p+" "),function(){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=e.$table,q=p.parent(),r=f.scroller_$header,s=f.scroller_$footer,t=e.namespace.slice(1)+"tsscroller",u=a("div."+d.scrollerWrap+'[id!="'+t+'"]').addClass(d.scrollerHideElement);for(c.scroller.removeFixed(e,f),p.children("thead").removeClass(d.scrollerHideElement),p.addClass(d.scrollerReset).children("thead").find("."+d.headerIn).addClass(d.scrollerReset).end().find("."+d.filterRow).removeClass(d.scrollerHideElement),q.addClass(d.scrollerReset),h=parseInt(p.css("border-left-width"),10),j=r.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=s.children("tfoot").children("tr").children("th, td").filter(":visible"),c.scroller.setWidth(j.add(k).add(l),""),m=p.children("thead").children().eq(0).children("th, td"),g=0;g<m.length;g++)n=m.eq(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)),c.scroller.setWidth(o,i);o=q.parent().innerWidth()-(c.scroller.hasScrollBar(q)?f.scroller_barSetWidth:0),q.width(o),i=q.innerWidth()-(c.scroller.hasScrollBar(q)?f.scroller_barSetWidth:0)+h,r.parent().add(s.parent()).width(i),f.scroller_$container.find("."+d.scrollerReset).removeClass(d.scrollerReset),c.scroller.updateFixed(e,f),p.children("thead").addClass(d.scrollerHideElement),u.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=b.namespace+"tsscrollerFixed",g="tablesorter-initialized sortEnd filterEnd ".split(" ").join(f+" "),h="scroll"+f,i=e.scroller_$fixedColumns.find("."+d.scrollerTable),j=!0,k=!0;b.$table.off(g).on(g,function(){c.scroller.updateFixed(b,e,!1),c.scroller.resize(b,e)}).parent().off(h).on(h,function(){(j||!c.scroller.isFirefox)&&(k=!1,i[0].scrollTop=a(this).scrollTop(),setTimeout(function(){k=!0},20))}),i.off(h).on(h,function(){(k||!c.scroller.isFirefox)&&(j=!1,b.$table.parent()[0].scrollTop=a(this).scrollTop(),setTimeout(function(){j=!0},20))}).scroll(),""!==e.scroller_rowHighlight&&(g="mouseover mouseleave ".split(" ").join(f+" "),b.$table.off(g,"tbody > tr").on(g,"tbody > tr",function(a){var c=b.$table.children("tbody").children("tr").index(this);i.children("table").children("tbody").children("tr").eq(c).add(this).toggleClass(e.scroller_rowHighlight,"mouseover"===a.type)}),i.find("table").off(g,"tbody > tr").on(g,"tbody > tr",function(a){var c=i.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 void c.scroller.removeFixed(b,e);if(b.isScrolling){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,u=b.$table,v=u.parent(),w=e.scroller_$header,x=e.scroller_$footer,y=e.scroller_$container.children("."+d.scrollerTable).children("table").children("tbody"),z=e.scroller_$header.children("thead").children("."+d.headerRow),A=e.scroller_$fixedColumns.addClass(d.scrollerHideElement),B=A.find("."+d.scrollerTable).children("table"),C=B.children("tbody"),D=c.scroller,E=e.scroller_barSetWidth,F=e.scroller_fixedColumns,G=u.hasClass(d.scrollerRtl),H=u.find("tbody td"),I=parseInt(H.css("border-right-width"),10)||1,J=parseInt((H.css("border-spacing")||"").split(/\s/)[0],10)/2||0,K=parseInt(u.css("padding-left"),10)+parseInt(u.css("padding-right"),10)-I;for(c.scroller.removeFixed(b,e,!1),u.children("thead").removeClass(d.scrollerHideElement),q=[],g=0;g<b.columns;g++)r=b.$headerIndexed[g].outerWidth(),K+=F>g?r+J:0,q.push(r);for(u.children("thead").addClass(d.scrollerHideElement),K=K+2*I-J,D.setWidth(A.add(A.children()),K),D.setWidth(A.children().children("table"),K),u.find("."+d.scrollerSpacerRow).remove(),t='<tr class="'+d.scrollerSpacerRow+" "+b.selectorRemove.slice(1)+'">',g=0;g<b.columns;g++)t+='<td style="padding:0; margin:0;height:0;max-height:0;min-height:0;width:'+q[g]+"px;min-width:"+q[g]+"px;max-width:"+q[g]+'px"></td>';for(b.$tbodies.eq(0).prepend(t+="</tr>"),h=0;h<b.$tbodies.length;h++)if(j=y.eq(h),j.length){for(z=j.children(),p=z.length,l=c.processTbody(B,C.eq(h),!0),l.empty(),i=0;p>i;i++)k=a(z[i].outerHTML),k.children("td, th").slice(F).remove(),l.append(k);for(m=A.find("thead").children("tr."+d.headerRow).children(),n=A.find(d.scrollerSpacerRow).children(),o=A.find("tfoot").children("tr").eq(0).children(),k=w.children("thead").children("tr").children("td, th"),z=x.children("tfoot").children("tr").children("td, th"),g=0;g<b.columns;g++)F>g&&(H=m.eq(g).add(n.eq(g)).add(o.eq(g)),D.setWidth(H,q[g])),H=k.eq(g).add(z.eq(g)),D.setWidth(H,q[g]);c.processTbody(B,l,!1)}for((D.isFirefox||D.isOldIE)&&B.parent().css({width:K}),A.removeClass(d.scrollerHideElement),g=0;F>g;g++)f.children("div").children("table").find("th:nth-child("+(g+1)+"), td:nth-child("+(g+1)+")").addClass(d.scrollerHideColumn);s=c.scroller.hasScrollBar(v)?E:0,K-=I,r=v.parent().innerWidth()-K,v.width(r),f.children("."+d.scrollerTable).css(G?"right":"left",K),f.children("."+d.scrollerHeader+", ."+d.scrollerFooter).css(G?"right":"left",K+(G&&c.scroller.isSafari?s:0)),w.parent().add(x.parent()).width(r-s),r=c.scroller.hasScrollBar(v,!0),s=r?E:0,!A.find("."+d.scrollerBarSpacer).length&&r?(H=a('<div class="'+d.scrollerBarSpacer+'">').css("height",s+"px"),A.find("."+d.scrollerTable).append(H)):r||A.find("."+d.scrollerBarSpacer).remove(),c.scroller.updateRowHeight(b,e),A.height(f.height()),A.removeClass(d.scrollerHideElement)}},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&&(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);