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

2 lines
5.7 KiB
JavaScript
Raw Normal View History

2017-09-28 02:07:28 +00:00
/*! Widget: stickyHeaders - updated 9/27/2017 (v2.29.0) */
2018-02-25 19:04:11 +00:00
!function(e,s){"use strict";function t(s,t){var i=isNaN(t.stickyHeaders_offset)?e(t.stickyHeaders_offset):[];return i.length?i.height()||0:parseInt(t.stickyHeaders_offset,10)||0}var i=e.tablesorter||{};e.extend(i.css,{sticky:"tablesorter-stickyHeader",stickyVis:"tablesorter-sticky-visible",stickyHide:"tablesorter-sticky-hidden",stickyWrap:"tablesorter-sticky-wrapper"}),i.addHeaderResizeEvent=function(s,t,i){if((s=e(s)[0]).config){var r={timer:250},a=e.extend({},r,i),d=s.config,n=d.widgetOptions,c=function(e){var s,t,i,r,a,c,l=d.$headers.length;for(n.resize_flag=!0,t=[],s=0;s<l;s++)r=(i=d.$headers.eq(s)).data("savedSizes")||[0,0],a=i[0].offsetWidth,c=i[0].offsetHeight,a===r[0]&&c===r[1]||(i.data("savedSizes",[a,c]),t.push(i[0]));t.length&&!1!==e&&d.$table.triggerHandler("resize",[t]),n.resize_flag=!1};if(clearInterval(n.resize_timer),t)return n.resize_flag=!1,!1;c(!1),n.resize_timer=setInterval(function(){n.resize_flag||c()},a.timer)}},i.addWidget({id:"stickyHeaders",priority:54,options:{stickyHeaders:"",stickyHeaders_appendTo:null,stickyHeaders_attachTo:null,stickyHeaders_xScroll:null,stickyHeaders_yScroll:null,stickyHeaders_offset:0,stickyHeaders_filteredToTop:!0,stickyHeaders_cloneId:"-sticky",stickyHeaders_addResizeEvent:!0,stickyHeaders_includeCaption:!0,stickyHeaders_zIndex:2},format:function(r,a,d){if(!(a.$table.hasClass("hasStickyHeaders")||e.inArray("filter",a.widgets)>=0&&!a.$table.hasClass("hasFilters"))){var n,c,l,o,p=a.$table,f=e(d.stickyHeaders_attachTo||d.stickyHeaders_appendTo),h=a.namespace+"stickyheaders ",y=e(d.stickyHeaders_yScroll||d.stickyHeaders_attachTo||s),k=e(d.stickyHeaders_xScroll||d.stickyHeaders_attachTo||s),g=p.children("thead:first").children("tr").not(".sticky-false").children(),H=p.children("tfoot"),u=t(a,d),b=p.parent().closest("."+i.css.table).hasClass("hasStickyHeaders")?p.parent().closest("table.tablesorter")[0].config.widgetOptions.$sticky.parent():[],_=b.length?b.height():0,v=d.$sticky=p.clone().addClass("containsStickyHeaders "+i.css.sticky+" "+d.stickyHeaders+" "+a.namespace.slice(1)+"_extra_table").wrap('<div class="'+i.css.stickyWrap+'">'),m=v.parent().addClass(i.css.stickyHide).css({position:f.length?"absolute":"fixed",padding:parseInt(v.parent().parent().css("padding-left"),10),top:u+_,left:0,visibility:"hidden",zIndex:d.stickyHeaders_zIndex||2}),z=v.children("thead:first"),C="",T=function(e,t){var i,r,a,d,n,c=e.filter(":visible"),l=c.length;for(i=0;i<l;i++)d=t.filter(":visible").eq(i),"border-box"===(n=c.eq(i)).css("box-sizing")?r=n.outerWidth():"collapse"===d.css("border-collapse")?s.getComputedStyle?r=parseFloat(s.getComputedStyle(n[0],null).width):(a=parseFloat(n.css("border-width")),r=n.outerWidth()-parseFloat(n.css("padding-left"))-parseFloat(n.css("padding-right"))-a):r=n.width(),d.css({width:r,"min-width":r,"max-width":r})},w=function(t){return!1===t&&b.length?p.position().left:f.length?parseInt(f.css("padding-left"),10)||0:p.offset().left-parseInt(p.css("margin-left"),10)-e(s).scrollLeft()},S=function(){m.css({left:w(),width:p.outerWidth()}),T(p,v),T(g,o)},x=function(s){if(p.is(":visible")){_=b.length?b.offset().top-y.scrollTop()+b.height():0;var r,n=p.offset(),c=t(a,d),l=e.isWindow(y[0]),o=l?y.scrollTop():b.length?parseInt(b[0].style.top,10):y.offset().top,h=f.length?o:y.scrollTop(),k=d.stickyHeaders_includeCaption?0:p.children("caption").height()||0,g=h+c+_-k,u=p.height()-(m.height()+(H.height()||0))-k,v=g>n.top&&g<n.top+u?"visible":"hidden",z="visible"===v?i.css.stickyVis:i.css.stickyHide,T=!m.hasClass(z),x={visibility:v};f.length&&(T=!0,x.top=l?g-f.offset().top:f.scrollTop()),(r=w(l))!==parseInt(m.css("left"),10)&&(T=!0,x.left=r),x.top=(x.top||0)+(!l&&b.length?b.height():c+_),T&&m.removeClass(i.css.stickyVis+" "+i.css.stickyHide).addClass(z).css(x),(v!==C||s)&&(S(),C=v)}};if(f.length&&!f.css("position")&&f.css("position","relative"),v.attr("id")&&(v[0].id+=d.stickyHeaders_cloneId),v.find("> thead:gt(0), tr.sticky-false").hide(),v.find("> tbody, > tfoot").remove(),v.find("caption").toggle(d.stickyHeaders_includeCaption),o=z.children().children(),v.css({height:0,wi