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

13 lines
17 KiB
JavaScript

/*! tableSorter 2.4 widgets - updated 9/29/2012 */
;(function(a){
a.tablesorter=a.tablesorter||{};
a.tablesorter.themes={bootstrap:{table:"table table-bordered table-striped",header:"bootstrap-header",icons:"",sortNone:"bootstrap-icon-unsorted",sortAsc:"icon-chevron-up",sortDesc:"icon-chevron-down",active:"",hover:"",filterRow:"",even:"",odd:""},jui:{table:"ui-widget ui-widget-content ui-corner-all",header:"ui-widget-header ui-corner-all ui-state-default",icons:"ui-icon",sortNone:"ui-icon-carat-2-n-s",sortAsc:"ui-icon-carat-1-n",sortDesc:"ui-icon-carat-1-s", active:"ui-state-active",hover:"ui-state-hover",filterRow:"",even:"ui-widget-content",odd:"ui-state-default"}};
a.tablesorter.storage=function(d,b,e){var c,h=!1;c={};var f=d.id||a(".tablesorter").index(a(d)),g=window.location.pathname;try{h=!!localStorage.getItem}catch(l){}a.parseJSON&&(h?c=a.parseJSON(localStorage[b])||{}:(c=document.cookie.split(/[;\s|=]/),d=a.inArray(b,c)+1,c=0!==d?a.parseJSON(c[d])||{}:{}));if(e&&JSON&&JSON.hasOwnProperty("stringify")){if(!c[g]||!c[g][f])c[g]||(c[g]={});c[g][f]= e;h?localStorage[b]=JSON.stringify(c):(d=new Date,d.setTime(d.getTime()+31536E6),document.cookie=b+"="+JSON.stringify(c).replace(/\"/g,'"')+"; expires="+d.toGMTString()+"; path=/")}else return c&&c.hasOwnProperty(g)&&c[g].hasOwnProperty(f)?c[g][f]:{}};
a.tablesorter.addWidget({id:"uitheme",format:function(d){var b,e,c,h,f=a(d),g=d.config,l=g.widgetOptions,m="object"===typeof l.uitheme?"jui":l.uitheme||"jui",j="object"===typeof l.uitheme&&!Object.prototype.toString.call(l.uitheme).test("Array")?l.uitheme: a.tablesorter.themes[a.tablesorter.themes.hasOwnProperty(m)?m:"jui"],n=a(g.headerList),q="tr."+(l.stickyHeaders||"tablesorter-stickyHeader"),r=j.sortNone+" "+j.sortDesc+" "+j.sortAsc;g.debug&&(b=new Date);if(!f.hasClass("tablesorter-"+m)||g.theme===m||!d.hasInitialized)""!==j.even&&(l.zebra[0]+=" "+j.even),""!==j.odd&&(l.zebra[1]+=" "+j.odd),f.removeClass(""===g.theme?"":"tablesorter-"+g.theme).addClass("tablesorter-"+m+" "+j.table),g.theme="",n.addClass(j.header).filter(":not(.sorter-false)").hover(function(){a(this).addClass(j.hover)}, function(){a(this).removeClass(j.hover)}),n.find(".tablesorter-wrapper").length||n.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>'),g.cssIcon&&n.find("."+g.cssIcon).addClass(j.icons),f.hasClass("hasFilters")&&n.find(".tablesorter-filter-row").addClass(j.filterRow);a.each(n,function(b){c=a(this);h=g.cssIcon?c.find("."+g.cssIcon):c;this.sortDisabled?(c.removeClass(r),h.removeClass(r+" tablesorter-icon "+j.icons)):(f.hasClass("hasStickyHeaders")&& f.find(q).find("th").eq(b).add(c),e=c.hasClass(g.cssAsc)?j.sortDesc:c.hasClass(g.cssDesc)?j.sortAsc:c.hasClass(g.cssHeader)?j.sortNone:"",c[e===j.sortNone?"removeClass":"addClass"](j.active),h.removeClass(r).addClass(e))});g.debug&&a.tablesorter.benchmark("Applying "+m+" theme",b)},remove:function(d,b,e){var d=a(d),c="object"===typeof e.uitheme?"jui":e.uitheme||"jui",e="object"===typeof e.uitheme?e.uitheme:a.tablesorter.themes[a.tablesorter.themes.hasOwnProperty(c)?c:"jui"],h=d.children("thead").children(), f=e.sortNone+" "+e.sortDesc+" "+e.sortAsc;d.removeClass("tablesorter-"+c+" "+e.table).find(b.cssHeader).removeClass(e.header);h.unbind("mouseenter mouseleave").removeClass(e.hover+" "+f+" "+e.active).find(".tablesorter-filter-row").removeClass(e.filterRow);h.find(".tablesorter-icon").removeClass(e.icons)}});
a.tablesorter.addWidget({id:"columns",format:function(d){var b,e,c,h,f,g,l,m,j,n=a(d),q=d.config,r=q.widgetOptions,p=n.children("tbody:not(."+q.cssInfoBlock+")"),t=q.sortList,v=t.length,k=["primary", "secondary","tertiary"],k=q.widgetColumns&&q.widgetColumns.hasOwnProperty("css")?q.widgetColumns.css||k:r&&r.hasOwnProperty("columns")?r.columns||k:k;g=k.length-1;l=k.join(" ");q.debug&&(f=new Date);for(j=0;j<p.length;j++)b=a.tablesorter.processTbody(d,a(p[j]),!0),e=b.children("tr"),e.each(function(){h=a(this);if("none"!==this.style.display&&(c=h.children().removeClass(l),t&&t[0]&&(c.eq(t[0][0]).addClass(k[0]),1<v)))for(m=1;m<v;m++)c.eq(t[m][0]).addClass(k[m]||k[g])}),a.tablesorter.processTbody(d, b,!1);e=!1!==r.columns_thead?"thead tr":"";!1!==r.columns_tfoot&&(e+=(""===e?"":",")+"tfoot tr");if(e.length&&(h=n.find(e).children().removeClass(l),t&&t[0]&&(h.filter('[data-column="'+t[0][0]+'"]').addClass(k[0]),1<v)))for(m=1;m<v;m++)h.filter('[data-column="'+t[m][0]+'"]').addClass(k[m]||k[g]);q.debug&&a.tablesorter.benchmark("Applying Columns widget",f)},remove:function(d,b){var e,c,h=a(d).children("tbody:not(."+b.cssInfoBlock+")"),f=(b.widgetOptions.columns||["primary","secondary","tertiary"]).join(" "); for(e=0;e<h.length;e++)c=a.tablesorter.processTbody(d,a(h[e]),!0),c.children("tr").each(function(){a(this).children().removeClass(f)}),a.tablesorter.processTbody(d,c,!1)}});
a.tablesorter.addWidget({id:"filter",format:function(d){if(d.config.parsers&&!a(d).hasClass("hasFilters")){var b,e,c,h,f,g,l,m,j,n,q,r,p,t,v,k,x,F="",z=a.tablesorter,s=d.config,B=a(s.headerList),i=s.widgetOptions,y=i.filter_cssFilter||"tablesorter-filter",u=a(d).addClass("hasFilters"),D=u.children("tbody:not(."+s.cssInfoBlock+ ")"),E=s.parsers.length,A=[/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/,RegExp(s.cssChildRow),/undefined|number/,/(^[\"|\'|=])|([\"|\'|=]$)/,/[\"\'=]/g,/[^\w,. \-()]/g,/[<>=]/g],L=B.map(function(b){return z.getData?"parsed"===z.getData(B.filter('[data-column="'+b+'"]:last'),s.headers[b],"filter"):a(this).hasClass("filter-parsed")}).get(),G,H,C=function(b){var c=a.isArray(b),e=u.find("thead").eq(0).children("tr").find("select."+y+", input."+y),d=c?b:e.map(function(){return a(this).val()||""}).get(),f=(d|| []).join("");c&&e.each(function(c,d){a(d).val(b[c]||"")});!0===i.filter_hideFilters&&u.find(".tablesorter-filter-row").trigger(""===f?"mouseleave":"mouseenter");if(!(F===f&&!1!==b))if(u.trigger("filterStart",[d]),s.showProcessing)setTimeout(function(){I(b,d,f);return!1},30);else return I(b,d,f),!1},I=function(g,h,j){var p,n,q,r,x,w,y;s.debug&&(y=new Date);for(c=0;c<D.length;c++){g=a.tablesorter.processTbody(d,a(D[c]),!0);p=g.children("tr");x=p.length;if(""===j)p.show().removeClass("filtered");else for(e= 0;e<x;e++)if(!A[1].test(p[e].className)){r=!0;q=p.eq(e).nextUntil("tr:not(."+s.cssChildRow+")");k=q.length&&(i&&i.hasOwnProperty("filter_childRows")&&"undefined"!==typeof i.filter_childRows?i.filter_childRows:1)?q.text():"";k=i.filter_ignoreCase?k.toLocaleLowerCase():k;n=p.eq(e).children("td");for(b=0;b<E;b++)if(h[b]){l=i.filter_useParsedData||L[b]?s.cache[c].normalized[e][b]:a.trim(n.eq(b).text());m=!A[2].test(typeof l)&&i.filter_ignoreCase?l.toLocaleLowerCase():l;w=r;f=i.filter_ignoreCase?h[b].toLocaleLowerCase(): h[b];if(i.filter_functions&&i.filter_functions[b])!0===i.filter_functions[b]?w=B.filter('[data-column="'+b+'"]:last').hasClass("filter-match")?0<=m.search(f):h[b]===l:"function"===typeof i.filter_functions[b]?w=i.filter_functions[b](l,s.cache[c].normalized[e][b],h[b],b):"function"===typeof i.filter_functions[b][h[b]]&&(w=i.filter_functions[b][h[b]](l,s.cache[c].normalized[e][b],h[b],b));else if(A[0].test(f)){t=A[0].exec(f);try{w=RegExp(t[1],t[2]).test(m)}catch(C){w=!1}}else A[3].test(f)&&m===f.replace(A[4], "")?w=!0:/^\!/.test(f)?(f=f.replace("!",""),v=m.search(a.trim(f)),w=""===f?!0:!(i.filter_startsWith?0===v:0<=v)):/^[<>]=?/.test(f)?(t=a.tablesorter.formatFloat(m.replace(A[5],""),d),isNaN(t)&&(t=m),v=a.tablesorter.formatFloat(f.replace(A[5],"").replace(A[6],""),d),/>/.test(f)&&(w=/>=/.test(f)?t>=v:t>v),/</.test(f)&&(w=/<=/.test(f)?t<=v:t<v)):/[\?|\*]/.test(f)?w=RegExp(f.replace(/\?/g,"\\S{1}").replace(/\*/g,"\\S*")).test(m):(l=(m+k).indexOf(f),w=!i.filter_startsWith&&0<=l||i.filter_startsWith&&0=== l);r=w?r?!0:!1:!1}p[e].style.display=r?"":"none";p.eq(e)[r?"removeClass":"addClass"]("filtered");if(q.length)q[r?"show":"hide"]()}a.tablesorter.processTbody(d,g,!1)}F=j;s.debug&&z.benchmark("Completed filter widget search",y);u.trigger("applyWidgets");u.trigger("filterEnd")},J=function(b,f){var g,p=[],b=parseInt(b,10);g='<option value="">'+(B.filter('[data-column="'+b+'"]:last').attr("data-placeholder")||"")+"</option>";for(c=0;c<D.length;c++){h=s.cache[c].row.length;for(e=0;e<h;e++)i.filter_useParsedData? p.push(""+s.cache[c].normalized[e][b]):(k=s.cache[c].row[e][0].cells[b])&&p.push(s.supportsTextContent?k.textContent:a(k).text())}p=a.grep(p,function(b,c){return a.inArray(b,p)===c});p=z.sortText?p.sort(function(a,c){return z.sortText(d,a,c,b)}):p.sort(!0);for(c=0;c<p.length;c++)g+='<option value="'+p[c]+'">'+p[c]+"</option>";u.find("thead").find("select."+y+'[data-column="'+b+'"]')[f?"html":"append"](g)},K=function(a){for(b=0;b<E;b++)k=B.filter('[data-column="'+b+'"]:last'),k.hasClass("filter-select")&& (!k.hasClass("filter-false")&&!(i.filter_functions&&!0===i.filter_functions[b]))&&(i.filter_functions||(i.filter_functions={}),i.filter_functions[b]=!0,J(b,a))};s.debug&&(G=new Date);i.filter_ignoreCase=!1!==i.filter_ignoreCase;i.filter_useParsedData=!0===i.filter_useParsedData;if(!1!==i.filter_columnFilters){k='<tr class="tablesorter-filter-row">';for(b=0;b<E;b++)p=!1,p=B.filter('[data-column="'+b+'"]:last'),g=i.filter_functions&&i.filter_functions[b]&&"function"!==typeof i.filter_functions[b]|| p.hasClass("filter-select"),k+="<td>",k=g?k+('<select data-column="'+b+'" class="'+y):k+('<input type="search" placeholder="'+(p.attr("data-placeholder")||"")+'" data-column="'+b+'" class="'+y),p=z.getData?"false"===z.getData(p[0],s.headers[b],"filter"):s.headers[b]&&s.headers[b].hasOwnProperty("filter")&&!1===s.headers[b].filter||p.hasClass("filter-false"),k+=p?' disabled" disabled':'"',k+=(g?"></select>":">")+"</td>";u.find("thead").eq(0).append(k+="</tr>")}u.bind(["addRows","updateCell","update", "appendCache","search"].join(".tsfilter "),function(a,b){"search"!==a.type&&K(!0);C("search"===a.type?b:"");return!1}).find("input."+y).bind("keyup search",function(a,b){if(!(32>a.which&&8!==a.which||37<=a.which&&40>=a.which)){if("undefined"!==typeof b)return C(b),!1;clearTimeout(H);H=setTimeout(function(){C()},i.filter_searchDelay||300)}});i.filter_reset&&a(i.filter_reset).length&&a(i.filter_reset).bind("click",function(){u.find("."+y).val("");C();return!1});if(i.filter_functions)for(x in i.filter_functions)if(i.filter_functions.hasOwnProperty(x)&& "string"===typeof x)if(k=B.filter('[data-column="'+x+'"]:last'),g="",!0===i.filter_functions[x]&&!k.hasClass("filter-false"))J(x);else if("string"===typeof x&&!k.hasClass("filter-false")){for(n in i.filter_functions[x])"string"===typeof n&&(g+=""===g?'<option value="">'+(k.attr("data-placeholder")||"")+"</option>":"",g+='<option value="'+n+'">'+n+"</option>");u.find("thead").find("select."+y+'[data-column="'+x+'"]').append(g)}K();u.find("select."+y).bind("change search",function(){C()});!0===i.filter_hideFilters&& u.find(".tablesorter-filter-row").addClass("hideme").bind("mouseenter mouseleave",function(b){var c;q=a(this);clearTimeout(j);j=setTimeout(function(){/enter|over/.test(b.type)?q.removeClass("hideme"):a(document.activeElement).closest("tr")[0]!==q[0]&&(c=u.find("."+(i.filter_cssFilter||"tablesorter-filter")).map(function(){return a(this).val()||""}).get().join(""),""===c&&q.addClass("hideme"))},200)}).find("input, select").bind("focus blur",function(b){r=a(this).closest("tr");clearTimeout(j);j=setTimeout(function(){if(""=== u.find("."+(i.filter_cssFilter||"tablesorter-filter")).map(function(){return a(this).val()||""}).get().join(""))r["focus"===b.type?"removeClass":"addClass"]("hideme")},200)});s.showProcessing&&u.bind("filterStart filterEnd",function(b,c){var d=c?u.find("."+s.cssHeader).filter("[data-column]").filter(function(){return""!==c[a(this).data("column")]}):"";z.isProcessing(u[0],"filterStart"===b.type,c?d:"")});s.debug&&z.benchmark("Applying Filter widget",G);u.trigger("filterInit")}},remove:function(d,b, e){var c,h;c=a(d);b=c.children("tbody:not(."+b.cssInfoBlock+")");c.removeClass("hasFilters").unbind(["addRows","updateCell","update","appendCache","search"].join(".tsfilter")).find(".tablesorter-filter-row").remove();for(c=0;c<b.length;c++)h=a.tablesorter.processTbody(d,a(b[c]),!0),h.children().removeClass("filtered").show(),a.tablesorter.processTbody(d,h,!1);e.filterreset&&a(e.filter_reset).unbind("click")}});
a.tablesorter.addWidget({id:"stickyHeaders",format:function(d){if(!a(d).hasClass("hasStickyHeaders")){var b= a(d).addClass("hasStickyHeaders"),e=d.config,c=e.widgetOptions,h=a(window),f=a(d).children("thead:first"),g=f.children("tr:not(.sticky-false)").children(),d=c.stickyHeaders||"tablesorter-stickyHeader",l=g.eq(0),m=b.find("tfoot"),j=f.clone().addClass(d).css({width:f.outerWidth(!0),position:"fixed",margin:0,top:0,visibility:"hidden",zIndex:1}),n=j.find("tr").children(),q="",r=function(){var c=navigator.userAgent,d=0;"collapse"!==b.css("border-collapse")&&!/webkit/i.test(c)&&(d=/msie/i.test(c)?parseInt(f.css("padding-left"), 10):parseInt(b.css("border-spacing"),10));j.css({left:f.offset().left-h.scrollLeft()-d,width:f.outerWidth()});n.each(function(b){b=g.eq(b);a(this).css({width:b.width(),height:b.height()})}).find(".tablesorter-header-inner").each(function(b){b=g.eq(b).find(".tablesorter-header-inner").width();a(this).width(b)})};j.find("tr.sticky-false").remove();n.find(".tablesorter-resizer").remove();b.bind("sortEnd.tsSticky",function(){g.each(function(b){b=n.eq(b);b.attr("class",a(this).attr("class"));e.cssIcon&& b.find("."+e.cssIcon).attr("class",a(this).find("."+e.cssIcon).attr("class"))})}).bind("pagerComplete.tsSticky",function(){r()});g.find("*").andSelf().filter(e.selectorSort).each(function(b){var c=a(this);n.eq(b).bind("mouseup",function(b){c.trigger(b,!0)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1})});f.after(j);h.bind("scroll.tsSticky",function(){var a=l.offset(),c=h.scrollTop(),d=b.height()-(l.height()+(m.height()||0)),a=c>a.top&&c<a.top+d?"visible":"hidden"; j.css({visibility:a});a!==q&&(r(),q=a)}).bind("resize.tsSticky",function(){r()})}},remove:function(d,b,e){d=a(d);e=e.stickyHeaders||"tablesorter-stickyHeader";d.removeClass("hasStickyHeaders").unbind("sortEnd.tsSticky pagerComplete.tsSticky").find("."+e).remove();a(window).unbind("scroll.tsSticky resize.tsSticky")}});
a.tablesorter.addWidget({id:"resizable",format:function(d){if(!a(d).hasClass("hasResizable")){a(d).addClass("hasResizable");var b,e,c,h,f,g=a(d),l=d.config,m=l.widgetOptions,j=0,n=null, q=null,r=function(){j=0;n=q=null;a(window).trigger("resize")};if(c=a.tablesorter.storage&&!1!==m.resizable?a.tablesorter.storage(d,"tablesorter-resizable"):{})for(e in c)!isNaN(e)&&e<l.headerList.length&&a(l.headerList[e]).width(c[e]);g.children("thead:first").find("tr").each(function(){h=a(this).children();a(this).find(".tablesorter-wrapper").length||h.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>');h=h.slice(0,-1);f=f?f.add(h):h});f.each(function(){b= a(this);e=parseInt(b.css("padding-right"),10)+8;b.find(".tablesorter-wrapper").append('<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;height:100%;width:16px;right:-'+e+'px;top:0;z-index:1;"></div>')}).bind("mousemove.tsresize",function(a){if(0!==j&&n){var b=a.pageX-j;n.width(n.width()+b);q.width(q.width()-b);j=a.pageX}}).bind("mouseup.tsresize",function(){a.tablesorter.storage&&n&&(c[n.index()]=n.width(),c[q.index()]=q.width(),!1!==m.resizable&&a.tablesorter.storage(d,"tablesorter-resizable", c));r()}).find(".tablesorter-resizer").bind("mousedown",function(b){n=a(b.target).parents("th:last");q=n.next();j=b.pageX});g.find("thead:first").bind("mouseup.tsresize mouseleave.tsresize",function(){r()}).bind("contextmenu.tsresize",function(){a.tablesorter.resizableReset(d);var b=a.isEmptyObject?a.isEmptyObject(c):c==={};c={};return b})}},remove:function(d){a(d).removeClass("hasResizable").find("thead").unbind("mouseup.tsresize mouseleave.tsresize contextmenu.tsresize").find("tr").children().unbind("mousemove.tsresize mouseup.tsresize").find(".tablesorter-wrapper").each(function(){a(this).find(".tablesorter-resizer").remove(); a(this).replaceWith(a(this).contents())});a.tablesorter.resizableReset(d)}});a.tablesorter.resizableReset=function(d){a(d.config.headerList).width("auto");a.tablesorter.storage(d,"tablesorter-resizable",{})};
a.tablesorter.addWidget({id:"saveSort",init:function(a,b){b.format(a,!0)},format:function(d,b){var e,c,h=d.config;e=!1!==h.widgetOptions.saveSort;var f={sortList:h.sortList};h.debug&&(c=new Date);a(d).hasClass("hasSaveSort")?e&&(d.hasInitialized&&a.tablesorter.storage)&&(a.tablesorter.storage(d, "tablesorter-savesort",f),h.debug&&a.tablesorter.benchmark("saveSort widget: Saving last sort: "+h.sortList,c)):(a(d).addClass("hasSaveSort"),f="",a.tablesorter.storage&&(f=(e=a.tablesorter.storage(d,"tablesorter-savesort"))&&e.hasOwnProperty("sortList")&&a.isArray(e.sortList)?e.sortList:"",h.debug&&a.tablesorter.benchmark('saveSort: Last sort loaded: "'+f+'"',c)),b&&f&&0<f.length?h.sortList=f:d.hasInitialized&&(f&&0<f.length)&&a(d).trigger("sorton",[f]))},remove:function(d){a.tablesorter.storage(d, "tablesorter-savesort","")}})
})(jQuery);