tablesorter/js/jquery.tablesorter.widgets.min.js

13 lines
17 KiB
JavaScript
Raw Normal View History

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