tablesorter/js/jquery.tablesorter.widgets.min.js
2012-09-27 14:57:19 -05:00

13 lines
16 KiB
JavaScript

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