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