mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
18 lines
29 KiB
JavaScript
18 lines
29 KiB
JavaScript
/*! tableSorter 2.16+ widgets - updated 4/30/2014 (v2.16.3) */
|
|
;(function(k){
|
|
var d=k.tablesorter=k.tablesorter||{};
|
|
d.themes={bootstrap:{table:"table table-bordered table-striped",caption:"caption",header:"bootstrap-header",footerRow:"",footerCells:"",icons:"",sortNone:"bootstrap-icon-unsorted",sortAsc:"icon-chevron-up glyphicon glyphicon-chevron-up",sortDesc:"icon-chevron-down glyphicon glyphicon-chevron-down",active:"",hover:"",filterRow:"",even:"",odd:""},jui:{table:"ui-widget ui-widget-content ui-corner-all",caption:"ui-widget-content ui-corner-all",header:"ui-widget-header ui-corner-all ui-state-default", footerRow:"",footerCells:"",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"}};k.extend(d.css,{filterRow:"tablesorter-filter-row",filter:"tablesorter-filter",wrapper:"tablesorter-wrapper",resizer:"tablesorter-resizer",grip:"tablesorter-resizer-grip",sticky:"tablesorter-stickyHeader",stickyVis:"tablesorter-sticky-visible"});
|
|
d.storage=function(b, a,c,e){b=k(b)[0];var f,d,g=!1;f={};d=b.config;var l=k(b);b=e&&e.id||l.attr(e&&e.group||"data-table-group")||b.id||k(".tablesorter").index(l);e=e&&e.url||l.attr(e&&e.page||"data-table-page")||d&&d.fixedUrl||window.location.pathname;if("localStorage"in window)try{window.localStorage.setItem("_tmptest","temp"),g=!0,window.localStorage.removeItem("_tmptest")}catch(n){}k.parseJSON&&(g?f=k.parseJSON(localStorage[a]||"{}"):(d=document.cookie.split(/[;\s|=]/),f=k.inArray(a,d)+1,f=0!==f?k.parseJSON(d[f]|| "{}"):{}));if((c||""===c)&&window.JSON&&JSON.hasOwnProperty("stringify"))f[e]||(f[e]={}),f[e][b]=c,g?localStorage[a]=JSON.stringify(f):(c=new Date,c.setTime(c.getTime()+31536E6),document.cookie=a+"="+JSON.stringify(f).replace(/\"/g,'"')+"; expires="+c.toGMTString()+"; path=/");else return f&&f[e]?f[e][b]:""};
|
|
d.addHeaderResizeEvent=function(b,a,c){var e;c=k.extend({},{timer:250},c);var d=b.config,h=d.widgetOptions,g=function(a){h.resize_flag=!0;e=[];d.$headers.each(function(){var a=k(this),b=a.data("savedSizes")|| [0,0],c=this.offsetWidth,d=this.offsetHeight;if(c!==b[0]||d!==b[1])a.data("savedSizes",[c,d]),e.push(this)});e.length&&!1!==a&&d.$table.trigger("resize",[e]);h.resize_flag=!1};g(!1);clearInterval(h.resize_timer);if(a)return h.resize_flag=!1;h.resize_timer=setInterval(function(){h.resize_flag||g()},c.timer)};
|
|
d.addWidget({id:"uitheme",priority:10,format:function(b,a,c){var e,f,h,g=d.themes;e=a.$table;h=a.$headers;var l=a.theme||"jui",n=g[l]||g.jui,g=n.sortNone+" "+n.sortDesc+" "+n.sortAsc;a.debug&& (f=new Date);e.hasClass("tablesorter-"+l)&&a.theme!==l&&b.hasInitialized||(""!==n.even&&(c.zebra[0]+=" "+n.even),""!==n.odd&&(c.zebra[1]+=" "+n.odd),e.find("caption").addClass(n.caption),b=e.removeClass(""===a.theme?"":"tablesorter-"+a.theme).addClass("tablesorter-"+l+" "+n.table).find("tfoot"),b.length&&b.find("tr").addClass(n.footerRow).children("th, td").addClass(n.footerCells),h.addClass(n.header).not(".sorter-false").bind("mouseenter.tsuitheme mouseleave.tsuitheme",function(a){k(this)["mouseenter"=== a.type?"addClass":"removeClass"](n.hover)}),h.find("."+d.css.wrapper).length||h.wrapInner('<div class="'+d.css.wrapper+'" style="position:relative;height:100%;width:100%"></div>'),a.cssIcon&&h.find("."+d.css.icon).addClass(n.icons),e.hasClass("hasFilters")&&h.find("."+d.css.filterRow).addClass(n.filterRow));for(e=0;e<a.columns;e++)b=a.$headers.add(a.$extraHeaders).filter('[data-column="'+e+'"]'),c=d.css.icon?b.find("."+d.css.icon):b,a.$headers.filter('[data-column="'+e+'"]:last')[0].sortDisabled? (b.removeClass(g),c.removeClass(g+" "+n.icons)):(h=b.hasClass(d.css.sortAsc)?n.sortAsc:b.hasClass(d.css.sortDesc)?n.sortDesc:b.hasClass(d.css.header)?n.sortNone:"",b[h===n.sortNone?"removeClass":"addClass"](n.active),c.removeClass(g).addClass(h));a.debug&&d.benchmark("Applying "+l+" theme",f)},remove:function(b,a,c){b=a.$table;a=a.theme||"jui";c=d.themes[a]||d.themes.jui;var e=b.children("thead").children(),f=c.sortNone+" "+c.sortDesc+" "+c.sortAsc;b.removeClass("tablesorter-"+a+" "+c.table).find(d.css.header).removeClass(c.header); e.unbind("mouseenter.tsuitheme mouseleave.tsuitheme").removeClass(c.hover+" "+f+" "+c.active).find("."+d.css.filterRow).removeClass(c.filterRow);e.find("."+d.css.icon).removeClass(c.icons)}});
|
|
d.addWidget({id:"columns",priority:30,options:{columns:["primary","secondary","tertiary"]},format:function(b,a,c){var e,f,h,g,l,n,p,m,u=a.$table,t=a.$tbodies,s=a.sortList,w=s.length,v=c&&c.columns||["primary","secondary","tertiary"],x=v.length-1;p=v.join(" ");a.debug&&(e=new Date);for(h=0;h<t.length;h++)f=d.processTbody(b, t.eq(h),!0),g=f.children("tr"),g.each(function(){l=k(this);if("none"!==this.style.display&&(n=l.children().removeClass(p),s&&s[0]&&(n.eq(s[0][0]).addClass(v[0]),1<w)))for(m=1;m<w;m++)n.eq(s[m][0]).addClass(v[m]||v[x])}),d.processTbody(b,f,!1);b=!1!==c.columns_thead?["thead tr"]:[];!1!==c.columns_tfoot&&b.push("tfoot tr");if(b.length&&(g=u.find(b.join(",")).children().removeClass(p),w))for(m=0;m<w;m++)g.filter('[data-column="'+s[m][0]+'"]').addClass(v[m]||v[x]);a.debug&&d.benchmark("Applying Columns widget", e)},remove:function(b,a,c){var e=a.$tbodies,f=(c.columns||["primary","secondary","tertiary"]).join(" ");a.$headers.removeClass(f);a.$table.children("tfoot").children("tr").children("th, td").removeClass(f);for(a=0;a<e.length;a++)c=d.processTbody(b,e.eq(a),!0),c.children("tr").each(function(){k(this).children().removeClass(f)}),d.processTbody(b,c,!1)}});
|
|
d.addWidget({id:"filter",priority:50,options:{filter_childRows:!1,filter_columnFilters:!0,filter_cssFilter:"",filter_external:"",filter_filteredRow:"filtered", filter_formatter:null,filter_functions:null,filter_hideEmpty:!0,filter_hideFilters:!1,filter_ignoreCase:!0,filter_liveSearch:!0,filter_onlyAvail:"filter-onlyAvail",filter_placeholder:{search:"",select:""},filter_reset:null,filter_saveFilters:!1,filter_searchDelay:300,filter_selectSource:null,filter_startsWith:!1,filter_useParsedData:!1,filter_serversideFiltering:!1,filter_defaultAttrib:"data-value"},format:function(b,a,c){a.$table.hasClass("hasFilters")||d.filter.init(b,a,c)},remove:function(b,a, c){var e,f=a.$tbodies;a.$table.removeClass("hasFilters").unbind("addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search ".split(" ").join(a.namespace+"filter ")).find("."+d.css.filterRow).remove();for(a=0;a<f.length;a++)e=d.processTbody(b,f.eq(a),!0),e.children().removeClass(c.filter_filteredRow).show(),d.processTbody(b,e,!1);c.filter_reset&&k(document).undelegate(c.filter_reset,"click.tsfilter")}});
|
|
d.filter={regex:{regex:/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/, child:/tablesorter-childRow/,filtered:/filtered/,type:/undefined|number/,exact:/(^[\"|\'|=]+)|([\"|\'|=]+$)/g,nondigit:/[^\w,. \-()]/g,operators:/[<>=]/g},types:{regex:function(b,a,c,e){if(d.filter.regex.regex.test(a)){var f;b=d.filter.regex.regex.exec(a);try{f=RegExp(b[1],b[2]).test(e)}catch(h){f=!1}return f}return null},operators:function(b,a,c,e,f,h,g,l,k){if(/^[<>]=?/.test(a)){var p,m;p=g.config;b=d.formatFloat(a.replace(d.filter.regex.operators,""),g);c=p.parsers[h];l=b;if(k[h]||"numeric"=== c.type)p=c.format(""+a.replace(d.filter.regex.operators,""),g,p.$headers.eq(h),h),b="number"!==typeof b||""===p||isNaN(p)?b:p;p=!k[h]&&"numeric"!==c.type||isNaN(b)||!f?isNaN(e)?d.formatFloat(e.replace(d.filter.regex.nondigit,""),g):d.formatFloat(e,g):f;/>/.test(a)&&(m=/>=/.test(a)?p>=b:p>b);/</.test(a)&&(m=/<=/.test(a)?p<=b:p<b);m||""!==l||(m=!0);return m}return null},exact:function(b,a,c,e,f,h,g,l,n,p){return d.filter.regex.exact.test(a)?(b=a.replace(d.filter.regex.exact,""),p?0<=k.inArray(b,p): b==e):null},notMatch:function(b,a,c,e,d,h,g,l){return/^\!/.test(a)?(a=a.replace("!",""),b=e.search(k.trim(a)),""===a?!0:!(l.filter_startsWith?0===b:0<=b)):null},and:function(b,a,c,e){if(/\s+(AND|&&)\s+/g.test(b)){b=a.split(/(?:\s+(?:and|&&)\s+)/g);a=0<=e.search(k.trim(b[0]));for(c=b.length-1;a&&c;)a=a&&0<=e.search(k.trim(b[c])),c--;return a}return null},range:function(b,a,c,e,f,h,g,k,n){if(/\s+(-|to)\s+/.test(a)){b=g.config;var p=a.split(/(?: - | to )/);c=d.formatFloat(p[0].replace(d.filter.regex.nondigit, ""),g);k=d.formatFloat(p[1].replace(d.filter.regex.nondigit,""),g);if(n[h]||"numeric"===b.parsers[h].type)a=b.parsers[h].format(""+p[0],g,b.$headers.eq(h),h),c=""===a||isNaN(a)?c:a,a=b.parsers[h].format(""+p[1],g,b.$headers.eq(h),h),k=""===a||isNaN(a)?k:a;a=!n[h]&&"numeric"!==b.parsers[h].type||isNaN(c)||isNaN(k)?isNaN(e)?d.formatFloat(e.replace(d.filter.regex.nondigit,""),g):d.formatFloat(e,g):f;c>k&&(e=c,c=k,k=e);return a>=c&&a<=k||""===c||""===k}return null},wild:function(b,a,c,e,d,h,g,l,n,p){return/[\?|\*]/.test(a)|| /\s+OR\s+/i.test(b)?(b=g.config,a=a.replace(/\s+OR\s+/gi,"|"),!b.$headers.filter('[data-column="'+h+'"]:last').hasClass("filter-match")&&/\|/.test(a)&&(a=k.isArray(p)?"("+a+")":"^("+a+")$"),RegExp(a.replace(/\?/g,"\\S{1}").replace(/\*/g,"\\S*")).test(e)):null},fuzzy:function(b,a,c,d){if(/^~/.test(a)){b=0;c=d.length;var f=a.slice(1);for(a=0;a<c;a++)d[a]===f[b]&&(b+=1);return b===f.length?!0:!1}return null}},init:function(b,a,c){var e,f,h,g,l,n;a.debug&&(n=new Date);a.$table.addClass("hasFilters"); d.filter.regex.child=RegExp(a.cssChildRow);d.filter.regex.filtered=RegExp(c.filter_filteredRow);!1!==c.filter_columnFilters&&a.$headers.filter(".filter-false").length!==a.$headers.length&&d.filter.buildRow(b,a,c);a.$table.bind("addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search ".split(" ").join(a.namespace+"filter "),function(e,f){a.$table.find("."+d.css.filterRow).toggle(!(c.filter_hideEmpty&&k.isEmptyObject(a.cache)));/(search|filter)/.test(e.type)||(e.stopPropagation(), d.filter.buildDefault(b,!0));"filterReset"===e.type?d.filter.searching(b,[]):"filterEnd"===e.type?d.filter.buildDefault(b,!0):(f="search"===e.type?f:"updateComplete"===e.type?a.$table.data("lastSearch"):"",/(update|add)/.test(e.type)&&"updateComplete"!==e.type&&(a.lastCombinedFilter=null),d.filter.searching(b,f,!0));return!1});c.filter_reset&&(c.filter_reset instanceof k?c.filter_reset.click(function(){a.$table.trigger("filterReset")}):k(c.filter_reset).length&&k(document).undelegate(c.filter_reset, "click.tsfilter").delegate(c.filter_reset,"click.tsfilter",function(){a.$table.trigger("filterReset")}));if(c.filter_functions)for(g in c.filter_functions)if(c.filter_functions.hasOwnProperty(g)&&"string"===typeof g)if(h=a.$headers.filter('[data-column="'+g+'"]:last'),e="",!0===c.filter_functions[g]&&!h.hasClass("filter-false"))d.filter.buildSelect(b,g);else if("string"===typeof g&&!h.hasClass("filter-false")){for(f in c.filter_functions[g])"string"===typeof f&&(e+=""===e?'<option value="">'+(h.data("placeholder")|| h.attr("data-placeholder")||c.filter_placeholder.select||"")+"</option>":"",e+='<option value="'+f+'">'+f+"</option>");a.$table.find("thead").find("select."+d.css.filter+'[data-column="'+g+'"]').append(e)}d.filter.buildDefault(b,!0);d.filter.bindSearch(b,a.$table.find("."+d.css.filter),!0);c.filter_external&&d.filter.bindSearch(b,c.filter_external);c.filter_hideFilters&&d.filter.hideFilters(b,a);a.showProcessing&&a.$table.bind("filterStart"+a.namespace+"filter filterEnd"+a.namespace+"filter",function(c, e){h=e?a.$table.find("."+d.css.header).filter("[data-column]").filter(function(){return""!==e[k(this).data("column")]}):"";d.isProcessing(b,"filterStart"===c.type,e?h:"")});a.debug&&d.benchmark("Applying Filter widget",n);a.$table.bind("tablesorter-initialized pagerInitialized",function(){l=d.filter.setDefaults(b,a,c)||[];l.length&&d.setFilters(b,l,!0);a.$table.trigger("filterFomatterUpdate");d.filter.checkFilters(b,l)});c.filter_initialized=!0;a.$table.trigger("filterInit")},setDefaults:function(b, a,c){var e,f=d.getFilters(b)||[];c.filter_saveFilters&&d.storage&&(e=d.storage(b,"tablesorter-filters")||[],(b=k.isArray(e))&&""===e.join("")||!b||(f=e));if(""===f.join(""))for(b=0;b<a.columns;b++)f[b]=a.$headers.filter('[data-column="'+b+'"]:last').attr(c.filter_defaultAttrib)||f[b];a.$table.data("lastSearch",f);return f},buildRow:function(b,a,c){var e,f,h,g=a.columns;f='<tr class="'+d.css.filterRow+'">';for(b=0;b<g;b++)f+="<td></td>";a.$filters=k(f+"</tr>").appendTo(a.$table.children("thead").eq(0)).find("td"); for(b=0;b<g;b++)e=a.$headers.filter('[data-column="'+b+'"]:last'),f=c.filter_functions&&c.filter_functions[b]&&"function"!==typeof c.filter_functions[b]||e.hasClass("filter-select"),h=d.getData?"false"===d.getData(e[0],a.headers[b],"filter"):a.headers[b]&&a.headers[b].hasOwnProperty("filter")&&!1===a.headers[b].filter||e.hasClass("filter-false"),f?f=k("<select>").appendTo(a.$filters.eq(b)):(c.filter_formatter&&k.isFunction(c.filter_formatter[b])?((f=c.filter_formatter[b](a.$filters.eq(b),b))&&0=== f.length&&(f=a.$filters.eq(b).children("input")),f&&(0===f.parent().length||f.parent().length&&f.parent()[0]!==a.$filters[b])&&a.$filters.eq(b).append(f)):f=k('<input type="search">').appendTo(a.$filters.eq(b)),f&&f.attr("placeholder",e.data("placeholder")||e.attr("data-placeholder")||c.filter_placeholder.search||"")),f&&(e=(k.isArray(c.filter_cssFilter)?"undefined"!==typeof c.filter_cssFilter[b]?c.filter_cssFilter[b]||"":"":c.filter_cssFilter)||"",f.addClass(d.css.filter+" "+e).attr("data-column", b),h&&(f.attr("placeholder","").addClass("disabled")[0].disabled=!0))},bindSearch:function(b,a,c){b=k(b)[0];a=k(a);if(a.length){var e=b.config,f=e.widgetOptions,h=f.filter_$externalFilters;!0!==c&&(f.filter_$anyMatch=a.filter('[data-column="all"]'),f.filter_$externalFilters=h&&h.length?f.filter_$externalFilters.add(a):a,d.setFilters(b,e.$table.data("lastSearch")||[],!1===c));a.attr("data-lastSearchTime",(new Date).getTime()).unbind(["keyup","search","change",""].join(e.namespace+"filter ")).bind(["keyup", "search","change",""].join(e.namespace+"filter "),function(a){k(this).attr("data-lastSearchTime",(new Date).getTime());if(27===a.which)this.value="";else if("number"===typeof f.filter_liveSearch&&this.value.length<f.filter_liveSearch&&""!==this.value||"keyup"===a.type&&(32>a.which&&8!==a.which&&!0===f.filter_liveSearch&&13!==a.which||37<=a.which&&40>=a.which||13!==a.which&&!1===f.filter_liveSearch))return;d.filter.searching(b,!0,!0)});e.$table.bind("filterReset",function(){a.val("")})}},checkFilters:function(b, a,c){var e=b.config,f=e.widgetOptions,h=k.isArray(a),g=h?a:d.getFilters(b,!0),l=(g||[]).join("");h&&d.setFilters(b,g,!1,!0!==c);f.filter_hideFilters&&e.$table.find("."+d.css.filterRow).trigger(""===l?"mouseleave":"mouseenter");if(e.lastCombinedFilter!==l||!1===a)if(!1===a&&(e.lastCombinedFilter=null),e.$table.trigger("filterStart",[g]),e.showProcessing)setTimeout(function(){d.filter.findRows(b,g,l);return!1},30);else return d.filter.findRows(b,g,l),!1},hideFilters:function(b,a){var c,e,f;k(b).find("."+ d.css.filterRow).addClass("hideme").bind("mouseenter mouseleave",function(b){c=k(this);clearTimeout(f);f=setTimeout(function(){/enter|over/.test(b.type)?c.removeClass("hideme"):k(document.activeElement).closest("tr")[0]!==c[0]&&""===a.lastCombinedFilter&&c.addClass("hideme")},200)}).find("input, select").bind("focus blur",function(b){e=k(this).closest("tr");clearTimeout(f);f=setTimeout(function(){if(""===d.getFilters(a.$table).join(""))e["focus"===b.type?"removeClass":"addClass"]("hideme")},200)})}, findRows:function(b,a,c){if(b.config.lastCombinedFilter!==c){var e,f,h,g,l,n,p,m,u,t,s,w,v,x,z,y,C,A,B,K,D,F,G,H,I,L,q=b.config,r=q.widgetOptions,M=q.columns,J=q.$table.children("tbody"),N=["range","notMatch","operators"],E=q.$headers.map(function(a){return q.parsers&&q.parsers[a]&&q.parsers[a].parsed||d.getData&&"parsed"===d.getData(q.$headers.filter('[data-column="'+a+'"]:last'),q.headers[a],"filter")||k(this).hasClass("filter-parsed")}).get();q.debug&&(K=new Date);for(l=0;l<J.length;l++)if(!J.eq(l).hasClass(q.cssInfoBlock|| d.css.info)){n=d.processTbody(b,J.eq(l),!0);m=q.columns;h=k(k.map(q.cache[l].normalized,function(a){return a[m].$row.get()}));f=h.length;if(""===c||r.filter_serversideFiltering)h.removeClass(r.filter_filteredRow).not("."+q.cssChildRow).show();else{C=!0;x=q.lastSearch||q.$table.data("lastSearch")||[];k.each(a,function(a,b){C=C&&0===(b||"").indexOf(x[a])&&!/(\s+or\s+|\|)/g.test(b||"")&&!/[=\"]/.test(x[a])&&!(""!==b&&r.filter_functions&&!0===r.filter_functions[a]&&!q.$headers.filter('[data-column="'+ a+'"]:last').hasClass("filter-match"))});p=h.not("."+r.filter_filteredRow).length;C&&0===p&&(C=!1);q.debug&&d.log("Searching through "+(C&&p<f?p:"all")+" rows");if(r.filter_$anyMatch&&r.filter_$anyMatch.length||a[q.columns])D=r.filter_$anyMatch&&r.filter_$anyMatch.val()||a[q.columns]||"",q.sortLocaleCompare&&(D=d.replaceAccents(D)),F=D.toLowerCase();for(g=0;g<f;g++)if(u=h[g].className,!(d.filter.regex.child.test(u)||C&&d.filter.regex.filtered.test(u))){B=!0;u=h.eq(g).nextUntil("tr:not(."+q.cssChildRow+ ")");t=u.length&&r.filter_childRows?u.text():"";t=r.filter_ignoreCase?t.toLocaleLowerCase():t;p=h.eq(g).children();D&&(G=p.map(function(a){E[a]?a=q.cache[l].normalized[g][a]:(a=r.filter_ignoreCase?k(this).text().toLowerCase():k(this).text(),q.sortLocaleCompare&&(a=d.replaceAccents(a)));return a}).get(),H=G.join(" "),I=H.toLowerCase(),L=q.cache[l].normalized[g].slice(0,-1).join(" "),A=null,k.each(d.filter.types,function(a,c){if(0>k.inArray(a,N)&&(z=c(D,F,H,I,L,M,b,r,E,G),null!==z))return A=z,!1}), B=null!==A?A:0<=(I+t).indexOf(F));for(m=0;m<M;m++)a[m]&&(e=q.cache[l].normalized[g][m],r.filter_useParsedData||E[m]?s=e:(s=k.trim(p.eq(m).text()),s=q.sortLocaleCompare?d.replaceAccents(s):s),w=!d.filter.regex.type.test(typeof s)&&r.filter_ignoreCase?s.toLocaleLowerCase():s,y=B,a[m]=q.sortLocaleCompare?d.replaceAccents(a[m]):a[m],v=r.filter_ignoreCase?(a[m]||"").toLocaleLowerCase():a[m],r.filter_functions&&r.filter_functions[m]?!0===r.filter_functions[m]?y=q.$headers.filter('[data-column="'+m+'"]:last').hasClass("filter-match")? 0<=w.search(v):a[m]===s:"function"===typeof r.filter_functions[m]?y=r.filter_functions[m](s,e,a[m],m,h.eq(g)):"function"===typeof r.filter_functions[m][a[m]]&&(y=r.filter_functions[m][a[m]](s,e,a[m],m,h.eq(g))):(A=null,k.each(d.filter.types,function(c,d){z=d(a[m],v,s,w,e,m,b,r,E);if(null!==z)return A=z,!1}),null!==A?y=A:(s=(w+t).indexOf(v),y=!r.filter_startsWith&&0<=s||r.filter_startsWith&&0===s)),B=y?B:!1);h.eq(g).toggle(B).toggleClass(r.filter_filteredRow,!B);u.length&&u.toggleClass(r.filter_filteredRow, !B)}}d.processTbody(b,n,!1)}q.lastCombinedFilter=c;q.lastSearch=a;q.$table.data("lastSearch",a);r.filter_saveFilters&&d.storage&&d.storage(b,"tablesorter-filters",a);q.debug&&d.benchmark("Completed filter widget search",K);q.$table.trigger("filterEnd");setTimeout(function(){q.$table.trigger("applyWidgets")},0)}},getOptionSource:function(b,a,c){var e,f=b.config,h=[],g=!1,l=f.widgetOptions.filter_selectSource;k.isFunction(l)?g=l(b,a,c):"object"===k.type(l)&&l.hasOwnProperty(a)&&(g=l[a](b,a,c));!1=== g&&(g=d.filter.getOptions(b,a,c));g=k.grep(g,function(a,b){return k.inArray(a,g)===b});f.$headers.filter('[data-column="'+a+'"]:last').hasClass("filter-select-nosort")||(k.each(g,function(c,e){h.push({t:e,p:f.parsers&&f.parsers[a].format(e,b,[],a)||e})}),e=f.textSorter||"",h.sort(function(c,f){var g=c.p.toString(),h=f.p.toString();return k.isFunction(e)?e(g,h,!0,a,b):"object"===typeof e&&e.hasOwnProperty(a)?e[a](g,h,!0,a,b):d.sortNatural?d.sortNatural(g,h):!0}),g=[],k.each(h,function(a,b){g.push(b.t)})); return g},getOptions:function(b,a,c){var e,d,h,g,l=b.config,n=l.widgetOptions,p=l.$table.children("tbody"),m=[];for(e=0;e<p.length;e++)if(!p.eq(e).hasClass(l.cssInfoBlock))for(g=l.cache[e],d=l.cache[e].normalized.length,b=0;b<d;b++)h=g.row?g.row[b]:g.normalized[b][l.columns].$row[0],c&&h.className.match(n.filter_filteredRow)||(n.filter_useParsedData?m.push(""+g.normalized[b][a]):(h=h.cells[a])&&m.push(k.trim(h.textContent||h.innerText||k(h).text())));return m},buildSelect:function(b,a,c,e){if(b.config.cache&& !k.isEmptyObject(b.config.cache)){a=parseInt(a,10);var f;f=b.config;var h=f.widgetOptions,g=f.$headers.filter('[data-column="'+a+'"]:last'),g='<option value="">'+(g.data("placeholder")||g.attr("data-placeholder")||h.filter_placeholder.select||"")+"</option>",l=d.filter.getOptionSource(b,a,e),n=f.$table.find("thead").find("select."+d.css.filter+'[data-column="'+a+'"]').val();for(b=0;b<l.length;b++)e=l[b].replace(/\"/g,"""),g+=""!==l[b]?'<option value="'+e+'"'+(n===e?' selected="selected"':"")+ ">"+l[b]+"</option>":"";f=(f.$filters?f.$filters:f.$table.children("thead")).find("."+d.css.filter);h.filter_$externalFilters&&(f=f&&f.length?f.add(h.filter_$externalFilters):h.filter_$externalFilters);f.filter('select[data-column="'+a+'"]')[c?"html":"append"](g)}},buildDefault:function(b,a){var c,e,f=b.config,h=f.widgetOptions,g=f.columns;for(c=0;c<g;c++)e=f.$headers.filter('[data-column="'+c+'"]:last'),(e.hasClass("filter-select")||h.filter_functions&&!0===h.filter_functions[c])&&!e.hasClass("filter-false")&& (h.filter_functions||(h.filter_functions={}),h.filter_functions[c]=!0,d.filter.buildSelect(b,c,a,e.hasClass(h.filter_onlyAvail)))},searching:function(b,a,c){if("undefined"===typeof a||!0===a){var e=b.config.widgetOptions;clearTimeout(e.searchTimer);e.searchTimer=setTimeout(function(){d.filter.checkFilters(b,a,c)},e.filter_liveSearch?e.filter_searchDelay:10)}else d.filter.checkFilters(b,a,c)}};
|
|
d.getFilters=function(b,a,c,e){var f,h=!1,g=b?k(b)[0].config:"",l=g?g.widgetOptions:"";if(!0!==a&&l&&!l.filter_columnFilters)return k(b).data("lastSearch"); if(g&&(g.$filters&&(f=g.$filters.find("."+d.css.filter)),l.filter_$externalFilters&&(f=f&&f.length?f.add(l.filter_$externalFilters):l.filter_$externalFilters),f&&f.length))for(h=c||[],b=0;b<g.columns+1;b++)a=f.filter('[data-column="'+(b===g.columns?"all":b)+'"]'),a.length&&(a=a.sort(function(a,b){return k(b).attr("data-lastSearchTime")-k(a).attr("data-lastSearchTime")}),k.isArray(c)?(e?a.slice(1):a).val(c[b]).trigger("change.tsfilter"):(h[b]=a.val()||"",a.slice(1).val(h[b])),b===g.columns&&a.length&& (l.filter_$anyMatch=a));0===h.length&&(h=!1);return h};
|
|
d.setFilters=function(b,a,c,e){var f=b?k(b)[0].config:"";b=d.getFilters(b,!0,a,e);f&&c&&(f.lastCombinedFilter=null,d.filter.searching(f.$table[0],a,e),f.$table.trigger("filterFomatterUpdate"));return!!b};
|
|
d.addWidget({id:"stickyHeaders",priority:60,options:{stickyHeaders:"",stickyHeaders_attachTo:null,stickyHeaders_offset:0,stickyHeaders_filteredToTop:!0,stickyHeaders_cloneId:"-sticky",stickyHeaders_addResizeEvent:!0,stickyHeaders_includeCaption:!0, stickyHeaders_zIndex:2},format:function(b,a,c){if(!(a.$table.hasClass("hasStickyHeaders")||0<=k.inArray("filter",a.widgets)&&!a.$table.hasClass("hasFilters"))){var e=a.$table,f=k(c.stickyHeaders_attachTo),h=e.children("thead:first"),g=f.length?f:k(window),l=h.children("tr").not(".sticky-false").children(),n="."+d.css.headerIn,p=e.find("tfoot"),m=isNaN(c.stickyHeaders_offset)?k(c.stickyHeaders_offset):"",u=f.length?0:m.length?m.height()||0:parseInt(c.stickyHeaders_offset,10)||0,t=c.$sticky=e.clone().addClass("containsStickyHeaders").css({position:f.length? "absolute":"fixed",margin:0,top:u,left:0,visibility:"hidden",zIndex:c.stickyHeaders_zIndex?c.stickyHeaders_zIndex:2}),s=t.children("thead:first").addClass(d.css.sticky+" "+c.stickyHeaders),w,v="",x=0,z="collapse"!==e.css("border-collapse")&&!/(webkit|msie)/i.test(navigator.userAgent),y=function(){u=m.length?m.height()||0:parseInt(c.stickyHeaders_offset,10)||0;x=0;z&&(x=2*parseInt(l.eq(0).css("border-left-width"),10));t.css({left:f.length?(parseInt(f.css("padding-left"),10)||0)+parseInt(a.$table.css("padding-left"), 10)+parseInt(a.$table.css("margin-left"),10)+parseInt(e.css("border-left-width"),10):h.offset().left-g.scrollLeft()-x,width:e.width()});w.filter(":visible").each(function(b){b=l.filter(":visible").eq(b);var c=z&&k(this).attr("data-column")===""+parseInt(a.columns/2,10)?1:0;k(this).css({width:b.width()-x}).find(n).width(b.find(n).width()-c)})};t.attr("id")&&(t[0].id+=c.stickyHeaders_cloneId);t.find("thead:gt(0), tr.sticky-false").hide();t.find("tbody, tfoot").remove();c.stickyHeaders_includeCaption? t.find("caption").css("margin-left","-1px"):t.find("caption").remove();w=s.children().children();t.css({height:0,width:0,padding:0,margin:0,border:0});w.find("."+d.css.resizer).remove();e.addClass("hasStickyHeaders").bind("pagerComplete.tsSticky",function(){y()});d.bindEvents(b,s.children().children(".tablesorter-header"));e.after(t);g.bind("scroll.tsSticky resize.tsSticky",function(a){if(e.is(":visible")){var b=e.offset(),d=c.stickyHeaders_includeCaption?0:e.find("caption").outerHeight(!0),d=(f.length? f.offset().top:g.scrollTop())+u-d,k=e.height()-(t.height()+(p.height()||0)),b=d>b.top&&d<b.top+k?"visible":"hidden",d={visibility:b};f.length?d.top=f.scrollTop():d.left=h.offset().left-g.scrollLeft()-x;t.removeClass("tablesorter-sticky-visible tablesorter-sticky-hidden").addClass("tablesorter-sticky-"+b).css(d);if(b!==v||"resize"===a.type)y(),v=b}});c.stickyHeaders_addResizeEvent&&d.addHeaderResizeEvent(b);e.hasClass("hasFilters")&&(e.bind("filterEnd",function(){var b=k(document.activeElement).closest("td"), b=b.parent().children().index(b);t.hasClass(d.css.stickyVis)&&c.stickyHeaders_filteredToTop&&(window.scrollTo(0,e.position().top),0<=b&&a.$filters&&a.$filters.eq(b).find("a, select, input").filter(":visible").focus())}),d.filter.bindSearch(e,w.find("."+d.css.filter)),c.filter_hideFilters&&d.filter.hideFilters(t,a));e.trigger("stickyHeadersInit")}},remove:function(b,a,c){a.$table.removeClass("hasStickyHeaders").unbind("pagerComplete.tsSticky").find("."+d.css.sticky).remove();c.$sticky&&c.$sticky.length&& c.$sticky.remove();k(".hasStickyHeaders").length||k(window).unbind("scroll.tsSticky resize.tsSticky");d.addHeaderResizeEvent(b,!1)}});
|
|
d.addWidget({id:"resizable",priority:40,options:{resizable:!0,resizable_addLastColumn:!1,resizable_widths:[]},format:function(b,a,c){if(!a.$table.hasClass("hasResizable")){a.$table.addClass("hasResizable");d.resizableReset(b,!0);var e,f,h,g,l={},n=a.$table,p=0,m=null,u=null,t=20>Math.abs(n.parent().width()-n.width()),s=function(){d.storage&&m&&u&&(l={},l[m.index()]= m.width(),l[u.index()]=u.width(),m.width(l[m.index()]),u.width(l[u.index()]),!1!==c.resizable&&d.storage(b,"tablesorter-resizable",a.$headers.map(function(){return k(this).width()}).get()));p=0;m=u=null;k(window).trigger("resize")};if(l=d.storage&&!1!==c.resizable?d.storage(b,"tablesorter-resizable"):{})for(g in l)!isNaN(g)&&g<a.$headers.length&&a.$headers.eq(g).width(l[g]);e=n.children("thead:first").children("tr");e.children().each(function(){var b;b=k(this);g=b.attr("data-column");b="false"=== d.getData(b,a.headers[g],"resizable");e.children().filter('[data-column="'+g+'"]')[b?"addClass":"removeClass"]("resizable-false")});e.each(function(){h=k(this).children().not(".resizable-false");k(this).find("."+d.css.wrapper).length||h.wrapInner('<div class="'+d.css.wrapper+'" style="position:relative;height:100%;width:100%"></div>');c.resizable_addLastColumn||(h=h.slice(0,-1));f=f?f.add(h):h});f.each(function(){var a=k(this),b=parseInt(a.css("padding-right"),10)+10;a.find("."+d.css.wrapper).append('<div class="'+ d.css.resizer+'" style="cursor:w-resize;position:absolute;z-index:1;right:-'+b+'px;top:0;height:100%;width:20px;"></div>')}).bind("mousemove.tsresize",function(a){if(0!==p&&m){var b=a.pageX-p,c=m.width();m.width(c+b);m.width()!==c&&t&&u.width(u.width()-b);p=a.pageX}}).bind("mouseup.tsresize",function(){s()}).find("."+d.css.resizer+",."+d.css.grip).bind("mousedown",function(b){m=k(b.target).closest("th");var c=a.$headers.filter('[data-column="'+m.attr("data-column")+'"]');1<c.length&&(m=m.add(c)); u=b.shiftKey?m.parent().find("th").not(".resizable-false").filter(":last"):m.nextAll(":not(.resizable-false)").eq(0);p=b.pageX});n.find("thead:first").bind("mouseup.tsresize mouseleave.tsresize",function(){s()}).bind("contextmenu.tsresize",function(){d.resizableReset(b);var a=k.isEmptyObject?k.isEmptyObject(l):!0;l={};return a})}},remove:function(b,a){a.$table.removeClass("hasResizable").children("thead").unbind("mouseup.tsresize mouseleave.tsresize contextmenu.tsresize").children("tr").children().unbind("mousemove.tsresize mouseup.tsresize").find("."+ d.css.resizer+",."+d.css.grip).remove();d.resizableReset(b)}});
|
|
d.resizableReset=function(b,a){k(b).each(function(){var c,e=this.config,f=e&&e.widgetOptions;b&&e&&(e.$headers.each(function(a){c=k(this);f.resizable_widths[a]?c.css("width",f.resizable_widths[a]):c.hasClass("resizable-false")||c.css("width","")}),d.storage&&!a&&d.storage(this,"tablesorter-resizable",{}))})};
|
|
d.addWidget({id:"saveSort",priority:20,options:{saveSort:!0},init:function(b,a,c,d){a.format(b,c,d,!0)},format:function(b,a,c,e){var f, h=a.$table;c=!1!==c.saveSort;var g={sortList:a.sortList};a.debug&&(f=new Date);h.hasClass("hasSaveSort")?c&&b.hasInitialized&&d.storage&&(d.storage(b,"tablesorter-savesort",g),a.debug&&d.benchmark("saveSort widget: Saving last sort: "+a.sortList,f)):(h.addClass("hasSaveSort"),g="",d.storage&&(g=(c=d.storage(b,"tablesorter-savesort"))&&c.hasOwnProperty("sortList")&&k.isArray(c.sortList)?c.sortList:"",a.debug&&d.benchmark('saveSort: Last sort loaded: "'+g+'"',f),h.bind("saveSortReset",function(a){a.stopPropagation(); d.storage(b,"tablesorter-savesort","")})),e&&g&&0<g.length?a.sortList=g:b.hasInitialized&&g&&0<g.length&&h.trigger("sorton",[g]))},remove:function(b){d.storage&&d.storage(b,"tablesorter-savesort","")}})
|
|
})(jQuery);
|