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