tablesorter/addons/pager/jquery.tablesorter.pager.min.js
2012-03-16 23:13:22 -05:00

4 lines
6.3 KiB
JavaScript

/* tablesorter pager plugin minified - updated 3/16/2012 */
(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:!0,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0};var n=this,i=function(c,b){var a=c.cssDisabled,e=!!b;c.updateArrows&&(c.container[c.totalRows< c.size?"addClass":"removeClass"](a),d(c.cssFirst+","+c.cssPrev,c.container)[e||0===c.page?"addClass":"removeClass"](a),d(c.cssNext+","+c.cssLast,c.container)[e||c.page===c.totalPages-1?"addClass":"removeClass"](a))},t=function(c,b){if(0<b.totalPages){b.startRow=b.size*b.page+1;b.endRow=Math.min(b.totalRows,b.size*(b.page+1));var a=d(b.cssPageDisplay,b.container),e=b.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi,function(a){return{"{page}":b.page+1,"{totalPages}":b.totalPages, "{startRow}":b.startRow,"{endRow}":b.endRow,"{totalRows}":b.totalRows}[a]});if(a[0])a["INPUT"===a[0].tagName?"val":"html"](e)}i(b);d(c).trigger("pagerComplete",b)},r=function(c,b){var a,e=d(c.tBodies[0]);if(b.fixedHeight&&(e.find("tr.pagerSavedHeightSpacer").remove(),a=d.data(c,"pagerSavedHeight")))a-=e.height(),5<a&&d.data(c,"pagerLastSize")===b.size&&e.find("tr:visible").length<b.size&&e.append('<tr class="pagerSavedHeightSpacer remove-me" style="height:'+a+'px;"></tr>')},o=function(c,b){var a, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies[0]),g=e.length,f=b.page*b.size,j=f+b.size;j>g&&(j=g);for(a=0;a<g;a++)e[a].style.display=a>=f&&a<j?"":"none"},p=function(c,b){b.size=parseInt(d(b.cssPageSize,b.container).val(),10);d.data(c,"pagerLastSize",b.size);i(b);b.removeRows||(o(c,b),d(c).bind("sortEnd.pager",function(){o(c,b);d(c).trigger("applyWidgets")}))},u=function(c,b,a,e){if("function"===typeof a.ajaxProcessing){var g,f,j,h=d(b),k=d(b.tBodies[0]),n=h.find("thead th").length,i="",l="", o='<tr class="remove-me"><td style="text-align: center;" colspan="'+n+'">'+(e?e.message+" ("+e.name+")":"No rows found")+"</td></tr>",m=a.ajaxProcessing(c)||[0,[]],s=m[1]||[],p=s.length,q=m[2];if(0<p)for(c=0;c<p;c++){l+="<tr>";for(g=0;g<s[c].length;g++)l+="<td>"+s[c][g]+"</td>";l+="</tr>"}q&&q.length===n&&(f=h.hasClass("hasStickyHeaders"),j=h.find("."+(a.widgetOptions&&a.widgetOptions.stickyHeaders||"tablesorter-stickyheader")),h.find("thead tr.tablesorter-header th").each(function(a){var b=d(this), b=b.find("span").length?b.find("span:first"):b;b.html(q[a]);f&&j.length&&(b=j.find("th").eq(a),b=b.find("span").length?b.find("span:first"):b,b.html(q[a]));i+="<th>"+q[a]+"</th>"}),h.find("tfoot").html("<tr>"+i+"</tr>"));e?h.find("thead").append(o):k.html(l);a.temp.remove();h.trigger("update");a.totalRows=m[0]||0;a.totalPages=Math.ceil(a.totalRows/a.size);t(b,a);r(b,a);h.trigger("pagerChange",a)}},v=function(c,b){var a=d(c),e=b.ajaxUrl.replace(/\{page\}/g,b.page).replace(/\{size\}/g,b.size);""!== e&&(b.temp=d("<div/>",{id:"tablesorterPagerLoading",width:a.outerWidth(!0),height:a.outerHeight(!0)}),a.before(b.temp),d(document).ajaxError(function(a,d,e,h){u(null,c,b,h)}),d.getJSON(e,function(a){u(a,c,b)}))},m=function(c,b,a){var e,g,f,j=d(c.tBodies[0]),h=b.length;e=a.page*a.size;var i=e+a.size;if(!(1>h)){d(c).trigger("pagerChange",a);if(a.removeRows){i>b.length&&(i=b.length);for(d(c.tBodies[0]).empty();e<i;e++){f=b[e];h=f.length;for(g=0;g<h;g++)j[0].appendChild(f[g])}}else o(c,a);d(c).trigger("applyWidgets"); a.page>=a.totalPages&&(a.page=a.totalPages-1,k(c,a));t(c,a);a.isDisabled||r(c,a)}},w=function(c,b){b.ajax?i(b,!0):(b.isDisabled=!0,d.data(c,"pagerLastPage",b.page),d.data(c,"pagerLastSize",b.size),b.page=0,b.size=b.totalRows,b.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),m(c,c.config.rowsCopy,b));d(b.cssPageSize,b.container).addClass(b.cssDisabled)[0].disabled=!0},k=function(c,b){if(!b.isDisabled){if(0>b.page||b.page>b.totalPages-1)b.page=0;d.data(c,"pagerLastPage",b.page);b.ajax? v(c,b):m(c,c.config.rowsCopy,b)}},x=function(c,b,a){a.size=b;d.data(c,"pagerLastPage",a.page);d.data(c,"pagerLastSize",a.size);a.totalPages=Math.ceil(a.totalRows/a.size);k(c,a)},y=function(c,b,a){var e=d(b.cssPageSize,b.container).removeClass(b.cssDisabled).removeAttr("disabled");b.isDisabled=!1;b.page=d.data(c,"pagerLastPage")||0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10);b.totalPages=Math.ceil(b.totalRows/b.size);a&&(d("table").trigger("update"),x(c,b.size,b),p(c,b),r(c,b))};n.appender= function(c,b){var a=c.config.pager;a.ajax||(c.config.rowsCopy=b,a.totalRows=b.length,a.size=d.data(c,"pagerLastSize")||a.size,a.totalPages=Math.ceil(a.totalRows/a.size),m(c,b,a))};n.construct=function(c){return this.each(function(){var b=this.config,a=b.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,g=d(e),f=d(a.container).show();b.appender=n.appender;y(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,v(e,a)):(a.ajax=!1,d(this).trigger("appendCache"),p(e,a));d(a.cssFirst,f).unbind("click.pager").bind("click.pager", function(){if(!d(this).hasClass(a.cssDisabled)){a.page=0;k(e,a)}return false});d(a.cssNext,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;k(e,a)}return false});d(a.cssPrev,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page--;if(a.page<=0)a.page=0;k(e,a)}return false});d(a.cssLast,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page= a.totalPages-1;k(e,a)}return false});d(a.cssPageSize,f).unbind("change.pager").bind("change.pager",function(){d(a.cssPageSize,f).val(d(this).val());if(!d(this).hasClass(a.cssDisabled)){x(e,parseInt(d(this).val(),10),a);var b=d(e.tBodies[0]);b.find("tr.pagerSavedHeightSpacer").remove();d.data(e,"pagerSavedHeight",b.height());r(e,a);d.data(e,"pagerLastSize",a.size)}return false});g.unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){w(e,a)}).bind("enable.pager",function(){y(e, a,true)}).bind("destroy.pager",function(){w(e,a);a.container.hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery);