tablesorter/dist/js/widgets/widget-stickyHeaders.min.js
Rob Garrison b6647faba5 2.29.0
2017-09-27 21:09:50 -05:00

2 lines
5.6 KiB
JavaScript

/*! Widget: stickyHeaders - updated 9/27/2017 (v2.29.0) */
!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,c=d.widgetOptions,l=function(e){var s,t,i,r,a,l,n=d.$headers.length;for(c.resize_flag=!0,t=[],s=0;s<n;s++)r=(i=d.$headers.eq(s)).data("savedSizes")||[0,0],a=i[0].offsetWidth,l=i[0].offsetHeight,a===r[0]&&l===r[1]||(i.data("savedSizes",[a,l]),t.push(i[0]));t.length&&!1!==e&&d.$table.triggerHandler("resize",[t]),c.resize_flag=!1};if(clearInterval(c.resize_timer),t)return c.resize_flag=!1,!1;l(!1),c.resize_timer=setInterval(function(){c.resize_flag||l()},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 c,l,n,o,f=a.$table,p=e(d.stickyHeaders_attachTo),h=a.namespace+"stickyheaders ",y=e(d.stickyHeaders_yScroll||d.stickyHeaders_attachTo||s),k=e(d.stickyHeaders_xScroll||d.stickyHeaders_attachTo||s),g=f.children("thead:first").children("tr").not(".sticky-false").children(),H=f.children("tfoot"),u=t(a,d),b=f.parent().closest("."+i.css.table).hasClass("hasStickyHeaders")?f.parent().closest("table.tablesorter")[0].config.widgetOptions.$sticky.parent():[],_=b.length?b.height():0,v=d.$sticky=f.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:p.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,c,l=e.filter(":visible"),n=l.length;for(i=0;i<n;i++)d=t.filter(":visible").eq(i),"border-box"===(c=l.eq(i)).css("box-sizing")?r=c.outerWidth():"collapse"===d.css("border-collapse")?s.getComputedStyle?r=parseFloat(s.getComputedStyle(c[0],null).width):(a=parseFloat(c.css("border-width")),r=c.outerWidth()-parseFloat(c.css("padding-left"))-parseFloat(c.css("padding-right"))-a):r=c.width(),d.css({width:r,"min-width":r,"max-width":r})},w=function(){return p.length?parseInt(p.css("padding-left"),10)||0:f.offset().left-parseInt(f.css("margin-left"),10)-e(s).scrollLeft()},S=function(){m.css({left:w(),width:f.outerWidth()}),T(f,v),T(g,o)},x=function(s){if(f.is(":visible")){_=b.length?b.offset().top-y.scrollTop()+b.height():0;var r,c=f.offset(),l=t(a,d),n=e.isWindow(y[0]),o=p.length?n?y.scrollTop():y.offset().top:y.scrollTop(),h=d.stickyHeaders_includeCaption?0:f.children("caption").height()||0,k=o+l+_-h,g=f.height()-(m.height()+(H.height()||0))-h,u=k>c.top&&k<c.top+g?"visible":"hidden",v="visible"===u?i.css.stickyVis:i.css.stickyHide,z=!m.hasClass(v),T={visibility:u};p.length&&(z=!0,T.top=n?k-p.offset().top:p.scrollTop()),(r=w())!==parseInt(m.css("left"),10)&&(z=!0,T.left=r),T.top=(T.top||0)+l+_,z&&m.removeClass(i.css.stickyVis+" "+i.css.stickyHide).addClass(v).css(T),(u!==C||s)&&(S(),C=u)}};if(p.length&&!p.css("position")&&p.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,width:0,margin:0}),o.find("."+i.css.resizer).remove(),f.addClass("hasStickyHeaders").bind("pagerComplete"+h,function(){S()}),i.bindEvents(r,z.children().children("."+i.css.header)),d.stickyHeaders_appendTo?e(d.stickyHeaders_appendTo).append(m):f.after(m),a.onRenderHeader)for(l=(n=z.children("tr").children()).length,c=0;c<l;c++)a.onRenderHeader.apply(n.eq(c),[c,a,v]);k.add(y).unbind("scroll resize ".split(" ").join(h).replace(/\s+/g," ")).bind("scroll resize ".split(" ").join(h),function(e){x("resize"===e.type)}),a.$table.unbind("stickyHeadersUpdate"+h).bind("stickyHeadersUpdate"+h,function(){x(!0)}),d.stickyHeaders_addResizeEvent&&i.addHeaderResizeEvent(r),f.hasClass("hasFilters")&&d.filter_columnFilters&&(f.bind("filterEnd"+h,function(){var t=e(document.activeElement).closest("td"),r=t.parent().children().index(t);m.hasClass(i.css.stickyVis)&&d.stickyHeaders_filteredToTop&&(s.scrollTo(0,f.position().top),r>=0&&a.$filters&&a.$filters.eq(r).find("a, select, input").filter(":visible").focus())}),i.filter.bindSearch(f,o.find("."+i.css.filter)),d.filter_hideFilters&&i.filter.hideFilters(a,v)),d.stickyHeaders_addResizeEvent&&f.bind("resize"+a.namespace+"stickyheaders",function(){S()}),x(!0),f.triggerHandler("stickyHeadersInit")}},remove:function(t,r,a){var d=r.namespace+"stickyheaders ";r.$table.removeClass("hasStickyHeaders").unbind("pagerComplete resize filterEnd stickyHeadersUpdate ".split(" ").join(d).replace(/\s+/g," ")).next("."+i.css.stickyWrap).remove(),a.$sticky&&a.$sticky.length&&a.$sticky.remove(),e(s).add(a.stickyHeaders_xScroll).add(a.stickyHeaders_yScroll).add(a.stickyHeaders_attachTo).unbind("scroll resize ".split(" ").join(d).replace(/\s+/g," ")),i.addHeaderResizeEvent(t,!0)}})}(jQuery,window);