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

17 lines
23 KiB
JavaScript
Raw Normal View History

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