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