mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
3 lines
6.3 KiB
JavaScript
3 lines
6.3 KiB
JavaScript
/*! tablesorter pager plugin minified - updated 5/4/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 o=this,p=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)}p(b);d(c).trigger("pagerComplete",b)},s=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>')},l=function(c,b){var a, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies),g=e.length,f=b.page*b.size,i=f+b.size;i>g&&(i=g);for(a=0;a<g;a++)e[a].style.display=a>=f&&a<i?"":"none"},q=function(c,b){b.size=parseInt(d(b.cssPageSize,b.container).val(),10)||b.size;d.data(c,"pagerLastSize",b.size);p(b);b.removeRows||(l(c,b),d(c).bind("sortEnd.pager",function(){l(c,b)}))},u=function(c,b,a,e){if("function"===typeof a.ajaxProcessing){var g,f,i,j,h=d(b),k=d(b.tBodies[0]),o=h.find("thead th").length,m="",p='<tr class="remove-me"><td style="text-align: center;" colspan="'+ o+'">'+(e?e.message+" ("+e.name+")":"No rows found")+"</td></tr>",l=a.ajaxProcessing(c)||[0,[]],n=l[1]||[],q=n.length,r=l[2];if(0<q)for(c=0;c<q;c++){m+="<tr>";for(g=0;g<n[c].length;g++)m+="<td>"+n[c][g]+"</td>";m+="</tr>"}r&&r.length===o&&(f=h.hasClass("hasStickyHeaders"),j=h.find("."+(a.widgetOptions&&a.widgetOptions.stickyHeaders||"tablesorter-stickyheader")),i=h.find("tfoot tr:first").children(),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(r[a]);i.eq(a).html(r[a]);f&&j.length&&(b=j.find("th").eq(a),b=b.find("span").length?b.find("span:first"):b,b.html(r[a]))}));e?h.find("thead").append(p):k.html(m);a.temp.remove();h.trigger("update");a.totalRows=l[0]||0;a.totalPages=Math.ceil(a.totalRows/a.size);t(b,a);s(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,j){u(null,c,b,j)}),d.getJSON(e,function(a){u(a,c,b)}))},n=function(c,b,a){var e,g,f,i=document.createDocumentFragment(),j=b.length;e=a.page*a.size;var h=e+a.size;if(!(1>j)){d(c).trigger("pagerChange",a);if(a.removeRows){h>b.length&&(h=b.length);for(d.tablesorter.clearTableBody(c);e<h;e++){f=b[e];j=f.length;for(g=0;g<j;g++)i.appendChild(f[g])}c.tBodies[0].appendChild(i)}else l(c,a);a.page>=a.totalPages&&(a.page=a.totalPages-1,k(c,a));t(c,a);a.isDisabled|| s(c,a);d(c).trigger("applyWidgets")}},w=function(c,b){b.ajax?p(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(),n(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):n(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")||b.page||0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10)||b.size;b.totalPages=Math.ceil(b.totalRows/b.size);a&&(d(c).trigger("update"),x(c,b.size,b),q(c,b),s(c,b))};o.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),n(c,b,a))};o.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=o.appender;y(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,v(e,a)):(a.ajax=!1,d(this).trigger("appendCache"),q(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());s(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);
|