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

17 lines
21 KiB
JavaScript
Raw Normal View History

/*! tableSorter 2.8+ widgets - updated 5/8/2013 */
2013-04-13 02:15:57 +00:00
;(function(h){
var f=h.tablesorter=h.tablesorter||{};
f.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"}};
f.storage=function(d,c,b){var a,e=!1;a={};var k=d.id||h(".tablesorter").index(h(d)),f=window.location.pathname;try{e=!!localStorage.getItem}catch(l){}h.parseJSON&&(e?a=h.parseJSON(localStorage[c]||"{}"):(a=document.cookie.split(/[;\s|=]/),d=h.inArray(c,a)+1,a=0!==d?h.parseJSON(a[d]||"{}"):{}));if((b||""===b)&&window.JSON&&JSON.hasOwnProperty("stringify"))a[f]|| (a[f]={}),a[f][k]=b,e?localStorage[c]=JSON.stringify(a):(d=new Date,d.setTime(d.getTime()+31536E6),document.cookie=c+"="+JSON.stringify(a).replace(/\"/g,'"')+"; expires="+d.toGMTString()+"; path=/");else return a&&a[f]?a[f][k]:{}};
f.addHeaderResizeEvent=function(d,c,b){b=h.extend({},{timer:250},b);var a=d.config,e=a.widgetOptions,f;clearInterval(e.resize_timer);if(c)return e.resize_flag=!1;a.$headers.each(function(){h.data(this,"savedSizes",[this.offsetWidth,this.offsetHeight])});e.resize_timer=setInterval(function(){e.resize_flag|| (e.resize_flag=!0,f=[],a.$headers.each(function(){var b=h.data(this,"savedSizes"),a=this.offsetWidth,c=this.offsetHeight;if(a!==b[0]||c!==b[1])h.data(this,"savedSizes",[a,c]),f.push(this)}),f.length&&a.$table.trigger("resize",[f]),e.resize_flag=!1)},b.timer)};
f.addWidget({id:"uitheme",priority:10,options:{uitheme:"jui"},format:function(d,c,b){var a,e,k,m,l=f.themes,q=c.$table,s="default"!==c.theme?c.theme:b.uitheme||"jui",g=l[l[s]?s:l[b.uitheme]?b.uitheme:"jui"],r=c.$headers,t="tr."+(b.stickyHeaders|| "tablesorter-stickyHeader"),u=g.sortNone+" "+g.sortDesc+" "+g.sortAsc;c.debug&&(a=new Date);if(!q.hasClass("tablesorter-"+s)||c.theme===s||!d.hasInitialized)""!==g.even&&(b.zebra[0]+=" "+g.even),""!==g.odd&&(b.zebra[1]+=" "+g.odd),l=q.removeClass(""===c.theme?"":"tablesorter-"+c.theme).addClass("tablesorter-"+s+" "+g.table).find("tfoot"),l.length&&l.find("tr").addClass(g.footerRow).children("th, td").addClass(g.footerCells),r.addClass(g.header).filter(":not(.sorter-false)").bind("mouseenter.tsuitheme mouseleave.tsuitheme", function(b){h(this)["mouseenter"===b.type?"addClass":"removeClass"](g.hover)}),r.find(".tablesorter-wrapper").length||r.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>'),c.cssIcon&&r.find("."+c.cssIcon).addClass(g.icons),q.hasClass("hasFilters")&&r.find(".tablesorter-filter-row").addClass(g.filterRow);h.each(r,function(b){k=h(this);m=c.cssIcon?k.find("."+c.cssIcon):k;this.sortDisabled?(k.removeClass(u),m.removeClass(u+" tablesorter-icon "+g.icons)): (l=q.hasClass("hasStickyHeaders")?q.find(t).find("th").eq(b).add(k):k,e=k.hasClass(c.cssAsc)?g.sortAsc:k.hasClass(c.cssDesc)?g.sortDesc:k.hasClass(c.cssHeader)?g.sortNone:"",k[e===g.sortNone?"removeClass":"addClass"](g.active),m.removeClass(u).addClass(e))});c.debug&&f.benchmark("Applying "+s+" theme",a)},remove:function(d,c,b){d=c.$table;var a="object"===typeof b.uitheme?"jui":b.uitheme||"jui";b="object"===typeof b.uitheme?b.uitheme:f.themes[f.themes.hasOwnProperty(a)?a:"jui"];var e=d.children("thead").children(), h=b.sortNone+" "+b.sortDesc+" "+b.sortAsc;d.removeClass("tablesorter-"+a+" "+b.table).find(c.cssHeader).removeClass(b.header);e.unbind("mouseenter.tsuitheme mouseleave.tsuitheme").removeClass(b.hover+" "+h+" "+b.active).find(".tablesorter-filter-row").removeClass(b.filterRow);e.find(".tablesorter-icon").removeClass(b.icons)}});
f.addWidget({id:"columns",priority:30,options:{columns:["primary","secondary","tertiary"]},format:function(d,c,b){var a,e,k,m,l,q,s,g,r,t=c.$table,u=c.$tbodies,j=c.sortList, v=j.length,n=c.widgetColumns&&c.widgetColumns.hasOwnProperty("css")?c.widgetColumns.css||n:b&&b.hasOwnProperty("columns")?b.columns||n:n;q=n.length-1;s=n.join(" ");c.debug&&(l=new Date);for(r=0;r<u.length;r++)a=f.processTbody(d,u.eq(r),!0),e=a.children("tr"),e.each(function(){m=h(this);if("none"!==this.style.display&&(k=m.children().removeClass(s),j&&j[0]&&(k.eq(j[0][0]).addClass(n[0]),1<v)))for(g=1;g<v;g++)k.eq(j[g][0]).addClass(n[g]||n[q])}),f.processTbody(d,a,!1);e=!1!==b.columns_thead?"thead tr": "";!1!==b.columns_tfoot&&(e+=(""===e?"":",")+"tfoot tr");if(e.length&&(m=t.find(e).children().removeClass(s),j&&j[0]&&(m.filter('[data-column="'+j[0][0]+'"]').addClass(n[0]),1<v)))for(g=1;g<v;g++)m.filter('[data-column="'+j[g][0]+'"]').addClass(n[g]||n[q]);c.debug&&f.benchmark("Applying Columns widget",l)},remove:function(d,c,b){var a=c.$tbodies,e=(b.columns||["primary","secondary","tertiary"]).join(" ");c.$headers.removeClass(e);c.$table.children("tfoot").children("tr").children("th, td").removeClass(e); for(c=0;c<a.length;c++)b=f.processTbody(d,a.eq(c),!0),b.children("tr").each(function(){h(this).children().removeClass(e)}),f.processTbody(d,b,!1)}});
f.addWidget({id:"filter",priority:50,options:{filter_childRows:!1,filter_columnFilters:!0,filter_cssFilter:"tablesorter-filter",filter_filteredRow:"filtered",filter_formatter:null,filter_functions:null,filter_hideFilters:!1,filter_ignoreCase:!0,filter_liveSearch:!0,filter_reset:null,filter_searchDelay:300,filter_startsWith:!1,filter_useParsedData:!1, filter_serversideFiltering:!1,filter_regex:{regex:/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/,child:/tablesorter-childRow/,type:/undefined|number/,exact:/(^[\"|\'|=])|([\"|\'|=]$)/g,nondigit:/[^\w,. \-()]/g,operators:/[<>=]/g}},format:function(d,c,b){if(c.parsers&&!c.$table.hasClass("hasFilters")){var a,e,k,m,l,q,s,g,r,t,u,j,v,n,w,p,F,A,D=f.formatFloat,K="",C=c.$headers,E=b.filter_cssFilter,x=c.$table.addClass("hasFilters"),I=x.find("tbody"),J=c.parsers.length,G,L,M,H=function(a){var e=h.isArray(a),g= e?a:f.getFilters(d),p=(g||[]).join("");e&&f.setFilters(x,g);b.filter_hideFilters&&x.find(".tablesorter-filter-row").trigger(""===p?"mouseleave":"mouseenter");if(!(K===p&&!1!==a))if(x.trigger("filterStart",[g]),c.showProcessing)setTimeout(function(){N(a,g,p);return!1},30);else return N(a,g,p),!1},N=function(m,j,q){var r,v,u,t,A,y,F,z,B;c.debug&&(F=new Date);for(k=0;k<I.length;k++)if(!I.eq(k).hasClass(c.cssInfoBlock)){m=f.processTbody(d,I.eq(k),!0);r=m.children("tr");A=r.length;if(""===q||b.filter_serversideFiltering)r.show().removeClass(b.filter_filteredRow); else for(e=0;e<A;e++)if(!b.filter_regex.child.test(r[e].className)){t=!0;u=r.eq(e).nextUntil("tr:not(."+c.cssChildRow+")");p=u.length&&b.filter_childRows?u.text():"";p=b.filter_ignoreCase?p.toLocaleLowerCase():p;v=r.eq(e).children("td");for(a=0;a<J;a++)if(j[a]){s=b.filter_useParsedData||G[a]?c.cache[k].normalized[e][a]:h.trim(v.eq(a).text());g=!b.filter_regex.type.test(typeof s)&&b.filter_ignoreCase?s.toLocaleLowerCase():s;y=t;l=b.filter_ignoreCase?j[a].toLocaleLowerCase():j[a];if(b.filter_functions&& b.filter_functions[a])!0===b.filter_functions[a]?y=C.filter('[data-column="'+a+'"]:last').hasClass("filter-match")?0<=g.search(l):j[a]===s:"function"===typeof b.filter_functions[a]?y=b.filter_functions[a](s,c.cache[k].normalized[e][a],j[a],a):"function"===typeof b.filter_functions[a][j[a]]&&(y=b.filter_functions[a][j[a]](s,c.cache[k].normalized[e][a],j[a],a));else if(b.filter_regex.regex.test(l)){n=b.filter_regex.regex.exec(l);try{y=RegExp(n[1],n[2]).test(g)}catch(E){y=!1}}else if(l.replace(b.filter_regex.exact, "")==g)y=!0;else if(/^\!/.test(l))l=l.replace("!",""),w=g.search(h.trim(l)),y=""===l?!0:!(b.filter_startsWith?0===w:0<=w);else if(/^[<>]=?/.test(l)){w=D(l.replace(b.filter_regex.nondigit,"").replace(b.filter_regex.operators,""),d);if(G[a]||"numeric"===c.parsers[a].type)n=c.parsers[a].format(""+w,d),w=""!==n&&!isNaN(n)?n:w;n=(G[a]||"numeric"===c.parsers[a].type)&&!isNaN(w)?c.cache[k].normalized[e][a]:isNaN(g)?D(g.replace(b.filter_regex.nondigit,""),d):D(g,d);/>/.test(l)&&(y=/>=/.test(l)?n>=w:n>w); /</.test(l)&&(y=/<=/.test(l)?n<=w:n<w);""===w&&(y=!0)}else if(/\s+(AND|&&)\s+/g.test(j[a])){w=l.split(/(?:\s+(?:and|&&)\s+)/g);y=0<=g.search(h.trim(w[0]));for(z=w.length-1;y&&z;)y=y&&0<=g.search(h.trim(w[z])),z--}else if(/\s+(-|to)\s+/.test(l)){w=l.split(/(?: - | to )/);z=D(w[0].replace(b.filter_regex.nondigit,""),d);B=D(w[1].replace(b.filter_regex.nondigit,""),d);if(G[a]||"numeric"===c.parsers[a].type)n=c.parsers[a].format(""+z,d),z=""!==n&&!isNaN(n)?n:z,n=c.parsers[a].format(""+B,d),B=""!==n&&!isNaN(n)? n:B;n=(G[a]||"numeric"===c.parsers[a].type)&&!isNaN(z)&&!isNaN(B)?c.cache[k].normalized[e][a]:isNaN(g)?D(g.replace(b.filter_regex.nondigit,""),d):D(g,d);z>B&&(y=z,z=B,B=y);y=n>=z&&n<=B||""===z||""===B?!0:!1}else/[\?|\*]/.test(l)||/\s+OR\s+/.test(j[a])?y=RegExp(l.replace(/\s+or\s+/gi,"|").replace(/\?/g,"\\S{1}").replace(/\*/g,"\\S*")).test(g):(s=(g+p).indexOf(l),y=!b.filter_startsWith&&0<=s||b.filter_startsWith&&0===s);t=y?t?!0:!1:!1}r[e].style.display=t?"":"none";r.eq(e)[t?"removeClass":"addClass"](b.filter_filteredRow); if(u.length)u[t?"show":"hide"]()}f.processTbody(d,m,!1)}K=q;x.data("lastSearch",j);c.debug&&f.benchmark("Compl
f.getFilters=function(d){return(d=d?h(d)[0].config:{})&&d.$filters?d.$filters.find("."+d.widgetOptions.filter_cssFilter).map(function(c,b){return h(b).val()}).get()||[]:!1};
f.setFilters=function(d,c,b){d=h(d);var a=d.length?d[0].config:{};(a=a&&a.$filters?a.$filters.find("."+a.widgetOptions.filter_cssFilter).each(function(a,b){h(b).val(c[a]||"")})|| !1:!1)&&b&&d.trigger("search");return!!a};
f.addWidget({id:"stickyHeaders",priority:60,options:{stickyHeaders:"tablesorter-stickyHeader",stickyHeaders_offset:0,stickyHeaders_cloneId:"-sticky",stickyHeaders_addResizeEvent:!0},format:function(d,c,b){if(!c.$table.hasClass("hasStickyHeaders")){var a=c.$table,e=h(window),k=a.children("thead:first"),m=k.children("tr:not(.sticky-false)").children(),l=a.find("tfoot"),q=isNaN(b.stickyHeaders_offset)?h(b.stickyHeaders_offset):"",s=q.length?q.height()||0:parseInt(b.stickyHeaders_offset, 10)||0,g=b.$sticky=a.clone().addClass("containsStickyHeaders").css({position:"fixed",margin:0,top:s,visibility:"hidden",zIndex:2}),r=g.children("thead:first").addClass(b.stickyHeaders),t,u="",j=0,v=!1,n=function(){s=q.length?q.height()||0:parseInt(b.stickyHeaders_offset,10)||0;var c=navigator.userAgent;j=0;"collapse"!==a.css("border-collapse")&&!/(webkit|msie)/i.test(c)&&(j=2*parseInt(m.eq(0).css("border-left-width"),10));g.css({left:k.offset().left-e.scrollLeft()-j,width:a.width()});t.filter(":visible").each(function(a){a= m.filter(":visible").eq(a);h(this).css({width:a.width()-j,height:a.height()}).find(".tablesorter-header-inner").width(a.find(".tablesorter-header-inner").width())})};g.attr("id")&&(g[0].id+=b.stickyHeaders_cloneId);g.find("thead:gt(0), tr.sticky-false, tbody, tfoot").remove();t=r.children().children();g.css({height:0,width:0,padding:0,margin:0,border:0});t.find(".tablesorter-resizer").remove();a.addClass("hasStickyHeaders").bind("sortEnd.tsSticky",function(){m.filter(":visible").each(function(a){a= t.filter(":visible").eq(a);a.attr("class",h(this).attr("class")).removeClass(c.cssProcessing);c.cssIcon&&a.find("."+c.cssIcon).attr("class",h(this).find("."+c.cssIcon).attr("class"))})}).bind("pagerComplete.tsSticky",function(){n()});m.find(c.selectorSort).add(c.$headers.filter(c.selectorSort)).each(function(a){var b=h(this);a=r.children("tr.tablesorter-headerRow").children().eq(a).bind("mouseup",function(a){b.trigger(a,!0)});c.cancelSelection&&a.attr("unselectable","on").bind("selectstart",!1).css({"user-select":"none", MozUserSelect:"none"})});a.after(g);e.bind("scroll.tsSticky resize.tsSticky",function(b){if(a.is(":visible")){var c=a.offset(),d=e.scrollTop()+s,f=a.height()-(g.height()+(l.height()||0)),c=d>c.top&&d<c.top+f?"visible":"hidden";g.removeClass("tablesorter-sticky-visible tablesorter-sticky-hidden").addClass("tablesorter-sticky-"+c).css({left:k.offset().left-e.scrollLeft()-j,visibility:c});if(c!==u||"resize"===b.type)n(),u=c}});b.stickyHeaders_addResizeEvent&&f.addHeaderResizeEvent(d);a.bind("filterEnd", function(){v||r.find(".tablesorter-filter-row").children().each(function(a){h(this).find("input, select").val(c.$filters.find("input, select").eq(a).val())})});t.find("input, select").bind("keyup search change",function(a){if(!(32>a.which&&8!==a.which||37<=a.which&&40>=a.which)){v=!0;a=h(this);var d=a.attr("data-column");c.$filters.find("input, select").eq(d).val(a.val()).trigger("search");setTimeout(function(){v=!1},b.filter_searchDelay)}})}},remove:function(d,c,b){c.$table.removeClass("hasStickyHeaders").unbind("sortEnd.tsSticky pagerComplete.tsSticky").find("."+ b.stickyHeaders).remove();b.$sticky&&b.$sticky.remove();h(window).unbind("scroll.tsSticky resize.tsSticky");f.addHeaderResizeEvent(d,!1)}});
f.addWidget({id:"resizable",priority:40,options:{resizable:!0,resizable_addLastColumn:!1},format:function(d,c,b){if(!c.$table.hasClass("hasResizable")){c.$table.addClass("hasResizable");var a,e,k,m,l={},q,s,g,r,t=c.$table,u=0,j=null,v=null,n=20>Math.abs(t.parent().width()-t.width()),w=function(){f.storage&&j&&(l[j.index()]=j.width(),l[v.index()]=v.width(),j.width(l[j.index()]), v.width(l[v.index()]),!1!==b.resizable&&f.storage(d,"tablesorter-resizable",l));u=0;j=v=null;h(window).trigger("resize")};if(l=f.storage&&!1!==b.resizable?f.storage(d,"tablesorter-resizable"):{})for(m in l)!isNaN(m)&&m<c.$headers.length&&c.$headers.eq(m).width(l[m]);a=t.children("thead:first").children("tr");a.children().each(function(){e=h(this);k=e.attr("data-column");m="false"===f.getData(e,c.headers[k],"resizable");a.children().filter('[data-column="'+k+'"]').toggleClass("resizable-false",m)}); a.each(function(){q=h(this).children(":not(.resizable-false)");h(this).find(".tablesorter-wrapper").length||q.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>');b.resizable_addLastColumn||(q=q.slice(0,-1));s=s?s.add(q):q});s.each(function(){a=h(this);m=parseInt(a.css("padding-right"),10)+10;e='<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;z-index:1;right:-'+m+'px;top:0;height:100%;width:20px;"></div>';a.find(".tablesorter-wrapper").append(e)}).bind("mousemove.tsresize", function(a){0!==u&&j&&(g=a.pageX-u,r=j.width(),j.width(r+g),j.width()!==r&&n&&v.width(v.width()-g),u=a.pageX)}).bind("mouseup.tsresize",function(){w()}).find(".tablesorter-resizer,.tablesorter-resizer-grip").bind("mousedown",function(a){j=h(a.target).closest("th");e=c.$headers.filter('[data-column="'+j.attr("data-column")+'"]');1<e.length&&(j=j.add(e));v=a.shiftKey?j.parent().find("th:not(.resizable-false)").filter(":last"):j.nextAll(":not(.resizable-false)").eq(0);u=a.pageX});t.find("thead:first").bind("mouseup.tsresize mouseleave.tsresize", function(){w()}).bind("contextmenu.tsresize",function(){f.resizableReset(d);var a=h.isEmptyObject?h.isEmptyObject(l):l==={};l={};return a})}},remove:function(d,c){c.$table.removeClass("hasResizable").find("thead").unbind("mouseup.tsresize mouseleave.tsresize contextmenu.tsresize").find("tr").children().unbind("mousemove.tsresize mouseup.tsresize").find(".tablesorter-resizer,.tablesorter-resizer-grip").remove();f.resizableReset(d)}});
f.resizableReset=function(d){d.config.$headers.filter(":not(.resizable-false)").css("width", "");f.storage&&f.storage(d,"tablesorter-resizable",{})};
f.addWidget({id:"saveSort",priority:20,options:{saveSort:!0},init:function(d,c,b,a){c.format(d,b,a,!0)},format:function(d,c,b,a){var e,k=c.$table;b=!1!==b.saveSort;var m={sortList:c.sortList};c.debug&&(e=new Date);k.hasClass("hasSaveSort")?b&&(d.hasInitialized&&f.storage)&&(f.storage(d,"tablesorter-savesort",m),c.debug&&f.benchmark("saveSort widget: Saving last sort: "+c.sortList,e)):(k.addClass("hasSaveSort"),m="",f.storage&&(m=(b=f.storage(d, "tablesorter-savesort"))&&b.hasOwnProperty("sortList")&&h.isArray(b.sortList)?b.sortList:"",c.debug&&f.benchmark('saveSort: Last sort loaded: "'+m+'"',e),k.bind("saveSortReset",function(a){a.stopPropagation();f.storage(d,"tablesorter-savesort","")})),a&&m&&0<m.length?c.sortList=m:d.hasInitialized&&(m&&0<m.length)&&k.trigger("sorton",[m]))},remove:function(d){f.storage&&f.storage(d,"tablesorter-savesort","")}})
})(jQuery);