tablesorter/addons/pager/jquery.tablesorter.pager.min.js

3 lines
16 KiB
JavaScript
Raw Normal View History

2014-12-23 03:12:59 +00:00
/* tablesorter (FORK) pager plugin updated 12/22/2014 (v2.18.4) */
;(function(h){var k=h.tablesorter;h.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,customAjaxUrl:function(c,a){return a},ajaxObject:{dataType:"json"},processAjaxOnInit:!0,ajaxProcessing:function(c){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,pageReset:0,size:10,maxOptionSize:20,savePages:!0,storageKey:"tablesorter-pager",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,ajaxCounter:0,currentFilters:[],startRow:0,endRow:0,$size:null,last:{}};var x=this,v=function(c,a){var b=c.cssDisabled,e=!!a,f=e||0===c.page,g=Math.min(c.totalPages,c.filteredPages),e=e||c.page===g-1||0===g;c.updateArrows&&(c.$container.find(c.cssFirst+","+c.cssPrev)[f?"addClass":"removeClass"](b).attr("aria-disabled", f),c.$container.find(c.cssNext+","+c.cssLast)[e?"addClass":"removeClass"](b).attr("aria-disabled",e))},p=function(c,a){var b=c.config,e=b.$table.hasClass("hasFilters");e&&!a.ajaxUrl?h.isEmptyObject(b.cache)?a.filteredRows=a.totalRows=b.$tbodies.eq(0).children("tr").not(a.countChildRows?"":"."+b.cssChildRow).length:(a.filteredRows=0,h.each(b.cache[0].normalized,function(c,e){a.filteredRows+=a.regexRows.test(e[b.columns].$row[0].className)?0:1})):e||(a.filteredRows=a.totalRows)},t=function(c,a,b){if(!a.initializing){var e, f,g,l=c.config;e=a.size||10;a.countChildRows&&f.push(l.cssChildRow);a.totalPages=Math.ceil(a.totalRows/e);l.totalRows=a.totalRows;p(c,a);l.filteredRows=a.filteredRows;a.filteredPages=Math.ceil(a.filteredRows/e)||0;0<=Math.min(a.totalPages,a.filteredPages)&&(f=a.size*a.page>a.filteredRows&&b,a.startRow=f?1:0===a.filteredRows?0:a.size*a.page+1,a.page=f?0:a.page,a.endRow=Math.min(a.filteredRows,a.totalRows,a.size*(a.page+1)),g=a.$container.find(a.cssPageDisplay),e=(a.ajaxData&&a.ajaxData.output?a.ajaxData.output|| a.output:a.output).replace(/\{page([\-+]\d+)?\}/gi,function(d,b){return a.totalPages?a.page+(b?parseInt(b,10):1):0}).replace(/\{\w+(\s*:\s*\w+)?\}/gi,function(d){var b,c;b=d.replace(/[{}\s]/g,"");d=b.split(":");c=a.ajaxData;var e=/(rows?|pages?)$/i.test(b)?0:"";return/(startRow|page)/.test(d[0])&&"input"===d[1]?(b=(""+("page"===d[0]?a.totalPages:a.totalRows)).length,c="page"===d[0]?a.page+1:a.startRow,'<input type="text" class="ts-'+d[0]+'" style="max-width:'+b+'em" value="'+c+'"/>'):1<d.length&& c&&c[d[0]]?c[d[0]][d[1]]:a[b]||(c?c[b]:e)||e}),g.length&&(g["INPUT"===g[0].tagName?"val":"html"](e),a.$goto.length&&(f="",h.each(I(a),function(a,b){f+='<option value="'+b+'">'+b+"</option>"}),a.$goto.html(f).val(a.page+1)),g.find(".ts-startRow, .ts-page").unbind("change").bind("change",function(){var b=h(this).val(),b=h(this).hasClass("ts-startRow")?Math.floor(b/a.size)+1:b;l.$table.trigger("pageSet.pager",[b])})));v(a);D(c,a);a.initialized&&!1!==b&&(l.$table.trigger("pagerComplete",a),a.savePages&& k.storage&&k.storage(c,a.storageKey,{page:a.page,size:a.size}))}},I=function(c){var a,b,e,f,g;g=Math.min(c.totalPages,c.filteredPages)||1;var l=5*Math.ceil(g/c.maxOptionSize/5);e=g>c.maxOptionSize;f=c.page+1;a=l;b=g-l;var d=[1];for(a=e?l:1;a<=g;)d.push(a),a+=e?l:1;d.push(g);if(e){e=[];b=Math.max(Math.floor(c.maxOptionSize/l)-1,5);a=f-b;1>a&&(a=1);b=f+b;for(b>g&&(b=g);a<=b;a++)e.push(a);d=h.grep(d,function(a,b){return h.inArray(a,d)===b});f=d.length;g=e.length;f-g>l/2&&f+g>c.maxOptionSize&&(c=Math.floor(f/ 2)-Math.floor(g/2),Array.prototype.splice.apply(d,[c,g]));d=d.concat(e)}return d=h.grep(d,function(a,b){return h.inArray(a,d)===b}).sort(function(a,b){return a-b})},D=function(c,a){var b,e=c.config,f=e.$tbodies.eq(0);f.find("tr.pagerSavedHeightSpacer").remove();a.fixedHeight&&!a.isDisabled&&(b=h.data(c,"pagerSavedHeight"))&&(b-=f.height(),5<b&&h.data(c,"pagerLastSize")===a.size&&f.children("tr:visible").length<a.size&&f.append('<tr class="pagerSavedHeightSpacer '+e.selectorRemove.slice(1)+'" styl