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