tablesorter/addons/pager/jquery.tablesorter.pager.min.js
2013-10-30 17:59:13 -05:00

3 lines
11 KiB
JavaScript

/*! tablesorter pager plugin minified - updated 10/30/2013 */
;(function(g){var l=g.tablesorter;g.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,customAjaxUrl:function(b,a){return a},ajaxObject:{dataType:"json"},ajaxProcessing:function(b){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,savePages:!0,fixedHeight:!1,countChildRows:!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,currentFilters:[],startRow:0,endRow:0,$size:null,last:{}};var w=this,x=function(b,a){var c=b.cssDisabled,f=!!a,e=Math.min(b.totalPages,b.filteredPages);b.updateArrows&&(b.$container.find(b.cssFirst+","+b.cssPrev)[f||0===b.page?"addClass":"removeClass"](c),b.$container.find(b.cssNext+","+b.cssLast)[f||b.page===e-1?"addClass":"removeClass"](c))},r=function(b,a,c){var f,e,h,d=b.config;f= d.$table.hasClass("hasFilters")&&!a.ajaxUrl;h=(d.widgetOptions&&d.widgetOptions.filter_filteredRow||"filtered")+","+d.selectorRemove;e=a.size||10;a.totalPages=Math.ceil(a.totalRows/e);a.filteredRows=f?d.$tbodies.eq(0).children("tr:not(."+h+")").length:a.totalRows;a.filteredPages=f?Math.ceil(a.filteredRows/e)||1:a.totalPages;if(0<=Math.min(a.totalPages,a.filteredPages)&&(h=a.size*a.page>a.filteredRows,a.startRow=h?1:0===a.filteredRows?0:a.size*a.page+1,a.page=h?0:a.page,a.endRow=Math.min(a.filteredRows, a.totalRows,a.size*(a.page+1)),f=a.$container.find(a.cssPageDisplay),h=(a.ajaxData&&a.ajaxData.output?a.ajaxData.output||a.output:a.output).replace(/\{page([\-+]\d+)?\}/gi,function(b,c){return a.page+(c?parseInt(c,10):1)}).replace(/\{\w+(\s*:\s*\w+)?\}/gi,function(b){b=b.replace(/[{}\s]/g,"");var c=b.split(":"),d=a.ajaxData;return 1<c.length&&d&&d[c[0]]?d[c[0]][c[1]]:a[b]||(d?d[b]:"")||""}),f.length&&(f["INPUT"===f[0].tagName?"val":"html"](h),a.$goto.length))){h="";e=Math.min(a.totalPages,a.filteredPages); for(f=1;f<=e;f++)h+="<option>"+f+"</option>";a.$goto.html(h).val(a.page+1)}x(a);a.initialized&&!1!==c&&(d.$table.trigger("pagerComplete",a),a.savePages&&l.storage&&l.storage(b,"tablesorter-pager",{page:a.page,size:a.size}))},t=function(b,a){var c,f=b.config,e=f.$tbodies.eq(0);a.fixedHeight&&(e.find("tr.pagerSavedHeightSpacer").remove(),c=g.data(b,"pagerSavedHeight"))&&(c-=e.height(),5<c&&g.data(b,"pagerLastSize")===a.size&&e.children("tr:visible").length<a.size&&e.append('<tr class="pagerSavedHeightSpacer '+ f.selectorRemove.replace(/(tr)?\./g,"")+'" style="height:'+c+'px;"></tr>'))},A=function(b,a){var c=b.config.$tbodies.eq(0);c.find("tr.pagerSavedHeightSpacer").remove();g.data(b,"pagerSavedHeight",c.height());t(b,a);g.data(b,"pagerLastSize",a.size)},u=function(b,a){if(!a.ajaxUrl){var c,f=b.config,e=f.$tbodies.eq(0).children(),h=e.length,d=a.page*a.size,g=d+a.size,n=f.widgetOptions&&f.widgetOptions.filter_filteredRow||"filtered",m=0;for(c=0;c<h;c++)e[c].className.match(n)||(e[c].style.display=m>=d&& m<g?"":"none",m+=e[c].className.match(f.cssChildRow+"|"+f.selectorRemove.slice(1))&&!a.countChildRows?0:1)}},B=function(b,a){a.size=parseInt(a.$size.val(),10)||a.size;g.data(b,"pagerLastSize",a.size);x(a);a.removeRows||(u(b,a),g(b).bind("sortEnd.pager filterEnd.pager",function(){u(b,a)}))},C=function(b,a,c,f,e){if("function"===typeof c.ajaxProcessing){var h,d,s,n,m,v,k=a.config,p=k.$table,q="";h=c.ajaxProcessing(b,a)||[0,[]];b=p.find("thead th").length;p.find("thead tr."+c.cssErrorRow).remove();if(e)g('<tr class="'+ c.cssErrorRow+'"><td style="text-align:center;" colspan="'+b+'">'+(0===f.status?"Not connected, verify Network":404===f.status?"Requested page not found [404]":500===f.status?"Internal Server Error [500]":"parsererror"===e?"Requested JSON parse failed":"timeout"===e?"Time out error":"abort"===e?"Ajax Request aborted":"Uncaught error: "+f.statusText+" ["+f.status+"]")+"</td></tr>").click(function(){g(this).remove()}).appendTo(p.find("thead:first")),k.$tbodies.eq(0).empty();else{g.isArray(h)?(f=isNaN(h[0])&& !isNaN(h[1]),e=h[f?1:0],c.totalRows=isNaN(e)?c.totalRows||0:e,f=h[f?0:1]||[],m=h[2]):(c.ajaxData=h,c.totalRows=h.total,m=h.headers,f=h.rows);v=f.length;if(f instanceof jQuery)k.$tbodies.eq(0).empty().append(f);else if(v){if(0<v)for(h=0;h<v;h++){q+="<tr>";for(e=0;e<f[h].length;e++)q+="<td>"+f[h][e]+"</td>";q+="</tr>"}k.$tbodies.eq(0).html(q)}m&&m.length===b&&(n=(d=p.hasClass("hasStickyHeaders"))?k.$sticky.children("thead:first").children().children():"",s=p.find("tfoot tr:first").children(),k.$headers.filter("th").each(function(a){var b= g(this),c;b.find("."+l.css.icon).length?(c=b.find("."+l.css.icon).clone(!0),b.find(".tablesorter-header-inner").html(m[a]).append(c),d&&n.length&&(c=n.eq(a).find("."+l.css.icon).clone(!0),n.eq(a).find(".tablesorter-header-inner").html(m[a]).append(c))):(b.find(".tablesorter-header-inner").html(m[a]),d&&n.length&&n.eq(a).find(".tablesorter-header-inner").html(m[a]));s.eq(a).html(m[a])}))}k.showProcessing&&l.isProcessing(a);c.totalPages=Math.ceil(c.totalRows/(c.size||10));r(a,c);t(a,c);c.initialized? (p.trigger("pagerChange",c),p.trigger("updateComplete")):p.trigger("update")}c.initialized||(c.initialized=!0,g(a).trigger("pagerInitialized",c))},H=function(b,a){var c=G(b,a),f=g(document),e=b.config;""!==c&&(e.showProcessing&&l.isProcessing(b,!0),f.bind("ajaxError.pager",function(c,d,e,g){C(null,b,a,d,g);f.unbind("ajaxError.pager")}),a.ajaxObject.url=c,a.ajaxObject.success=function(c){C(c,b,a);f.unbind("ajaxError.pager");"function"===typeof a.oldAjaxSuccess&&a.oldAjaxSuccess(c)},g.ajax(a.ajaxObject))}, G=function(b,a){var c=a.ajaxUrl?a.ajaxUrl.replace(/\{page([\-+]\d+)?\}/,function(c,b){return a.page+(b?parseInt(b,10):0)}).replace(/\{size\}/g,a.size):"",f=b.config.sortList,e=a.currentFilters||[],h=c.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),d=c.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),k=[];h&&(h=h[1],g.each(f,function(a,b){k.push(h+"["+b[0]+"]="+b[1])}),c=c.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g,k.length?k.join("&"):h),k=[]);d&&(d=d[1],g.each(e,function(a,b){b&&k.push(d+"["+a+"]="+ encodeURIComponent(b))}),c=c.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g,k.length?k.join("&"):d));"function"===typeof a.customAjaxUrl&&(c=a.customAjaxUrl(b,c));return c},y=function(b,a,c){var f,e;f=c.page*c.size;var h=f+c.size;if(!(1>(a&&a.length||0))){c.page>=c.totalPages&&D(b,c);c.isDisabled=!1;c.initialized&&g(b).trigger("pagerChange",c);if(c.removeRows){h>a.length&&(h=a.length);l.clearTableBody(b);for(e=l.processTbody(b,b.config.$tbodies.eq(0),!0);f<h;f++)e.append(a[f]);l.processTbody(b, e,!1)}else u(b,c);r(b,c);c.isDisabled||t(b,c);g(b).trigger("applyWidgets")}},E=function(b,a){a.ajax?x(a,!0):(a.isDisabled=!0,g.data(b,"pagerLastPage",a.page),g.data(b,"pagerLastSize",a.size),a.page=0,a.size=a.totalRows,a.totalPages=1,g(b).addClass("pagerDisabled").find("tr.pagerSavedHeightSpacer").remove(),y(b,b.config.rowsCopy,a));a.$size.add(a.$goto).each(function(){g(this).addClass(a.cssDisabled)[0].disabled=!0})},k=function(b,a,c){if(!a.isDisabled){var f=a.last,e=Math.min(a.totalPages,a.filteredPages); 0>a.page&&(a.page=0);a.page>e-1&&0!==e&&(a.page=e-1);if(f.page!==a.page||f.size!==a.size||f.total!==a.totalPages||f.filters!==a.currentFilters)a.last={page:a.page,size:a.size,totalPages:a.totalPages,currentFilters:a.currentFilters},a.ajax?H(b,a):a.ajax||y(b,b.config.rowsCopy,a),g.data(b,"pagerLastPage",a.page),g.data(b,"pagerUpdateTriggered",!0),a.initialized&&!1!==c&&g(b).trigger("pageMoved",a)}},z=function(b,a,c){c.size=a;c.$size.val(a);g.data(b,"pagerLastPage",c.page);g.data(b,"pagerLastSize", c.size);c.totalPages=Math.ceil(c.totalRows/(c.size||10));k(b,c)},I=function(b,a){a.page=0;k(b,a)},D=function(b,a){a.page=Math.min(a.totalPages,a.filteredPages)-1;k(b,a)},J=function(b,a){a.page++;a.page>=Math.min(a.totalPages,a.filteredPages)-1&&(a.page=Math.min(a.totalPages,a.filteredPages)-1);k(b,a)},K=function(b,a){a.page--;0>=a.page&&(a.page=0);k(b,a)},F=function(b,a,c){var f=a.$size.removeClass(a.cssDisabled).removeAttr("disabled");a.$goto.removeClass(a.cssDisabled).removeAttr("disabled");a.isDisabled= !1;a.page=g.data(b,"pagerLastPage")||a.page||0;a.size=g.data(b,"pagerLastSize")||parseInt(f.find("option[selected]").val(),10)||a.size;f.val(a.size);a.totalPages=Math.ceil(Math.min(a.totalPages,a.filteredPages)/(a.size||10));c&&(g(b).trigger("update"),z(b,a.size,a),B(b,a),t(b,a))};w.appender=function(b,a){var c=b.config.pager;c.ajax||(b.config.rowsCopy=a,c.totalRows=a.length,c.size=g.data(b,"pagerLastSize")||c.size,c.totalPages=Math.ceil(c.totalRows/(c.size||10)),y(b,a,c))};w.construct=function(b){return this.each(function(){if(this.config&& this.hasInitialized){var a,c,f,e=this,h=e.config,d=h.pager=g.extend({},g.tablesorterPager.defaults,b),s=h.$table,n=d.$container=g(d.container).addClass("tablesorter-pager").show();d.oldAjaxSuccess=d.oldAjaxSuccess||d.ajaxObject.success;h.appender=w.appender;d.savePages&&l.storage&&(a=l.storage(e,"tablesorter-pager")||{},d.page=isNaN(a.page)?d.page:a.page,d.size=(isNaN(a.size)?d.size:a.size)||10);s.unbind("filterStart.pager filterEnd.pager sortEnd.pager disable.pager enable.pager destroy.pager update.pager pageSize.pager").bind("filterStart.pager", function(a,b){g.data(e,"pagerUpdateTriggered",!1);d.currentFilters=b}).bind("filterEnd.pager sortEnd.pager",function(a){g.data(e,"pagerUpdateTriggered")?g.data(e,"pagerUpdateTriggered",!1):(("filterEnd"===a.type||"sortEnd"===a.type&&h.serverSideSorting)&&k(e,d,!1),r(e,d,!1),t(e,d))}).bind("disable.pager",function(a){a.stopPropagation();E(e,d)}).bind("enable.pager",function(a){a.stopPropagation();F(e,d,!0)}).bind("destroy.pager",function(a){a.stopPropagation();E(e,d);d.$container.hide();e.config.appender= null;d.initialized=!1;g(e).unbind("destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager");l.storage&&l.storage(e,"tablesorter-pager","")}).bind("update.pager",function(a){a.stopPropagation();u(e,d)}).bind("pageSize.pager",function(a,b){a.stopPropagation();z(e,parseInt(b,10)||10,d);u(e,d);r(e,d,!1);d.$size.length&&d.$size.val(d.size)}).bind("pageSet.pager",function(a,b){a.stopPropagation();d.page=(parseInt(b,10)||1)-1;d.$goto.length&&d.$goto.val(d.size);k(e,d);r(e,d,!1)});c=[d.cssFirst, d.cssPrev,d.cssNext,d.cssLast];f=[I,K,J,D];n.find(c.join(",")).unbind("click.pager").bind("click.pager",function(a){var b=g(this),h=c.length;if(!b.hasClass(d.cssDisabled))for(a=0;a<h;a++)if(b.is(c[a])){f[a](e,d);break}return!1});d.$goto=n.find(d.cssGoto);d.$goto.length&&d.$goto.unbind("change").bind("change",function(){d.page=g(this).val()-1;k(e,d);r(e,d,!1)});d.$size=n.find(d.cssPageSize);d.$size.length&&d.$size.unbind("change.pager").bind("change.pager",function(){d.$size.val(g(this).val());g(this).hasClass(d.cssDisabled)|| (z(e,parseInt(g(this).val(),10),d),A(e,d));return!1});d.initialized=!1;s.trigger("pagerBeforeInitialized",d);F(e,d,!1);"string"===typeof d.ajaxUrl?(d.ajax=!0,h.widgetOptions.filter_serversideFiltering=!0,h.serverSideSorting=!0,k(e,d)):(d.ajax=!1,g(this).trigger("appendCache",!0),B(e,d));A(e,d);d.ajax||(d.initialized=!0,g(e).trigger("pagerInitialized",d))}})}}});g.fn.extend({tablesorterPager:g.tablesorterPager.construct})})(jQuery);