tablesorter/addons/pager/jquery.tablesorter.pager.min.js
Mottie 4f1aa02a93 new pager events - issue #153
Added "pagerInitialized" and "pageMoved" thanks to ViViDboarder
2012-10-15 16:43:09 -05:00

2 lines
8.1 KiB
JavaScript

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