tablesorter/addons/pager/jquery.tablesorter.pager.min.js
2012-09-27 14:57:19 -05:00

3 lines
7.5 KiB
JavaScript

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