mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
2 lines
5.6 KiB
JavaScript
2 lines
5.6 KiB
JavaScript
/*! Widget: stickyHeaders - updated 6/2/2017 (v2.28.13) */
|
|
!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"),b=t(a,d),u=f.parent().closest("."+i.css.table).hasClass("hasStickyHeaders")?f.parent().closest("table.tablesorter")[0].config.widgetOptions.$sticky.parent():[],_=u.length?u.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:b+_,left:0,visibility:"hidden",zIndex:d.stickyHeaders_zIndex||2}),z=v.children("thead:first"),C="",w=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})},T=function(){m.css({left:p.length?parseInt(p.css("padding-left"),10)||0:f.offset().left-parseInt(f.css("margin-left"),10)-k.scrollLeft(),width:f.outerWidth()}),w(f,v),w(g,o)},S=function(s){if(f.is(":visible")){_=u.length?u.offset().top-y.scrollTop()+u.height():0;var r=f.offset(),c=t(a,d),l=e.isWindow(y[0]),n=e.isWindow(k[0]),o=p.length?l?y.scrollTop():y.offset().top:y.scrollTop(),h=d.stickyHeaders_includeCaption?0:f.children("caption").height()||0,g=o+c+_-h,b=f.height()-(m.height()+(H.height()||0))-h,v=g>r.top&&g<r.top+b?"visible":"hidden",z={visibility:v};p.length&&(z.top=l?g-p.offset().top:p.scrollTop()),n&&(z.left=f.offset().left-parseInt(f.css("margin-left"),10)-k.scrollLeft()),z.top=(z.top||0)+c+_,m.removeClass(i.css.stickyVis+" "+i.css.stickyHide).addClass("visible"===v?i.css.stickyVis:i.css.stickyHide).css(z),(v!==C||s)&&(T(),C=v)}};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(){T()}),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){S("resize"===e.type)}),a.$table.unbind("stickyHeadersUpdate"+h).bind("stickyHeadersUpdate"+h,function(){S(!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(){T()}),S(!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); |