tablesorter/addons/pager/jquery.tablesorter.pager.min.js

3 lines
9.1 KiB
JavaScript

/*! tablesorter pager plugin minified - updated 1/4/2013 */
;(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!1,cssFirst:".first",cssPrev:".prev",cssNext:".next",cssLast:".last",cssGoto:".gotoPage",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssErrorRow:"tablesorter-errorRow",cssDisabled:"disabled",totalRows:0,totalPages:0,filteredRows:0,filteredPages:0}; var p=this,s=function(b,a){var c=b.cssDisabled,f=!!a,h=Math.min(b.totalPages,b.filteredPages);b.updateArrows&&(d(b.cssFirst+","+b.cssPrev,b.container)[f||0===b.page?"addClass":"removeClass"](c),d(b.cssNext+","+b.cssLast,b.container)[f||b.page===h-1?"addClass":"removeClass"](c))},u=function(b,a){var c,f,h;c=d(b).hasClass("hasFilters")&&!a.ajaxUrl;a.filteredRows=c?b.config.$tbodies.children("tr:not(.filtered,.remove-me)").length:a.totalRows;a.filteredPages=c?Math.ceil(a.filteredRows/a.size):a.totalPages; if(0<Math.min(a.totalPages,a.filteredPages)&&(h=a.size*a.page>a.filteredRows,a.startRow=h?1:a.size*a.page+1,a.page=h?0:a.page,a.endRow=Math.min(a.filteredRows,a.totalRows,a.size*(a.page+1)),f=d(a.cssPageDisplay,a.container),c=a.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi,function(b){return{"{page}":a.page+1,"{filteredRows}":a.filteredRows,"{filteredPages}":a.filteredPages,"{totalPages}":a.totalPages,"{startRow}":a.startRow,"{endRow}":a.endRow,"{totalRows}":a.totalRows}[b]}), f[0]&&(f["INPUT"===f[0].tagName?"val":"html"](c),d(a.cssGoto,a.container).length))){h="";f=Math.min(a.totalPages,a.filteredPages);for(c=1;c<=f;c++)h+="<option>"+c+"</option>";d(a.cssGoto,a.container).html(h).val(a.page+1)}s(a);a.initialized&&d(b).trigger("pagerComplete",a)},t=function(b,a){var c,f=d(b.tBodies[0]);if(a.fixedHeight&&(f.find("tr.pagerSavedHeightSpacer").remove(),c=d.data(b,"pagerSavedHeight")))c-=f.height(),5<c&&(d.data(b,"pagerLastSize")===a.size&&f.children("tr:visible").length<a.size)&& f.append('<tr class="pagerSavedHeightSpacer '+b.config.selectorRemove.replace(".","")+'" style="height:'+c+'px;"></tr>')},w=function(b,a){var c=d(b.tBodies[0]);c.find("tr.pagerSavedHeightSpacer").remove();d.data(b,"pagerSavedHeight",c.height());t(b,a);d.data(b,"pagerLastSize",a.size)},n=function(b,a){if(!a.ajaxUrl){var c,f=d(b.tBodies).children("tr:not(."+b.config.cssChildRow+")"),h=f.length,e=a.page*a.size,g=e+a.size,k=0;for(c=0;c<h;c++)/filtered/.test(f[c].className)||(f[c].style.display=k>=e&& k<g?"":"none",k++)}},x=function(b,a){a.size=parseInt(d(a.cssPageSize,a.container).find("option[selected]").val(),10)||a.size;d.data(b,"pagerLastSize",a.size);s(a);a.removeRows||(n(b,a),d(b).bind("sortEnd.pager filterEnd.pager",function(){n(b,a)}))},z=function(b,a,c,f){if("function"===typeof c.ajaxProcessing){var h,e,g,k,j=d(a),l=a.config,E=c.$tbodies,y=j.find("thead th").length,q="",m='<tr class="'+c.cssErrorRow+" "+l.selectorRemove.replace(".","")+'"><td style="text-align: center;" colspan="'+y+ '">'+(f?f.message+" ("+f.name+")":"No rows found")+"</td></tr>",n=c.ajaxProcessing(b)||[0,[]],p=n[1]||[],s=p.length,r=n[2];if(0<s)for(b=0;b<s;b++){q+="<tr>";for(h=0;h<p[b].length;h++)q+="<td>"+p[b][h]+"</td>";q+="</tr>"}r&&r.length===y&&(e=j.hasClass("hasStickyHeaders"),k=j.find("."+(l.widgetOptions&&l.widgetOptions.stickyHeaders||"tablesorter-stickyheader")),g=j.find("tfoot tr:first").children(),j.find("th."+l.cssHeader).each(function(a){var b=d(this),c;b.find("."+l.cssIcon).length?(c=b.find("."+ l.cssIcon).clone(!0),b.find(".tablesorter-header-inner").html(r[a]).append(c),e&&k.length&&(c=k.find("th").eq(a).find("."+l.cssIcon).clone(!0),k.find("th").eq(a).find(".tablesorter-header-inner").html(r[a]).append(c))):(b.find(".tablesorter-header-inner").html(r[a]),k.find("th").eq(a).find(".tablesorter-header-inner").html(r[a]));g.eq(a).html(r[a])}));j.find("thead tr."+c.cssErrorRow).remove();f?j.find("thead").append(m):E.html(q);l.showProcessing&&d.tablesorter.isProcessing(a);j.trigger("update"); c.totalRows=n[0]||0;c.totalPages=Math.ceil(c.totalRows/c.size);u(a,c);t(a,c);c.initialized&&j.trigger("pagerChange",c)}c.initialized||(c.initialized=!0,d(a).trigger("pagerInitialized",c))},v=function(b,a,c){c.isDisabled=!1;var f,h,e,g=document.createDocumentFragment(),k=a.length;f=c.page*c.size;var j=f+c.size;if(!(1>k)){c.initialized&&d(b).trigger("pagerChange",c);if(c.removeRows){j>a.length&&(j=a.length);d(b.tBodies[0]).addClass("tablesorter-hidden");for(d.tablesorter.clearTableBody(b);f<j;f++){e= a[f];k=e.length;for(h=0;h<k;h++)g.appendChild(e[h])}b.tBodies[0].appendChild(g);d(b.tBodies[0]).removeClass("tablesorter-hidden")}else n(b,c);c.page>=c.totalPages&&A(b,c);u(b,c);c.isDisabled||t(b,c);d(b).trigger("applyWidgets")}},B=function(b,a){a.ajax?s(a,!0):(a.isDisabled=!0,d.data(b,"pagerLastPage",a.page),d.data(b,"pagerLastSize",a.size),a.page=0,a.size=a.totalRows,a.totalPages=1,d("tr.pagerSavedHeightSpacer",b.tBodies[0]).remove(),v(b,b.config.rowsCopy,a));d(a.container).find(a.cssPageSize+","+ a.cssGoto).each(function(){d(this).addClass(a.cssDisabled)[0].disabled=!0})},m=function(b,a){if(!a.isDisabled){var c=Math.min(a.totalPages,a.filteredPages);if(0>a.page||a.page>c-1)a.page=0;if(a.ajax){var f,c=a.ajaxUrl?a.ajaxUrl.replace(/\{page\}/g,a.page).replace(/\{size\}/g,a.size):"",h=b.config.sortList,e=a.currentFilters||[],g=c.match(/\{sortList[\s+]?:[\s+]?([^}]*)\}/),k=c.match(/\{filterList[\s+]?:[\s+]?([^}]*)\}/),j=[];g&&(g=g[1],d.each(h,function(a,b){j.push(g+"["+b[0]+"]="+b[1])}),c=c.replace(/\{sortList[\s+]?:[\s+]?([^\}]*)\}/g, j.length?j.join("&"):g));k&&(k=k[1],d.each(e,function(a,b){b&&j.push(k+"["+a+"]="+encodeURIComponent(b))}),c=c.replace(/\{filterList[\s+]?:[\s+]?([^\}]*)\}/g,j.length?j.join("&"):k));f=c;c=b.config;""!==f&&(c.showProcessing&&d.tablesorter.isProcessing(b,!0),d(document).bind("ajaxError.pager",function(c,e,g,h){g.url===f&&(z(null,b,a,h),d(document).unbind("ajaxError.pager"))}),d.getJSON(f,function(c){z(c,b,a);d(document).unbind("ajaxError.pager")}))}else a.ajax||v(b,b.config.rowsCopy,a);d.data(b,"pagerLastPage", a.page);d.data(b,"pagerUpdateTriggered",!0);a.initialized&&d(b).trigger("pageMoved",a)}},C=function(b,a,c){c.size=a;d.data(b,"pagerLastPage",c.page);d.data(b,"pagerLastSize",c.size);c.totalPages=Math.ceil(c.totalRows/c.size);m(b,c)},F=function(b,a){a.page=0;m(b,a)},A=function(b,a){a.page=Math.min(a.totalPages,a.filteredPages)-1;m(b,a)},G=function(b,a){a.page++;a.page>=Math.min(a.totalPages,a.filteredPages)-1&&(a.page=Math.min(a.totalPages,a.filteredPages)-1);m(b,a)},H=function(b,a){a.page--;0>=a.page&& (a.page=0);m(b,a)},D=function(b,a,c){var f=d(a.cssPageSize,a.container).removeClass(a.cssDisabled).removeAttr("disabled");d(a.container).find(a.cssGoto).removeClass(a.cssDisabled).removeAttr("disabled");a.isDisabled=!1;a.page=d.data(b,"pagerLastPage")||a.page||0;a.size=d.data(b,"pagerLastSize")||parseInt(f.find("option[selected]").val(),10)||a.size;f.val(a.size);a.totalPages=Math.ceil(Math.min(a.totalPages,a.filteredPages)/a.size);c&&(d(b).trigger("update"),C(b,a.size,a),x(b,a),t(b,a))};p.appender= function(b,a){var c=b.config.pager;c.ajax||(b.config.rowsCopy=a,c.totalRows=a.length,c.size=d.data(b,"pagerLastSize")||c.size,c.totalPages=Math.ceil(c.totalRows/c.size),v(b,a,c))};p.construct=function(b){return this.each(function(){if(this.config&&this.hasInitialized){var a,c,f,h=this.config,e=h.pager=d.extend({},d.tablesorterPager.defaults,b),g=this,k=g.config,j=d(g),l=d(e.container).addClass("tablesorter-pager").show();h.appender=p.appender;j.unbind("filterStart.pager filterEnd.pager sortEnd.pager disable.pager enable.pager destroy.pager update.pager").bind("filterStart.pager", function(a,b){d.data(g,"pagerUpdateTriggered",!1);e.currentFilters=b}).bind("filterEnd.pager sortEnd.pager",function(a){d.data(g,"pagerUpdateTriggered")?d.data(g,"pagerUpdateTriggered",!1):("filterEnd"===a.type&&(e.page=0),u(g,e),m(g,e),t(g,e))}).bind("disable.pager",function(){B(g,e)}).bind("enable.pager",function(){D(g,e,!0)}).bind("destroy.pager",function(){B(g,e);d(e.container).hide();g.config.appender=null;d(g).unbind("destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager")}).bind("update.pager", function(){n(g,e)});c=[e.cssFirst,e.cssPrev,e.cssNext,e.cssLast];f=[F,H,G,A];l.find(c.join(",")).unbind("click.pager").bind("click.pager",function(){var a,b=d(this),h=c.length;if(!b.hasClass(e.cssDisabled))for(a=0;a<h;a++)if(b.is(c[a])){f[a](g,e);break}return!1});l.find(e.cssGoto).length&&(l.find(e.cssGoto).unbind("change").bind("change",function(){e.page=d(this).val()-1;m(g,e)}),u(g,e));a=l.find(e.cssPageSize);a.length&&a.unbind("change.pager").bind("change.pager",function(){a.val(d(this).val()); d(this).hasClass(e.cssDisabled)||(C(g,parseInt(d(this).val(),10),e),w(g,e));return!1});e.initialized=!1;j.trigger("pagerBeforeInitialized",e);D(g,e,!1);"string"===typeof e.ajaxUrl?(e.ajax=!0,k.widgetOptions.filter_serversideFiltering=!0,k.serverSideSorting=!0,m(g,e)):(e.ajax=!1,d(this).trigger("appendCache",!0),x(g,e));w(g,e);e.ajax||(e.initialized=!0,d(g).trigger("pagerInitialized",e))}})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery);