tablesorter/js/jquery.tablesorter.widgets.min.js
2012-03-22 09:58:43 -05:00

10 lines
6.8 KiB
JavaScript

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