tablesorter/js/jquery.tablesorter.widgets.min.js

13 lines
10 KiB
JavaScript
Raw Normal View History

2012-06-21 06:10:02 +00:00
/*! tableSorter 2.3 widgets - updated 6/21/2012 */
;(function(b){
2012-06-21 06:10:02 +00:00
b.tablesorter.storage=function(e,a,c){var d,i=!1;d={};var k=e.id||b(".tablesorter").index(b(e)),h=window.location.pathname;try{i=!!localStorage.getItem}catch(f){}b.parseJSON&&(i?d=b.parseJSON(localStorage[a])||{}:(d=document.cookie.split(/[;\s|=]/),e=b.inArray(a,d)+1,d=0!==e?b.parseJSON(d[e])||{}:{}));if(c&&JSON&&JSON.hasOwnProperty("stringify")){if(!d[h]||!d[h][k])d[h]||(d[h]={});d[h][k]=c;i?localStorage[a]=JSON.stringify(d):(e=new Date,e.setTime(e.getTime()+31536E6),document.cookie= a+"="+JSON.stringify(d).replace(/\"/g,'"')+"; expires="+e.toGMTString()+"; path=/")}else return d&&d.hasOwnProperty(h)&&d[h].hasOwnProperty(k)?d[h][k]:{}};
b.tablesorter.addWidget({id:"uitheme",format:function(e){var a,c,d,i,k,h=b(e),f=e.config,l=f.widgetOptions,g=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"],g=f.widgetUitheme&&f.widgetUitheme.hasOwnProperty("css")?f.widgetUitheme.css||g:l&&l.hasOwnProperty("uitheme")?l.uitheme:g;d=g.join(" ");f.debug&&(a=new Date); h.hasClass("ui-theme")||(h.addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),b.each(f.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(f.headerList,function(a){i=b(this);if(this.sortDisabled)i.find("span.ui-icon").removeClass(d+" ui-icon");else{c=i.hasClass(f.cssAsc)? g[1]:i.hasClass(f.cssDesc)?g[2]:i.hasClass(f.cssHeader)?g[0]:"";k=h.hasClass("hasStickyHeaders")?h.find("tr."+(l.stickyHeaders||"tablesorter-stickyHeader")).find("th").eq(a).add(i):i;k[c===g[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(d).addClass(c)}});f.debug&&b.tablesorter.benchmark("Applying uitheme widget",a)}});
b.tablesorter.addWidget({id:"columns",format:function(e){var a,c,d,i,k,h,f,l,g=e.config,m=b(e).children("tbody:not(."+g.cssInfoBlock+")"),p=g.sortList, r=p.length,q=["primary","secondary","tertiary"],q=g.widgetColumns&&g.widgetColumns.hasOwnProperty("css")?g.widgetColumns.css||q:g.widgetOptions&&g.widgetOptions.hasOwnProperty("columns")?g.widgetOptions.columns||q:q;k=q.length-1;h=q.join(" ");g.debug&&(i=new Date);for(l=0;l<m.length;l++)e=b(m[l]),a=e.addClass("tablesorter-hidden").children("tr"),a.each(function(){d=b(this);if("none"!==this.style.display&&(c=d.children().removeClass(h),p&&p[0]&&(c.eq(p[0][0]).addClass(q[0]),1<r)))for(f=1;f<r;f++)c.eq(p[f][0]).addClass(q[f]|| q[k])}),e.removeClass("tablesorter-hidden");g.debug&&b.tablesorter.benchmark("Applying Columns widget",i)}});
2012-06-21 14:29:52 +00:00
b.tablesorter.addWidget({id:"filter",format:function(e){if(e.config.parsers&&!b(e).hasClass("hasFilters")){var a,c,d,i,k,h,f,l,g,m,p,r,q,z,v,t,D,A,n=e.config,w=b(n.headerList),j=n.widgetOptions,s=j.filter_cssFilter||"tablesorter-filter",u=b(e).addClass("hasFilters"),B=u.children("tbody:not(."+n.cssInfoBlock+")"),C=n.parsers.length,o='<tr class="'+s+'">',E=/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, I=RegExp(n.cssChildRow),x,F,y=function(){n.debug&&(x=new Date);h=u.find("thead").eq(0).children("tr").find("select."+s+", input."+s).map(function(){return b(this).val()||""}).get();k=h.join("");for(d=0;d<B.length;d++){z=b(B[d]);t=z.addClass("tablesorter-hidden").children("tr");i=t.length;for(c=0;c<i;c++)if(""===k)t[c].style.display="";else if(!I.test(t[c].className)){l=!0;q=t.eq(c).nextUntil("tr:not(."+n.cssChildRow+")");m=q.length&&(j&&j.hasOwnProperty("filter_childRows")&&"undefined"!==typeof j.filter_childRows? j.filter_childRows:1)?q.text():"";m=j.filter_ignoreCase?m.toLocaleLowerCase():m;D=t.eq(c).children("td");for(a=0;a<C;a++)if(p=b.trim(D.eq(a).text()),r=j.filter_ignoreCase?p.toLocaleLowerCase():p,""!==h[a]){g=l;f=j.filter_ignoreCase?h[a].toLocaleLowerCase():h[a];if(j.filter_functions&&j.filter_functions[a])!0===j.filter_functions[a]?g=j.filter_ignoreCase?f===r:h[a]===p:"function"===typeof j.filter_functions[a]?g=j.filter_functions[a](p,n.cache[d].normalized[c][a],h[a],a):"function"===typeof j.filter_functions[a][h[a]]&& (g=j.filter_functions[a][h[a]](p,n.cache[d].normalized[c][a],h[a],a));else if(E.test(f)){A=E.exec(f);try{g=RegExp(A[1],A[2]).test(r)}catch(e){g=!1}}else/[\"|\']$/.test(f)&&r===f.replace(/(\"|\')/g,"")?g=!0:/[\?|\*]/.test(f)?g=RegExp(f.replace(/\?/g,"\\S{1}").replace(/\*/g,"\\S*")).test(r):(p=(r+m).indexOf(f),g=!j.filter_startsWith&&0<=p||j.filter_startsWith&&0===p);l=g?l?!0:!1:!1}t[c].style.display=l?"":"none";if(q.length)q[l?"show":"hide"]()}z.removeClass("tablesorter-hidden")}n.debug&&b.tablesorter.benchmark("Completed filter widget search", x);u.trigger("applyWidgets")},G=function(a,e){var f,g=[],a=parseInt(a,10);f='<option value="">'+(w.filter('[data-column="'+a+'"]:last').attr("data-placeholder")||"")+"</option>";for(d=0;d<B.length;d++){i=n.cache[d].row.length;for(c=0;c<i;c++)(m=n.cache[d].row[c][0].cells[a])&&g.push(n.supportsTextContent?m.textContent:b(m).text())}g=g.getUnique(!0);for(d=0;d<g.length;d++)f+='<option value="'+g[d]+'">'+g[d]+"</option>";u.find("thead").find("select."+s+'[data-column="'+a+'"]')[e?"html":"append"](f)}, H=function(b){for(a=0;a<C;a++)m=w.filter('[data-column="'+a+'"]:last'),m.hasClass("filter-select")&&(!m.hasClass("filter-false")&&!(j.filter_functions&&!0===j.filter_functions[a]))&&G(a,b)};n.debug&&(x=new Date);j.filter_ignoreCase=!1!==j.filter_ignoreCase;for(a=0;a<C;a++)v=w.filter('[data-column="'+a+'"]:last'),e=j.filter_functions&&j.filter_functions[a]&&"function"!==typeof j.filter_functions[a]||v.hasClass("filter-select"),o+="<td>",o=e?o+('<select data-column="'+a+'" class="'+s):o+('<input type="search" placeholder="'+ (v.attr("data-placeholder")||"")+'" data-column="'+a+'" class="'+s),o=b.tablesorter.getData?o+("false"===b.tablesorter.getData(v[0],n.headers[a],"filter")?' disabled" disabled':'"'):o+(n.headers[a]&&n.headers[a].hasOwnProperty("filter")&&!1===n.headers[a].filter||v.hasClass("filter-false")?' disabled" disabled':'"'),o+=(e?"></select>":">")+"</td>";u.bind("addRows updateCell update appendCache",function(){H(!0);y()}).find("thead").eq(0).append(o+="</tr>").find("input."+s).bind("keyup search",function(a, b){32>a.which&&8!==a.which||37<=a.which&&40>=a.which||(!1===b?y():(clearTimeout(F),F=setTimeout(function(){y()},j.filter_searchDelay||300)))});if(j.filter_functions)for(a in j.filter_functions)if(m=w.filter('[data-column="'+a+'"]:last'),o="","string"===typeof a&&!0===j.filter_functions[a]&&!m.hasClass("filter-false"))G(a);else if("string"===typeof a&&!m.hasClass("filter-false")){for(c in j.filter_functions[a])"string"===typeof c&&(o+=""===o?"<option>"+(m.attr("data-placeholder")||"")+"</option>": "",o+="<option>"+c+"</option>");u.find("thead").find("selec
2012-06-21 06:10:02 +00:00
b.tablesorter.addWidget({id:"stickyHeaders",format:function(e){if(!b(e).hasClass("hasStickyHeaders")){var a=b(e).addClass("hasStickyHeaders"),c=e.config.widgetOptions,d=b(window),i=b(e).children("thead"),k=i.children("tr:not(.sticky-false)").children(),h=c.stickyHeaders||"tablesorter-stickyHeader", f=k.eq(0),l=a.find("tfoot"),g=i.find("tr.tablesorter-header:not(.sticky-false)").clone().removeClass("tablesorter-header").addClass(h).css({width:i.outerWidth(!0),position:"fixed",left:f.offset().left,margin:0,top:0,visibility:"hidden",zIndex:10}),m=g.children(),p="";a.bind("sortEnd",function(a,d){var c=b(d).find("thead tr"),e=c.filter("."+h).children();c.filter(":not(."+h+")").children().each(function(a){e.eq(a).attr("class",b(this).attr("class"))})}).bind("pagerComplete",function(){d.resize()}); k.each(function(a){var d=b(this);m.eq(a).bind("mouseup",function(a){d.trigger(a,!0)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1}).find(".tablesorter-header-inner").width(d.find(".tablesorter-header-inner").width())});i.prepend(g);d.scroll(function(){var b=f.offset(),c=d.scrollTop(),e=a.height()-(f.height()+(l.height()||0)),c=c>b.top&&c<b.top+e?"visible":"hidden";g.css({left:b.left-d.scrollLeft(),visibility:c});c!==p&&(d.resize(),p=c)}).resize(function(){var a=0; g.css({left:f.offset().left-d.scrollLeft(),width:i.outerWidth()}).each(function(c){b(this).css("top",a);a+=i.find("tr").eq(c).outerHeight()});m.find(".tablesorter-header-inner").each(function(a){b(this).width(k.eq(a).find(".tablesorter-header-inner").width())})})}}});
b.tablesorter.addWidget({id:"resizable",format:function(e){if(!b(e).hasClass("hasResizable")){b(e).addClass("hasResizable");var a,c,d=e.config,i=b(d.headerList).filter(":gt(0)"),k=0,h=null,f=null,l=function(){k=0;h=f=null;b(window).trigger("resize")}; if(c=b.tablesorter.storage?b.tablesorter.storage(e,"tablesorter-resizable"):"")for(a in c)!isNaN(a)&&a<d.headerList.length&&b(d.headerList[a]).width(c[a]);i.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!==k&&h){var b=a.pageX-k;h.width()<-b||f&&f.width()<=b||(f.width(f.width()+ b),k=a.pageX)}}).bind("mouseup",function(){c&&(b.tablesorter.storage&&h)&&(c[f.index()]=f.width(),b.tablesorter.storage(e,"tablesorter-resizable",c));l();return!1}).find(".tablesorter-resizer").bind("mousedown",function(a){h=b(a.target).closest("th");f=h.prev();k=a.pageX;return!1});b(e).find("thead").bind("mouseup mouseleave",function(){l()})}}});
b.tablesorter.addWidget({id:"saveSort",init:function(b,a,c){c.format(b,!0)},format:function(e,a){var c,d,i=e.config;c={sortList:i.sortList};i.debug&&(d= new Date);b(e).hasClass("hasSaveSort")?e.hasInitialized&&b.tablesorter.storage&&(b.tablesorter.storage(e,"tablesorter-savesort",c),i.debug&&b.tablesorter.benchmark("saveSort widget: Saving last sort: "+i.sortList,d)):(b(e).addClass("hasSaveSort"),c="",b.tablesorter.storage&&(c=(c=b.tablesorter.storage(e,"tablesorter-savesort"))&&c.hasOwnProperty("sortList")&&b.isArray(c.sortList)?c.sortList:"",i.debug&&b.tablesorter.benchmark("saveSort: Last sort loaded: "+c,d)),a&&c&&0<c.length?i.sortList=c:e.hasInitialized&& (c&&0<c.length)&&b(e).trigger("sorton",[c]))}})
2012-05-11 17:46:54 +00:00
})(jQuery);
2012-06-21 06:10:02 +00:00
Array.prototype.getUnique=function(b){var e,a=[],c={},d,i=0,k=this.length;for(d=0;d<k;++d)e=this[d],c[e]||(c[e]={},a[i++]=e);return b?a.sort():a};
2012-06-21 14:29:52 +00:00