tablesorter/addons/pager/jquery.tablesorter.pager.min.js
2013-03-27 20:01:39 -05:00

3 lines
9.5 KiB
JavaScript

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