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

18 lines
26 KiB
JavaScript
Raw Normal View History

2013-11-23 02:01:48 +00:00
/*! tableSorter 2.8+ widgets - updated 11/22/2013 (v2.14.1) */
2013-11-09 20:30:58 +00:00
;(function(l){
var e=l.tablesorter=l.tablesorter||{};
e.themes={bootstrap:{table:"table table-bordered table-striped",caption:"caption",header:"bootstrap-header",footerRow:"",footerCells:"",icons:"",sortNone:"bootstrap-icon-unsorted",sortAsc:"icon-chevron-up glyphicon glyphicon-chevron-up",sortDesc:"icon-chevron-down glyphicon glyphicon-chevron-down",active:"",hover:"",filterRow:"",even:"",odd:""},jui:{table:"ui-widget ui-widget-content ui-corner-all",caption:"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"}};
2013-11-20 04:21:16 +00:00
e.storage=function(b,a,c,f){b=l(b)[0];var d,g,e=!1;d={};g=b.config;var p=l(b);b=f&&f.id||p.attr(f&&f.group||"data-table-group")||b.id||l(".tablesorter").index(p);f=f&&f.url||p.attr(f&&f.page||"data-table-page")||g&&g.fixedUrl||window.location.pathname;if("localStorage"in window)try{window.localStorage.setItem("_tmptest","temp"),e=!0,window.localStorage.removeItem("_tmptest")}catch(q){}l.parseJSON&&(e?d=l.parseJSON(localStorage[a]||"{}"):(g=document.cookie.split(/[;\s|=]/),d=l.inArray(a,g)+1,d=0!==d?l.parseJSON(g[d]||"{}"):{}));if((c||""===c)&&window.JSON&&JSON.hasOwnProperty("stringify"))d[f]||(d[f]={}),d[f][b]=c,e?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[f]?d[f][b]:{}};
e.addHeaderResizeEvent=function(b,a,c){var f;c=l.extend({},{timer:250},c);var d=b.config,e=d.widgetOptions,h=function(a){e.resize_flag=!0;f=[];d.$headers.each(function(){var a=l(this),b=a.data("savedSizes")||[0,0],c=this.offsetWidth,d=this.offsetHeight;if(c!==b[0]||d!==b[1])a.data("savedSizes",[c,d]),f.push(this)});f.length&&!1!==a&&d.$table.trigger("resize",[f]);e.resize_flag=!1};h(!1);clearInterval(e.resize_timer);if(a)return e.resize_flag=!1;e.resize_timer= setInterval(function(){e.resize_flag||h()},c.timer)};
e.addWidget({id:"uitheme",priority:10,format:function(b,a,c){var f,d,g,h,p=e.themes,q=a.$table,m=a.$headers,k=a.theme||"jui",n=p[k]||p.jui,u=n.sortNone+" "+n.sortDesc+" "+n.sortAsc;a.debug&&(f=new Date);q.hasClass("tablesorter-"+k)&&a.theme!==k&&b.hasInitialized||(""!==n.even&&(c.zebra[0]+=" "+n.even),""!==n.odd&&(c.zebra[1]+=" "+n.odd),q.find("caption").addClass(n.caption),b=q.removeClass(""===a.theme?"":"tablesorter-"+a.theme).addClass("tablesorter-"+ k+" "+n.table).find("tfoot"),b.length&&b.find("tr").addClass(n.footerRow).children("th, td").addClass(n.footerCells),m.addClass(n.header).not(".sorter-false").bind("mouseenter.tsuitheme mouseleave.tsuitheme",function(a){l(this)["mouseenter"===a.type?"addClass":"removeClass"](n.hover)}),m.find(".tablesorter-wrapper").length||m.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>'),a.cssIcon&&m.find("."+e.css.icon).addClass(n.icons),q.hasClass("hasFilters")&& m.find(".tablesorter-filter-row").addClass(n.filterRow));l.each(m,function(){g=l(this);h=e.css.icon?g.find("."+e.css.icon):g;this.sortDisabled?(g.removeClass(u),h.removeClass(u+" tablesorter-icon "+n.icons)):(d=g.hasClass(e.css.sortAsc)?n.sortAsc:g.hasClass(e.css.sortDesc)?n.sortDesc:g.hasClass(e.css.header)?n.sortNone:"",g[d===n.sortNone?"removeClass":"addClass"](n.active),h.removeClass(u).addClass(d))});a.debug&&e.benchmark("Applying "+k+" theme",f)},remove:function(b,a,c){b=a.$table;a=a.theme|| "jui";c=e.themes[a]||e.themes.jui;var f=b.children("thead").children(),d=c.sortNone+" "+c.sortDesc+" "+c.sortAsc;b.removeClass("tablesorter-"+a+" "+c.table).find(e.css.header).removeClass(c.header);f.unbind("mouseenter.tsuitheme mouseleave.tsuitheme").removeClass(c.hover+" "+d+" "+c.active).find(".tablesorter-filter-row").removeClass(c.filterRow);f.find(".tablesorter-icon").removeClass(c.icons)}});
2013-11-23 02:01:48 +00:00
e.addWidget({id:"columns",priority:30,options:{columns:["primary","secondary","tertiary"]},format:function(b, a,c){var f,d,g,h,p,q,m,k,n=a.$table,u=a.$tbodies,r=a.sortList,w=r.length,v=c&&c.columns||["primary","secondary","tertiary"],y=v.length-1;m=v.join(" ");a.debug&&(f=new Date);for(g=0;g<u.length;g++)d=e.processTbody(b,u.eq(g),!0),h=d.children("tr"),h.each(function(){p=l(this);if("none"!==this.style.display&&(q=p.children().removeClass(m),r&&r[0]&&(q.eq(r[0][0]).addClass(v[0]),1<w)))for(k=1;k<w;k++)q.eq(r[k][0]).addClass(v[k]||v[y])}),e.processTbody(b,d,!1);b=!1!==c.columns_thead?["thead tr"]:[];!1!== c.columns_tfoot&&b.push("tfoot tr");if(b.length&&(h=n.find(b.join(",")).children().removeClass(m),w))for(k=0;k<w;k++)h.filter('[data-column="'+r[k][0]+'"]').addClass(v[k]||v[y]);a.debug&&e.benchmark("Applying Columns widget",f)},remove:function(b,a,c){var f=a.$tbodies,d=(c.columns||["primary","secondary","tertiary"]).join(" ");a.$headers.removeClass(d);a.$table.children("tfoot").children("tr").children("th, td").removeClass(d);for(a=0;a<f.length;a++)c=e.processTbody(b,f.eq(a),!0),c.children("tr").each(function(){l(this).children().removeClass(d)}), e.processTbody(b,c,!1)}});
2013-11-20 04:21:16 +00:00
e.addWidget({id:"filter",priority:50,options:{filter_anyMatch:!1,filter_childRows:!1,filter_columnFilters:!0,filter_cssFilter:"",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_saveFilters:!1,filter_searchDelay:300,filter_startsWith:!1,filter_useParsedData:!1,filter_serversideFiltering:!1,filter_defaultAttrib:"data-value"}, format:function(b,a,c){a.$table.hasClass("hasFilters")||(a.parsers||!a.parsers&&c.filter_serversideFiltering)&&e.filter.init(b,a,c)},remove:function(b,a,c){var f,d=a.$tbodies;a.$table.removeClass("hasFilters").unbind("addRows updateCell update updateComplete appendCache search filterStart filterEnd ".split(" ").join(".tsfilter ")).find(".tablesorter-filter-row").remove();for(a=0;a<d.length;a++)f=e.processTbody(b,d.eq(a),!0),f.children().removeClass(c.filter_filteredRow).show(),e.processTbody(b,f, !1);c.filter_reset&&l(document).undelegate(c.filter_reset,"click.tsfilter")}});
2013-11-23 02:01:48 +00:00
e.filter={regex:{regex:/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/,child:/tablesorter-childRow/,filtered:/filtered/,type:/undefined|number/,exact:/(^[\"|\'|=]+)|([\"|\'|=]+$)/g,nondigit:/[^\w,. \-()]/g,operators:/[<>=]/g},types:{regex:function(b,a,c,f){if(e.filter.regex.regex.test(a)){var d;b=e.filter.regex.regex.exec(a);try{d=RegExp(b[1],b[2]).test(f)}catch(g){d=!1}return d}return null},exact:function(b,a,c,f){return a.replace(e.filter.regex.exact, "")==f?!0:null},notMatch:function(b,a,c,f,d,e,h,p){return/^\!/.test(a)?(a=a.replace("!",""),b=f.search(l.trim(a)),""===a?!0:!(p.filter_startsWith?0===b:0<=b)):null},operators:function(b,a,c,f,d,g,h,l,q){if(/^[<>]=?/.test(a)){var m,k;m=h.config;b=e.formatFloat(a.replace(e.filter.regex.operators,""),h);c=m.parsers[g];l=b;if(q[g]||"numeric"===c.type)m=c.format(""+a.replace(e.filter.regex.operators,""),h,m.$headers.eq(g),g),b="number"!==typeof b||""===m||isNaN(m)?b:m;m=!q[g]&&"numeric"!==c.type||isNaN(b)|| !d?isNaN(f)?e.formatFloat(f.replace(e.filter.regex.nondigit,""),h):e.formatFloat(f,h):d;/>/.test(a)&&(k=/>=/.test(a)?m>=b:m>b);/</.test(a)&&(k=/<=/.test(a)?m<=b:m<b);k||""!==l||(k=!0);return k}return null},and:function(b,a,c,f){if(/\s+(AND|&&)\s+/g.test(b)){b=a.split(/(?:\s+(?:and|&&)\s+)/g);a=0<=f.search(l.trim(b[0]));for(c=b.length-1;a&&c;)a=a&&0<=f.search(l.trim(b[c])),c--;return a}return null},range:function(b,a,c,f,d,g,h,l,q){if(/\s+(-|to)\s+/.test(a)){b=h.config;c=a.split(/(?: - | to )/);l= e.formatFloat(c[0].replace(e.filter.regex.nondigit,""),h);var m=e.formatFloat(c[1].replace(e.filter.regex.nondigit,""),h);if(q[g]||"numeric"===b.parsers[g].type)a=b.parsers[g].format(""+c[0],h,b.$headers.eq(g),g),l=""===a||isNaN(a)?l:a,a=b.parsers[g].format(""+c[1],h,b.$headers.eq(g),g),m=""===a||isNaN(a)?m:a;a=!q[g]&&"numeric"!==b.parsers[g].type||isNaN(l)||isNaN(m)?isNaN(f)?e.formatFloat(f.replace(e.filter.regex.nondigit,""),h):e.formatFloat(f,h):d;l>m&&(a=l,l=m,m=a);return a>=l&&a<=m||""===l|| ""===m}return null},wild:function(b,a,c,f,d,e,h){return/[\?|\*]/.test(a)||/\s+OR\s+/.test(b)?(b=h.config,a=a.replace(/\s+OR\s+/gi,"|"),!b.$headers.filter('[data-column="'+e+'"]:last').hasClass("filter-match")&&/\|/.test(a)&&(a="^("+a+")$"),RegExp(a.replace(/\?/g,"\\S{1}").replace(/\*/g,"\\S*")).test(f)):null},fuzzy:function(b,a,c,f){if(/^~/.test(a)){b=0;c=f.length;var d=a.slice(1);for(a=0;a<c;a++)f[a]===d[b]&&(b+=1);return b===d.length?!0:!1}return null}},init:function(b,a,c){var f,d,g,h,p,q;a.debug&& (q=new Date);a.$table.addClass("hasFilters");e.filter.regex.child=RegExp(a.cssChildRow);e.filter.regex.filtered=RegExp(c.filter_filteredRow);!1!==c.filter_columnFilters&&a.$headers.filter(".filter-false").length!==a.$headers.length&&e.filter.buildRow(b,a,c);a.$table.bind("addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search ".split(" ").join(".tsfilter "),function(c,d){/(search|filterReset|filterEnd)/.test(c.type)||(c.stopPropagation(),e.filter.buildDefault(b, !0));"filterReset"===c.type&&e.filter.searching(b,[]);"filterEnd"===c.type?e.filter.buildDefault(b,!0):(d="search"===c.type?d:"updateComplete"===c.type?a.$table.data("lastSearch"):"",e.filter.searching(b,d));return!1});e.filter.bindSearch(b,a.$table.find("input.tablesorter-filter"));c.filter_reset&&l(document).delegate(c.filter_reset,"click.tsfilter",function(){a.$table.trigger("filterReset")});if(c.filter_functions)for(h in c.filter_functions)if(c.filter_functions.hasOwnProperty(h)&&"string"===typeof h)if(g= a.$headers.filter('[data-column="'+h+'"]:last'),f="",!0===c.filter_functions[h]&&!g.hasClass("filter-false"))e.filter.buildSelect(b,h);else if("string"===typeof h&&!g.hasClass("filter-false")){for(d in c.filter_functions[h])"string"===typeof d&&(f+=""===f?'<option value="">'+(g.data("placeholder")||g.attr("data-placeholder")||"")+"</option>":"",f+='<option value="'+d+'">'+d+"</option>");a.$table.find("thead").find('select.tablesorter-filter[data-column="'+h+'"]').append(f)}e.filter.buildDefault(b, !0);a.$table.find("select.tablesorter-filter").bind("change search",function(a,c){e.filter.checkFilters(
2013-11-20 04:21:16 +00:00
e.getFilters=function(b){var a=b?l(b)[0].config:{};return a&&a.widgetOptions&&!a.widgetOptions.filter_columnFilters?l(b).data("lastSearch"):a&&a.$filters?a.$filters.map(function(a,b){return l(b).find(".tablesorter-filter").val()|| ""}).get()||[]:!1};
e.setFilters=function(b,a,c){b=l(b);var e=b.length?b[0].config:{},e=e&&e.$filters?e.$filters.each(function(b,c){l(c).find(".tablesorter-filter").val(a[b]||"")}).trigger("change.tsfilter")||!1:!1;c&&b.trigger("search",[a,!1]);return!!e};
2013-11-23 02:01:48 +00:00
e.addWidget({id:"stickyHeaders",priority:60,options:{stickyHeaders:"",stickyHeaders_offset:0,stickyHeaders_cloneId:"-sticky",stickyHeaders_addResizeEvent:!0,stickyHeaders_includeCaption:!0, stickyHeaders_zIndex:2},format:function(b,a,c){if(!a.$table.hasClass("hasStickyHeaders")){var f,d=a.$table,g=l(window),h=d.children("thead:first"),p=h.children("tr").not(".sticky-false").children(),q=d.find("tfoot"),m=isNaN(c.stickyHeaders_offset)?l(c.stickyHeaders_offset):"",k=m.length?m.height()||0:parseInt(c.stickyHeaders_offset,10)||0,n=c.$sticky=d.clone().addClass("containsStickyHeaders").css({position:"fixed",margin:0,top:k,visibility:"hidden",zIndex:c.stickyHeaders_zIndex?c.stickyHeaders_zIndex: 2}),u=n.children("thead:first").addClass("tablesorter-stickyHeader "+c.stickyHeaders),r,w="",v=0,y=!1,A="collapse"!==d.css("border-collapse")&&!/(webkit|msie)/i.test(navigator.userAgent),x=function(){k=m.length?m.height()||0:parseInt(c.stickyHeaders_offset,10)||0;v=0;A&&(v=2*parseInt(p.eq(0).css("border-left-width"),10));n.css({left:h.offset().left-g.scrollLeft()-v,width:d.width()});r.filter(":visible").each(function(b){b=p.filter(":visible").eq(b);var c=A&&l(this).attr("data-column")===""+parseInt(a.columns/ 2,10)?1:0;l(this).css({width:b.width()-v,height:b.height()}).find(".tablesorter-header-inner").width(b.find(".tablesorter-header-inner").width()-c)})};n.attr("id")&&(n[0].id+=c.stickyHeaders_cloneId);n.find("thead:gt(0), tr.sticky-false, tbody, tfoot").remove();c.stickyHeaders_includeCaption?n.find("caption").css("margin-left","-1px"):n.find("caption").remove();r=u.children().children();n.css({height:0,width:0,padding:0,margin:0,border:0});r.find(".tablesorter-resizer").remove();d.addClass("hasStickyHeaders").bind("sortEnd.tsSticky", function(){p.filter(":visible").each(function(b){f=r.filter(":visible").eq(b).attr("class",l(this).attr("class")).removeClass(e.css.processing+" "+a.cssProcessing);a.cssIcon&&f.find("."+e.css.icon).attr("class",l(this).find("."+e.css.icon).attr("class"))})}).bind("pagerComplete.tsSticky",function(){x()});p.find(a.selectorSort).add(a.$headers.filter(a.selectorSort)).each(function(b){var c=l(this);b=u.children("tr.tablesorter-headerRow").children().eq(b).bind("mouseup",function(a){c.trigger(a,!0)}); a.cancelSelection&&b.attr("unselectable","on").bind("selectstart",!1).css({"user-select":"none",MozUserSelect:"none"})});d.after(n);g.bind("scroll.tsSticky resize.tsSticky",function(a){if(d.is(":visible")){var b=d.offset(),e=c.stickyHeaders_includeCaption?0:d.find("caption").outerHeight(!0),e=g.scrollTop()+k-e,f=d.height()-(n.height()+(q.height()||0)),b=e>b.top&&e<b.top+f?"visible":"hidden";n.removeClass("tablesorter-sticky-visible tablesorter-sticky-hidden").addClass("tablesorter-sticky-"+b).css({left:h.offset().left- g.scrollLeft()-v,visibility:b});if(b!==w||"resize"===a.type)x(),w=b}});c.stickyHeaders_addResizeEvent&&e.addHeaderResizeEvent(b);d.bind("filterEnd",function(){y||u.find(".tablesorter-filter-row").children().each(function(b){l(this).find(".tablesorter-filter").val(a.$filters.find(".tablesorter-filter").eq(b).val())})});r.find(".tablesorter-filter").bind("keyup search change",function(b){if(!(32>b.which&&8!==b.which||37<=b.which&&40>=b.which)){y=!0;b=l(this);var d=b.attr("data-column");a.$filters.find(".tablesorter-filter").eq(d).val(b.val()).trigger("search"); setTimeout(function(){y=!1},c.filter_searchDelay)}});d.trigger("stickyHeadersInit")}},remove:function(b,a,c){a.$table.removeClass("hasStickyHeaders").unbind("sortEnd.tsSticky pagerComplete.tsSticky").find(".tablesorter-stickyHeader").remove();c.$sticky&&c.$sticky.length&&c.$sticky.remove();l(".hasStickyHeaders").length||l(window).unbind("scroll.tsSticky resize.tsSticky");e.addHeaderResizeEvent(b,!1)}});
e.addWidget({id:"resizable",priority:40,options:{resizable:!0,resizable_addLastColumn:!1},format:function(b, a,c){if(!a.$table.hasClass("hasResizable")){a.$table.addClass("hasResizable");var f,d,g,h,p={},q=a.$table,m=0,k=null,n=null,u=20>Math.abs(q.parent().width()-q.width()),r=function(){e.storage&&k&&(p[k.index()]=k.width(),p[n.index()]=n.width(),k.width(p[k.index()]),n.width(p[n.index()]),!1!==c.resizable&&e.storage(b,"tablesorter-resizable",p));m=0;k=n=null;l(window).trigger("resize")};if(p=e.storage&&!1!==c.resizable?e.storage(b,"tablesorter-resizable"):{})for(h in p)!isNaN(h)&&h<a.$headers.length&& a.$headers.eq(h).width(p[h]);f=q.children("thead:first").children("tr");f.children().each(function(){var b;b=l(this);h=b.attr("data-column");b="false"===e.getData(b,a.headers[h],"resizable");f.children().filter('[data-column="'+h+'"]')[b?"addClass":"removeClass"]("resizable-false")});f.each(function(){g=l(this).children().not(".resizable-false");l(this).find(".tablesorter-wrapper").length||g.wrapInner('<div class="tablesorter-wrapper" style="position:relative;height:100%;width:100%"></div>');c.resizable_addLastColumn|| (g=g.slice(0,-1));d=d?d.add(g):g});d.each(function(){var a=l(this),b=parseInt(a.css("padding-right"),10)+10;a.find(".tablesorter-wrapper").append('<div class="tablesorter-resizer" style="cursor:w-resize;position:absolute;z-index:1;right:-'+b+'px;top:0;height:100%;width:20px;"></div>')}).bind("mousemove.tsresize",function(a){if(0!==m&&k){var b=a.pageX-m,c=k.width();k.width(c+b);k.width()!==c&&u&&n.width(n.width()-b);m=a.pageX}}).bind("mouseup.tsresize",function(){r()}).find(".tablesorter-resizer,.tablesorter-resizer-grip").bind("mousedown", function(b){k=l(b.target).closest("th");var c=a.$headers.filter('[data-column="'+k.attr("data-column")+'"]');1<c.length&&(k=k.add(c));n=b.shiftKey?k.parent().find("th").not(".resizable-false").filter(":last"):k.nextAll(":not(.resizable-false)").eq(0);m=b.pageX});q.find("thead:first").bind("mouseup.tsresize mouseleave.tsresize",function(){r()}).bind("contextmenu.tsresize",function(){e.resizableReset(b);var a=l.isEmptyObject?l.isEmptyObject(p):!0;p={};return a})}},remove:function(b,a){a.$table.removeClass("hasResizable").children("thead").unbind("mouseup.tsresize mouseleave.tsresize contextmenu.tsresize").children("tr").children().unbind("mousemove.tsresize mouseup.tsresize").find(".tablesorter-resizer,.tablesorter-resizer-grip").remove(); e.resizableReset(b)}});
e.resizableReset=function(b){b.config.$headers.not(".resizable-false").css("width","");e.storage&&e.storage(b,"tablesorter-resizable",{})};
e.addWidget({id:"saveSort",priority:20,options:{saveSort:!0},init:function(b,a,c,e){a.format(b,c,e,!0)},format:function(b,a,c,f){var d,g=a.$table;c=!1!==c.saveSort;var h={sortList:a.sortList};a.debug&&(d=new Date);g.hasClass("hasSaveSort")?c&&b.hasInitialized&&e.storage&&(e.storage(b,"tablesorter-savesort",h),a.debug&&e.benchmark("saveSort widget: Saving last sort: "+ a.sortList,d)):(g.addClass("hasSaveSort"),h="",e.storage&&(h=(c=e.storage(b,"tablesorter-savesort"))&&c.hasOwnProperty("sortList")&&l.isArray(c.sortList)?c.sortList:"",a.debug&&e.benchmark('saveSort: Last sort loaded: "'+h+'"',d),g.bind("saveSortReset",function(a){a.stopPropagation();e.storage(b,"tablesorter-savesort","")})),f&&h&&0<h.length?a.sortList=h:b.hasInitialized&&h&&0<h.length&&g.trigger("sorton",[h]))},remove:function(b){e.storage&&e.storage(b,"tablesorter-savesort","")}})
2013-10-30 22:47:58 +00:00
})(jQuery);