tablesorter/js/jquery.tablesorter.widgets.min.js
2012-05-03 23:38:10 -05:00

10 lines
7.2 KiB
JavaScript

/*! tableSorter 2.1 widgets - updated 5/3/2012 */
;(function(b){
b.tablesorter.storage=function(a,f,d){var c,g=!1;c={};var i=a.id||b(".tablesorter").index(b(a)),e=window.location.pathname;try{g=!!localStorage.getItem}catch(h){}b.parseJSON&&(g?c=b.parseJSON(localStorage[f])||{}:(c=document.cookie.split(/[;\s|=]/),a=b.inArray(f,c)+1,c=0!==a?b.parseJSON(c[a])||{}:{}));if(d&&JSON&&JSON.hasOwnProperty("stringify")){if(!c[e]||!c[e][i])c[e]||(c[e]={});c[e][i]=d;g?localStorage[f]=JSON.stringify(c):(a=new Date,a.setTime(a.getTime()+31536E6),document.cookie= f+"="+JSON.stringify(c).replace(/\"/g,'"')+"; expires="+a.toGMTString()+"; path=/")}else return c&&c.hasOwnProperty(e)&&c[e].hasOwnProperty(i)?c[e][i]:{}};
b.tablesorter.addWidget({id:"uitheme",format:function(a){var f,d,c,g,i,e=b(a),h=a.config,j=h.widgetOptions,k=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"],k=h.widgetUitheme&&h.widgetUitheme.hasOwnProperty("css")?h.widgetUitheme.css||k:j&&j.hasOwnProperty("uitheme")?j.uitheme:k;c=k.join(" ");h.debug&&(f=new Date); e.hasClass("ui-theme")||(e.addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),b.each(h.headerList,function(){b(this).addClass("ui-widget-header ui-corner-all ui-state-default").append('<span class="ui-icon"/>').wrapInner('<div class="tablesorter-inner"/>').hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")})}));b.each(h.headerList,function(a){g=b(this);if(this.sortDisabled)g.find("span.ui-icon").removeClass(c+" ui-icon");else{d=g.hasClass(h.cssAsc)? k[1]:g.hasClass(h.cssDesc)?k[2]:g.hasClass(h.cssHeader)?k[0]:"";i=e.hasClass("hasStickyHeaders")?e.find("tr."+(j.stickyHeaders||"tablesorter-stickyHeader")).find("th").eq(a).add(g):g;i[d===k[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(c).addClass(d)}});h.debug&&b.tablesorter.benchmark("Applying uitheme widget",f)}});
b.tablesorter.addWidget({id:"columns",format:function(a){var f,d,c,g,i,e=a.config,h=a.tBodies,j=e.sortList,k=j.length,l=["primary","secondary","tertiary"], l=e.widgetColumns&&e.widgetColumns.hasOwnProperty("css")?e.widgetColumns.css||l:e.widgetOptions&&e.widgetOptions.hasOwnProperty("columns")?e.widgetOptions.columns||l:l;c=l.length-1;g=l.join(" ");e.debug&&(d=new Date);if(j&&j[0])for(i=0;i<h.length;i++)a=b(h[i]).filter(":not("+e.cssInfoBlock+")").find("tr:visible:not(."+e.cssInfoBlock+")"),a.each(function(a){f=b(this).children().removeClass(g);f.eq(j[0][0]).addClass(l[0]);if(1<k)for(a=1;a<k;a++)f.eq(j[a][0]).addClass(l[a]||l[c])});else b("td",a).removeClass(g); e.debug&&b.tablesorter.benchmark("Applying Columns widget",d)}});
b.tablesorter.addWidget({id:"filter",format:function(a){if(!b(a).hasClass("hasFilters")){var f,d,c,g,i,e,h,j=a.config,k=j.widgetOptions,l=k.filter_cssFilter||"tablesorter-filter",m=b(a).addClass("hasFilters"),n=m.find("tbody tr:first td").length,a='<tr class="'+l+'">',o;j.debug&&(o=new Date);for(f=0;f<n;f++)a+='<td><input type="search" data-col="'+f+'" class="'+l,a+=j.headers[f]&&j.headers[f].hasOwnProperty("filter")&&!1===j.headers[f].filter|| b(j.headerList[f]).is(".filter-false")?' disabled" disabled':'"',a+="></td>";m.find("thead").append(a+="</tr>").find("input."+l).bind("keyup search",function(){d=m.find("thead").find("input."+l).map(function(){return(b(this).val()||"").toLowerCase()}).get();""===d.join("")?m.find("tr").show():m.find("tbody").find("tr:not(."+j.cssChildRow+"):not(."+j.cssInfoBlock+")").each(function(){c=!0;e=b(this).nextUntil("tr:not(."+j.cssChildRow+")");g=e.length&&(k&&k.hasOwnProperty("filter_childRows")&&"undefined"!== typeof k.filter_childRows?k.filter_childRows:1)?e.text():"";h=b(this).find("td");for(f=0;f<n;f++)i=b.trim(h.eq(f).text()+g).toLowerCase().indexOf(d[f]),""!==d[f]&&(!k.filter_startsWith&&0<=i||k.filter_startsWith&&0===i)?c=c?!0:!1:""!==d[f]&&(c=!1);b(this)[c?"show":"hide"]();if(e.length)e[c?"show":"hide"]()});m.trigger("applyWidgets")});j.debug&&b.tablesorter.benchmark("Applying Filter widget",o)}}});
b.tablesorter.addWidget({id:"stickyHeaders",format:function(a){if(!b(a).hasClass("hasStickyHeaders")){var f= b(a).addClass("hasStickyHeaders"),d=a.config.widgetOptions,c=b(window),g=b(a).find("thead"),i=g.find("tr:not(.sticky-false)").children(),e=d.stickyHeaders||"tablesorter-stickyHeader",h=i.eq(0),j=f.find("tfoot"),k=g.find("tr.tablesorter-header:not(.sticky-false)").clone().removeClass("tablesorter-header").addClass(e).css({width:g.outerWidth(!0),position:"fixed",left:h.offset().left,margin:0,top:0,visibility:"hidden",zIndex:10}),l=k.children(),m="";f.bind("sortEnd",function(a,c){var d=b(c).find("thead tr"), f=d.filter("."+e).children();d.filter(":not(."+e+")").children().each(function(a){f.eq(a).attr("class",b(this).attr("class"))})}).bind("pagerComplete",function(){c.resize()});i.each(function(a){var c=b(this);l.eq(a).bind("click",function(a){c.trigger(a)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1}).find(".tablesorter-header-inner").width(c.find(".tablesorter-header-inner").width())});g.prepend(k);c.scroll(function(){var a=h.offset(),b=c.scrollTop(),d=f.height()- (h.height()+(j.height()||0)),b=b>a.top&&b<a.top+d?"visible":"hidden";k.css({left:a.left-c.scrollLeft(),visibility:b});b!==m&&(c.resize(),m=b)}).resize(function(){var a=0;k.css({left:h.offset().left-c.scrollLeft(),width:g.outerWidth()}).each(function(c){b(this).css("top",a);a+=g.find("tr").eq(c).outerHeight()});l.find(".tablesorter-header-inner").each(function(a){b(this).width(i.eq(a).find(".tablesorter-header-inner").width())})})}}});
b.tablesorter.addWidget({id:"resizable",format:function(a){if(!b(a).hasClass("hasResizable")){b(a).addClass("hasResizable"); var f,d,c=a.config,g=b(c.headerList).filter(":gt(0)"),i=0,e=null,h=null,j=function(){i=0;e=h=null;b(window).trigger("resize")};if(d=b.tablesorter.storage?b.tablesorter.storage(a,"tablesorter-resizable"):"")for(f in d)!isNaN(f)&&f<c.headerList.length&&b(c.headerList[f]).width(d[f]);g.each(function(){b(this).append('<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>')}).bind("mousemove", function(a){if(0!==i&&e){var b=a.pageX-i;e.width()<-b||h&&h.width()<=b||(h.width(h.width()+b),i=a.pageX)}}).bind("mouseup",function(){d&&(b.tablesorter.storage&&e)&&(d[h.index()]=h.width(),b.tablesorter.storage(a,"tablesorter-resizable",d));j();return!1}).find(".tablesorter-resizer").bind("mousedown",function(a){e=b(a.target).closest("th");h=e.prev();i=a.pageX});b(a).find("thead").bind("mouseup mouseleave",function(){j()})}}});
b.tablesorter.addWidget({id:"saveSort",init:function(a,b,d){d.format(a, !0)},format:function(a,f){var d,c,g=a.config;d={sortList:g.sortList};g.debug&&(c=new Date);b(a).hasClass("hasSaveSort")?a.hasInitialized&&b.tablesorter.storage&&(b.tablesorter.storage(a,"tablesorter-savesort",d),g.debug&&b.tablesorter.benchmark("saveSort widget: Saving last sort: "+g.sortList,c)):(b(a).addClass("hasSaveSort"),d="",b.tablesorter.storage&&(d=(d=b.tablesorter.storage(a,"tablesorter-savesort"))&&d.hasOwnProperty("sortList")&&b.isArray(d.sortList)?d.sortList:"",g.debug&&b.tablesorter.benchmark("saveSort: Last sort loaded: "+ d,c)),f&&d&&0<d.length?g.sortList=d:a.hasInitialized&&(d&&0<d.length)&&b(a).trigger("sorton",[d]))}})
})(jQuery);