mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
c82280e598
These variables were causing memory leaks
2 lines
5.2 KiB
JavaScript
2 lines
5.2 KiB
JavaScript
/*! Widget: stickyHeaders - updated 3/5/2015 (v2.21.0) */
|
|
!function(a,b){"use strict";var c=a.tablesorter=a.tablesorter||{};a.extend(c.css,{sticky:"tablesorter-stickyHeader",stickyVis:"tablesorter-sticky-visible",stickyHide:"tablesorter-sticky-hidden",stickyWrap:"tablesorter-sticky-wrapper"}),c.addHeaderResizeEvent=function(b,c,d){b=a(b)[0];var e,f={timer:250},g=a.extend({},f,d),h=b.config,i=h.widgetOptions,j=function(b){i.resize_flag=!0,e=[],h.$headers.each(function(){var b=a(this),c=b.data("savedSizes")||[0,0],d=this.offsetWidth,f=this.offsetHeight;(d!==c[0]||f!==c[1])&&(b.data("savedSizes",[d,f]),e.push(this))}),e.length&&b!==!1&&h.$table.trigger("resize",[e]),i.resize_flag=!1};return j(!1),clearInterval(i.resize_timer),c?(i.resize_flag=!1,!1):void(i.resize_timer=setInterval(function(){i.resize_flag||j()},g.timer))},c.addWidget({id:"stickyHeaders",priority:60,options:{stickyHeaders:"",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(d,e,f){if(!(e.$table.hasClass("hasStickyHeaders")||a.inArray("filter",e.widgets)>=0&&!e.$table.hasClass("hasFilters"))){var g,h=e.$table,i=a(f.stickyHeaders_attachTo),j=e.namespace+"stickyheaders ",k=a(f.stickyHeaders_yScroll||f.stickyHeaders_attachTo||b),l=a(f.stickyHeaders_xScroll||f.stickyHeaders_attachTo||b),m=h.children("thead:first"),n=m.children("tr").not(".sticky-false").children(),o=h.children("tfoot"),p=isNaN(f.stickyHeaders_offset)?a(f.stickyHeaders_offset):"",q=p.length?p.height()||0:parseInt(f.stickyHeaders_offset,10)||0,r=h.parent().closest("."+c.css.table).hasClass("hasStickyHeaders")?h.parent().closest("table.tablesorter")[0].config.widgetOptions.$sticky.parent():[],s=r.length?r.height():0,t=f.$sticky=h.clone().addClass("containsStickyHeaders "+c.css.sticky+" "+f.stickyHeaders+" "+e.namespace.slice(1)+"_extra_table").wrap('<div class="'+c.css.stickyWrap+'">'),u=t.parent().addClass(c.css.stickyHide).css({position:i.length?"absolute":"fixed",padding:parseInt(t.parent().parent().css("padding-left"),10),top:q+s,left:0,visibility:"hidden",zIndex:f.stickyHeaders_zIndex||2}),v=t.children("thead:first"),w="",x=0,y=function(c,d){c.filter(":visible").each(function(c){var e,f,g=d.filter(":visible").eq(c),h=a(this);"border-box"===h.css("box-sizing")?e=h.outerWidth():"collapse"===g.css("border-collapse")?b.getComputedStyle?e=parseFloat(b.getComputedStyle(this,null).width):(f=parseFloat(h.css("border-width")),e=h.outerWidth()-parseFloat(h.css("padding-left"))-parseFloat(h.css("padding-right"))-f):e=h.width(),g.css({"min-width":e,"max-width":e})})},z=function(){q=p.length?p.height()||0:parseInt(f.stickyHeaders_offset,10)||0,x=0,u.css({left:i.length?parseInt(i.css("padding-left"),10)||0:h.offset().left-parseInt(h.css("margin-left"),10)-l.scrollLeft()-x,width:h.outerWidth()}),y(h,t),y(n,g)};i.length&&!i.css("position")&&i.css("position","relative"),t.attr("id")&&(t[0].id+=f.stickyHeaders_cloneId),t.find("thead:gt(0), tr.sticky-false").hide(),t.find("tbody, tfoot").remove(),t.find("caption").toggle(f.stickyHeaders_includeCaption),g=v.children().children(),t.css({height:0,width:0,margin:0}),g.find("."+c.css.resizer).remove(),h.addClass("hasStickyHeaders").bind("pagerComplete"+j,function(){z()}),c.bindEvents(d,v.children().children("."+c.css.header)),h.after(u),e.onRenderHeader&&v.children("tr").children().each(function(b){e.onRenderHeader.apply(a(this),[b,e,t])}),l.add(k).unbind("scroll resize ".split(" ").join(j).replace(/\s+/g," ")).bind("scroll resize ".split(" ").join(j),function(b){if(h.is(":visible")){s=r.length?r.offset().top-k.scrollTop()+r.height():0;var d=h.offset(),e=a.isWindow(k[0]),f=a.isWindow(l[0]),g=(i.length?e?k.scrollTop():k.offset().top:k.scrollTop())+q+s,j=h.height()-(u.height()+(o.height()||0)),m=g>d.top&&g<d.top+j?"visible":"hidden",n={visibility:m};i.length&&(n.top=e?g-i.offset().top:i.scrollTop()),f&&(n.left=h.offset().left-parseInt(h.css("margin-left"),10)-l.scrollLeft()-x),r.length&&(n.top=(n.top||0)+q+s),u.removeClass(c.css.stickyVis+" "+c.css.stickyHide).addClass("visible"===m?c.css.stickyVis:c.css.stickyHide).css(n),(m!==w||"resize"===b.type)&&(z(),w=m)}}),f.stickyHeaders_addResizeEvent&&c.addHeaderResizeEvent(d),h.hasClass("hasFilters")&&f.filter_columnFilters&&(h.bind("filterEnd"+j,function(){var d=a(document.activeElement).closest("td"),g=d.parent().children().index(d);u.hasClass(c.css.stickyVis)&&f.stickyHeaders_filteredToTop&&(b.scrollTo(0,h.position().top),g>=0&&e.$filters&&e.$filters.eq(g).find("a, select, input").filter(":visible").focus())}),c.filter.bindSearch(h,g.find("."+c.css.filter)),f.filter_hideFilters&&c.filter.hideFilters(t,e)),h.trigger("stickyHeadersInit")}},remove:function(d,e,f){var g=e.namespace+"stickyheaders ";e.$table.removeClass("hasStickyHeaders").unbind("pagerComplete filterEnd ".split(" ").join(g).replace(/\s+/g," ")).next("."+c.css.stickyWrap).remove(),f.$sticky&&f.$sticky.length&&f.$sticky.remove(),a(b).add(f.stickyHeaders_xScroll).add(f.stickyHeaders_yScroll).add(f.stickyHeaders_attachTo).unbind("scroll resize ".split(" ").join(g).replace(/\s+/g," ")),c.addHeaderResizeEvent(d,!1)}})}(jQuery,window); |