mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-12-05 05:04:20 +00:00
5 lines
20 KiB
JavaScript
5 lines
20 KiB
JavaScript
/*!
|
|
* tablesorter (FORK) pager plugin
|
|
* updated 2018-03-26 (v2.30.2)
|
|
*/
|
|
!function(e){"use strict";var t=e.tablesorter;e.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,customAjaxUrl:function(e,t){return t},ajaxError:null,ajaxObject:{dataType:"json"},processAjaxOnInit:!0,ajaxProcessing:function(){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 a="filterInit filterStart filterEnd sortEnd disablePager enablePager destroyPager updateComplete pageSize pageSet pageAndSize pagerUpdate refreshComplete ",i=this,s=function(e,t,a){var i,s="addClass",r="removeClass",o=t.cssDisabled,n=!!a,l=n||0===t.page,g=z(e,t),c=n||t.page===g-1||0===g;t.updateArrows&&((i=t.$container.find(t.cssFirst+","+t.cssPrev))[l?s:r](o),i.each(function(){this.ariaDisabled=l}),(i=t.$container.find(t.cssNext+","+t.cssLast))[c?s:r](o),i.each(function(){this.ariaDisabled=c}))},r=function(e,a){var i,s,r,o=e.config,n=o.$table.hasClass("hasFilters");if(n&&!a.ajax)if(t.isEmptyObject(o.cache))a.filteredRows=a.totalRows=o.$tbodies.eq(0).children("tr").not(a.countChildRows?"":"."+o.cssChildRow).length;else for(a.filteredRows=0,r=(i=o.cache[0].normalized).length,s=0;s<r;s++)a.filteredRows+=a.regexRows.test(i[s][o.columns].$row[0].className)?0:1;else n||(a.filteredRows=a.totalRows)},o=function(a,i,o){if(!i.initializing){var g,c,d,p,f,u,h,w,b=a.config,R=b.namespace+"pager",P=j(i,i.size,"get");if("all"===P&&(P=i.totalRows),i.countChildRows&&(c[c.length]=b.cssChildRow),i.totalPages=Math.ceil(i.totalRows/P),b.totalRows=i.totalRows,x(a,i),r(a,i),b.filteredRows=i.filteredRows,i.filteredPages=Math.ceil(i.filteredRows/P)||0,z(a,i)>=0){if(c=P*i.page>i.filteredRows&&o,i.page=c?i.pageReset||0:i.page,i.startRow=c?P*i.page+1:0===i.filteredRows?0:P*i.page+1,i.endRow=Math.min(i.filteredRows,i.totalRows,P*(i.page+1)),d=i.$container.find(i.cssPageDisplay),"function"==typeof i.output?g=i.output(a,i):(w=d.attr("data-pager-output"+(i.filteredRows<i.totalRows?"-filtered":""))||i.output,g=(i.ajaxData&&i.ajaxData.output?i.ajaxData.output||w:w).replace(/\{page([\-+]\d+)?\}/gi,function(e,t){return i.totalPages?i.page+(t?parseInt(t,10):1):0}).replace(/\{\w+(\s*:\s*\w+)?\}/gi,function(e){var t,a,s=e.replace(/[{}\s]/g,""),r=s.split(":"),o=i.ajaxData,n=/(rows?|pages?)$/i.test(s)?0:"";return/(startRow|page)/.test(r[0])&&"input"===r[1]?(t=(""+("page"===r[0]?i.totalPages:i.totalRows)).length,a="page"===r[0]?i.page+1:i.startRow,'<input type="text" class="ts-'+r[0]+'" style="max-width:'+t+'em" value="'+a+'"/>'):r.length>1&&o&&o[r[0]]?o[r[0]][r[1]]:i[s]||(o?o[s]:n)||n})),(p=i.$container.find(i.cssGoto)).length){for(c="",u=(h=n(a,i)).length,f=0;f<u;f++)c+='<option value="'+h[f]+'">'+h[f]+"</option>";p.html(c).val(i.page+1)}d.length&&(d["INPUT"===d[0].nodeName?"val":"html"](g),d.find(".ts-startRow, .ts-page").unbind("change"+R).bind("change"+R,function(){var t=e(this).val(),a=e(this).hasClass("ts-startRow")?Math.floor(t/P)+1:t;b.$table.triggerHandler("pageSet"+R,[a])}))}s(a,i),l(a,i),i.initialized&&!1!==o&&(t.debug(b,"pager")&&console.log("Pager >> Triggering pagerComplete"),b.$table.triggerHandler("pagerComplete",i),i.savePages&&t.storage&&t.storage(a,i.storageKey,{page:i.page,size:P===i.totalRows?"all":P}))}},n=function(t,a){var i,s,r,o,n,l,g=z(t,a)||1,c=5*Math.ceil(g/a.maxOptionSize/5),d=g>a.maxOptionSize,p=a.page+1,f=c,u=g-c,h=[1];for(i=d?c:1;i<=g;)h[h.length]=i,i+=d?c:1;if(h[h.length]=g,d){for(r=[],(f=p-(s=Math.max(Math.floor(a.maxOptionSize/c)-1,5)))<1&&(f=1),(u=p+s)>g&&(u=g),i=f;i<=u;i++)r[r.length]=i;(n=(h=e.grep(h,function(t,a){return e.inArray(t,h)===a})).length)-(l=r.length)>c/2&&n+l>a.maxOptionSize&&(o=Math.floor(n/2)-Math.floor(l/2),Array.prototype.splice.apply(h,[o,l])),h=h.concat(r)}return h=e.grep(h,function(t,a){return e.inArray(t,h)===a}).sort(function(e,t){return e-t})},l=function(t,a){var i,s,r,o=t.config,n=o.$tbodies.eq(0);n.find("tr.pagerSavedHeightSpacer").remove(),a.fixedHeight&&!a.isDisabled&&(s=e.data(t,"pagerSavedHeight"))&&(r=0,e(t).css("border-spacing").split(" ").length>1&&(r=e(t).css("border-spacing").split(" ")[1].replace(/[^-\d\.]/g,"")),(i=s-n.height()+r*a.size-r)>5&&e.data(t,"pagerLastSize")===a.size&&n.children("tr:visible").length<("all"===a.size?a.totalRows:a.size)&&n.append('<tr class="pagerSavedHeightSpacer '+o.selectorRemove.slice(1)+'" style="height:'+i+'px;"></tr>'))},g=function(t,a){var i,s=t.config,r=s.$tbodies.eq(0);r.find("tr.pagerSavedHeightSpacer").remove(),r.children("tr:visible").length||r.append('<tr class="pagerSavedHeightSpacer '+s.selectorRemove.slice(1)+'"><td> </td></tr>'),i=r.children("tr").eq(0).height()*("all"===a.size?a.totalRows:a.size),e.data(t,"pagerSavedHeight",i),l(t,a),e.data(t,"pagerLastSize",a.size)},c=function(e,a){if(!a.ajaxUrl){var i,s=0,r=e.config,o=r.$tbodies.eq(0).children("tr"),n=o.length,l="all"===a.size?a.totalRows:a.size,g=a.page*l,c=g+l,d=0,p=0;for(a.cacheIndex=[],i=0;i<n;i++)a.regexFiltered.test(o[i].className)||(p===g&&o[i].className.match(r.cssChildRow)?o[i].style.display="none":(o[i].style.display=p>=g&&p<c?"":"none",d!==p&&p>=g&&p<c&&(a.cacheIndex[a.cacheIndex.length]=i,d=p),(p+=o[i].className.match(r.cssChildRow+"|"+r.selectorRemove.slice(1))&&!a.countChildRows?0:1)===c&&"none"!==o[i].style.display&&o[i].className.match(t.css.cssHasChild)&&(s=i)));if(s>0&&o[s].className.match(t.css.cssHasChild))for(;++s<n&&o[s].className.match(r.cssChildRow);)o[s].style.display=""}},d=function(t,a){a.size=j(a,a.$container.find(a.cssPageSize).val(),"get"),P(t,a.size,a),s(t,a),a.removeRows||(c(t,a),e(t).bind("sortEnd filterEnd ".split(" ").join(t.config.namespace+"pager "),function(){c(t,a)}))},p=function(a,i,s,r,n,l){if("function"==typeof s.ajaxProcessing){i.config.$tbodies.eq(0).empty();var g,c,d,p,f,u,h,w,b,R,z,x,P,v,m,y=i.config,C=y.$table,$="",I=s.ajaxProcessing(a,i,r)||[0,[]];if(t.showError(i),l)t.debug(y,"pager")&&console.error("Pager >> Ajax Error",r,n,l),t.showError(i,r,n,l),y.$tbodies.eq(0).children("tr").detach(),s.totalRows=0;else{if(e.isArray(I)?(P=I[(d=isNaN(I[0])&&!isNaN(I[1]))?1:0],s.totalRows=isNaN(P)?s.totalRows||0:P,y.totalRows=y.filteredRows=s.filteredRows=s.totalRows,z=0===s.totalRows?[]:I[d?0:1]||[],R=I[2]):(s.ajaxData=I,y.totalRows=s.totalRows=I.total,y.filteredRows=s.filteredRows=void 0!==I.filteredRows?I.filteredRows:I.total,R=I.headers,z=I.rows||[]),x=z&&z.length,z instanceof e)s.processAjaxOnInit&&(y.$tbodies.eq(0).empty(),y.$tbodies.eq(0).append(z));else if(x){for(g=0;g<x;g++){for($+="<tr>",c=0;c<z[g].length;c++)$+=/^\s*<td/.test(z[g][c])?e.trim(z[g][c]):"<td>"+z[g][c]+"</td>";$+="</tr>"}s.processAjaxOnInit&&y.$tbodies.eq(0).html($)}if(s.processAjaxOnInit=!0,R)for(u=(p=C.hasClass("hasStickyHeaders"))?y.widgetOptions.$sticky.children("thead:first").children("tr:not(."+y.cssIgnoreRow+")").children():"",f=C.find("tfoot tr:first").children(),v=(h=y.$headers.filter("th ")).length,c=0;c<v;c++)(w=h.eq(c)).find("."+t.css.icon).length?(b=w.find("."+t.css.icon).clone(!0),w.find("."+t.css.headerIn).html(R[c]).append(b),p&&u.length&&(b=u.eq(c).find("."+t.css.icon).clone(!0),u.eq(c).find("."+t.css.headerIn).html(R[c]).append(b))):(w.find("."+t.css.headerIn).html(R[c]),p&&u.length&&(s.$container=s.$container.add(y.widgetOptions.$sticky),u.eq(c).find("."+t.css.headerIn).html(R[c]))),f.eq(c).html(R[c])}y.showProcessing&&t.isProcessing(i),m=j(s,s.size,"get"),s.totalPages="all"===m?1:Math.ceil(s.totalRows/m),s.last.totalRows=s.totalRows,s.last.currentFilters=s.currentFilters,s.last.sortList=(y.sortList||[]).join(","),o(i,s,!1),t.updateCache(y,function(){s.initialized&&setTimeout(function(){t.debug(y,"pager")&&console.log("Pager >> Triggering pagerChange"),C.triggerHandler("pagerChange",s),t.applyWidget(i),o(i,s,!0)},0)})}s.initialized||S(i,s)},f=function(a,i){var s,r=u(a,i),o=e(document),n=a.config,l=n.namespace+"pager";""!==r&&(n.showProcessing&&t.isProcessing(a,!0),o.bind("ajaxError"+l,function(e,t,s,r){p(null,a,i,t,s,r),o.unbind("ajaxError"+l)}),s=++i.ajaxCounter,i.last.ajaxUrl=r,i.ajaxObject.url=r,i.ajaxObject.success=function(e,t,r){s<i.ajaxCounter||(p(e,a,i,r),o.unbind("ajaxError"+l),"function"==typeof i.oldAjaxSuccess&&i.oldAjaxSuccess(e))},t.debug(n,"pager")&&console.log("Pager >> Ajax initialized",i.ajaxObject),e.ajax(i.ajaxObject))},u=function(a,i){var s,r,o=a.config,n=i.ajaxUrl?i.ajaxUrl.replace(/\{page([\-+]\d+)?\}/,function(e,t){return i.page+(t?parseInt(t,10):0)}).replace(/\{size\}/g,i.size):"",l=o.sortList,g=i.currentFilters||e(a).data("lastSearch")||[],c=n.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),d=n.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),p=[];if(c){for(c=c[1],r=l.length,s=0;s<r;s++)p[p.length]=c+"["+l[s][0]+"]="+l[s][1];n=n.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g,p.length?p.join("&"):c),p=[]}if(d){for(d=d[1],r=g.length,s=0;s<r;s++)g[s]&&(p[p.length]=d+"["+s+"]="+encodeURIComponent(g[s]));n=n.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g,p.length?p.join("&"):d),i.currentFilters=g}return"function"==typeof i.customAjaxUrl&&(n=i.customAjaxUrl(a,n)),t.debug(o,"pager")&&console.log("Pager >> Ajax url = "+n),n},h=function(a,i,s){var r,n,l,g,d=e(a),p=a.config,f=t.debug(p,"pager"),u=p.$table.hasClass("hasFilters"),h=i&&i.length||0,w="all"===s.size?s.totalRows:s.size,b=s.page*w;if(h<1)f&&console.warn("Pager >> No rows for pager to render");else{if(s.page>=s.totalPages&&m(a,s),s.cacheIndex=[],s.isDisabled=!1,s.initialized&&(f&&console.log("Pager >> Triggering pagerChange"),d.triggerHandler("pagerChange",s)),s.removeRows){for(t.clearTableBody(a),r=t.processTbody(a,p.$tbodies.eq(0),!0),n=u?0:b,l=u?0:b,g=0;g<w&&n<i.length;)u&&s.regexFiltered.test(i[n][0].className)||++l>b&&g<=w&&(g++,s.cacheIndex[s.cacheIndex.length]=n,r.append(i[n])),n++;t.processTbody(a,r,!1)}else c(a,s);o(a,s),a.isUpdating&&(f&&console.log("Pager >> Triggering updateComplete"),d.triggerHandler("updateComplete",[a,!0]))}},w=function(a,i){var r,o,n;for(i.ajax?s(a,i,!0):(e.data(a,"pagerLastPage",i.page),e.data(a,"pagerLastSize",i.size),i.page=0,i.size=i.totalRows,i.totalPages=1,e(a).addClass("pagerDisabled").removeAttr("aria-describedby").find("tr.pagerSavedHeightSpacer").remove(),h(a,a.config.rowsCopy,i),i.isDisabled=!0,t.applyWidget(a),t.debug(a.config,"pager")&&console.log("Pager >> Disabled")),n=(o=i.$container.find(i.cssGoto+","+i.cssPageSize+", .ts-startRow, .ts-page")).length,r=0;r<n;r++)o.eq(r).addClass(i.cssDisabled)[0].disabled=!0,o[r].ariaDisabled=!0},b=function(e){var a=e.config,i=a.pager;t.updateCache(a,function(){var t,s=[],r=e.config.cache[0].normalized;for(i.totalRows=r.length,t=0;t<i.totalRows;t++)s[s.length]=r[t][a.columns].$row;a.rowsCopy=s,R(e,i,!0)})},R=function(a,i,s){if(!i.isDisabled){var o,n=a.config,l=t.debug(n,"pager"),g=e(a),c=i.last;if(!1!==s&&i.initialized&&t.isEmptyObject(n.cache))return b(a);i.ajax&&t.hasWidget(a,"filter")&&!n.widgetOptions.filter_initialized||(x(a,i),r(a,i),c.currentFilters=""===(c.currentFilters||[]).join("")?[]:c.currentFilters,i.currentFilters=""===(i.currentFilters||[]).join("")?[]:i.currentFilters,c.page===i.page&&c.size===i.size&&c.totalRows===i.totalRows&&(c.currentFilters||[]).join(",")===(i.currentFilters||[]).join(",")&&(c.ajaxUrl||"")===(i.ajaxObject.url||"")&&(c.optAjaxUrl||"")===(i.ajaxUrl||"")&&c.sortList===(n.sortList||[]).join(",")||(l&&console.log("Pager >> Changing to page "+i.page),i.last={page:i.page,size:i.size,sortList:(n.sortList||[]).join(","),totalRows:i.totalRows,currentFilters:i.currentFilters||[],ajaxUrl:i.ajaxObject.url||"",optAjaxUrl:i.ajaxUrl||""},i.ajax?i.processAjaxOnInit||t.isEmptyObject(i.initialRows)?f(a,i):(i.processAjaxOnInit=!0,o=i.initialRows,i.totalRows=void 0!==o.total?o.total:l?console.error("Pager >> No initial total page set!")||0:0,i.filteredRows=void 0!==o.filtered?o.filtered:l?console.error("Pager >> No initial filtered page set!")||0:0,S(a,i)):i.ajax||h(a,n.rowsCopy,i),e.data(a,"pagerLastPage",i.page),i.initialized&&!1!==s&&(l&&console.log("Pager >> Triggering pageMoved"),g.triggerHandler("pageMoved",i),t.applyWidget(a),a.isUpdating&&(l&&console.log("Pager >> Triggering updateComplete"),g.triggerHandler("updateComplete",[a,!0])))))}},z=function(e,a){return t.hasWidget(e,"filter")?Math.min(a.totalPages,a.filteredPages):a.totalPages},x=function(e,t){var a=z(e,t)-1;return t.page=parseInt(t.page,10),(t.page<0||isNaN(t.page))&&(t.page=0),t.page>a&&a>=0&&(t.page=a),t.page},j=function(e,t,a){var i=parseInt(t,10)||e.size||e.settings.size||10;return e.initialized&&(/all/i.test(i+" "+t)||i===e.totalRows)?e.$container.find(e.cssPageSize+' option[value="all"]').length?"all":e.totalRows:"get"===a?i:e.size},P=function(t,a,i){i.size=j(i,a,"get"),i.$container.find(i.cssPageSize).val(i.size),e.data(t,"pagerLastPage",x(t,i)),e.data(t,"pagerLastSize",i.size),i.totalPages="all"===i.size?1:Math.ceil(i.totalRows/i.size),i.filteredPages="all"===i.size?1:Math.ceil(i.filteredRows/i.size)},v=function(e,t){t.page=0,R(e,t)},m=function(e,t){t.page=z(e,t)-1,R(e,t)},y=function(e,t){t.page++;var a=z(e,t)-1;t.page>=a&&(t.page=a),R(e,t)},C=function(e,t){--t.page<=0&&(t.page=0),R(e,t)},S=function(a,i){i.initialized=!0,i.initializing=!1,t.debug(a.config,"pager")&&console.log("Pager >> Triggering pagerInitialized"),e(a).triggerHandler("pagerInitialized",i),t.applyWidget(a),o(a,i)},$=function(t,a){t.config.pager=e.extend(!0,{},e.tablesorterPager.defaults,a.settings),A(t,a.settings)},I=function(e,a){var i=e.config,s=i.namespace+"pager",r=[a.cssFirst,a.cssPrev,a.cssNext,a.cssLast,a.cssGoto,a.cssPageSize].join(",");w(e,a),a.$container.hide().find(r).unbind(s),i.appender=null,i.$table.unbind(s),t.storage&&t.storage(e,a.storageKey,""),delete i.pager,delete i.rowsCopy},N=function(a,i,s){var r,o,n,l=a.config;i.$container.find(i.cssGoto+","+i.cssPageSize+",.ts-startRow, .ts-page").removeClass(i.cssDisabled).removeAttr("disabled").each(function(){this.ariaDisabled=!1}),i.isDisabled=!1,i.page=e.data(a,"pagerLastPage")||i.page||0,o=(n=i.$container.find(i.cssPageSize)).find("option[selected]").val(),i.size=e.data(a,"pagerLastSize")||j(i,o,"get"),i.totalPages="all"===i.size?1:Math.ceil(z(a,i)/i.size),P(a,i.size,i),a.id&&!l.$table.attr("aria-describedby")&&((r=(n=i.$container.find(i.cssPageDisplay)).attr("id"))||(r=a.id+"_pager_info",n.attr("id",r)),l.$table.attr("aria-describedby",r)),g(a,i),s&&(t.update(l),P(a,i.size,i),R(a,i),d(a,i),t.debug(l,"pager")&&console.log("Pager >> Enabled"))},A=function(s,r){var n,l,p,f,u=s.config,h=u.widgetOptions,z=t.debug(u,"pager"),x=u.pager=e.extend(!0,{},e.tablesorterPager.defaults,r),S=u.$table,A=u.namespace+"pager",F=x.$container=e(x.container).addClass("tablesorter-pager").show();x.settings=e.extend(!0,{},e.tablesorterPager.defaults,r),z&&console.log("Pager >> Initializing"),x.oldAjaxSuccess=x.oldAjaxSuccess||x.ajaxObject.success,u.appender=i.appender,x.initializing=!0,x.savePages&&t.storage&&(n=t.storage(s,x.storageKey)||{},x.page=isNaN(n.page)?x.page:n.page,x.size="all"===n.size?n.size:(isNaN(n.size)?x.size:n.size)||x.setSize||10,P(s,x.size,x)),x.regexRows=new RegExp("("+(h.filter_filteredRow||"filtered")+"|"+u.selectorRemove.slice(1)+"|"+u.cssChildRow+")"),x.regexFiltered=new RegExp(h.filter_filteredRow||"filtered"),S.unbind(a.split(" ").join(A+" ").replace(/\s+/g," ")).bind("filterInit filterStart ".split(" ").join(A+" "),function(a,i){x.currentFilters=e.isArray(i)?i:u.$table.data("lastSearch");var r;if(x.ajax&&"filterInit"===a.type)return R(s,x,!1);r=t.filter.equalFilters?t.filter.equalFilters(u,u.lastSearch,x.currentFilters):(u.lastSearch||[]).join("")!==(x.currentFilters||[]).join(""),"filterStart"!==a.type||!1===x.pageReset||r||(x.page=x.pageReset)}).bind("filterEnd sortEnd ".split(" ").join(A+" "),function(){x.currentFilters=u.$table.data("lastSearch"),(x.initialized||x.initializing)&&(u.delayInit&&u.rowsCopy&&0===u.rowsCopy.length&&b(s),o(s,x,!1),R(s,x,!1),t.applyWidget(s))}).bind("disablePager"+A,function(e){e.stopPropagation(),w(s,x)}).bind("enablePager"+A,function(e){e.stopPropagation(),N(s,x,!0)}).bind("destroyPager"+A,function(e){e.stopPropagation(),I(s,x)}).bind("resetToLoadState"+A,function(e){e.stopPropagation(),$(s,x)}).bind("updateComplete"+A,function(e,t,a){if(e.stopPropagation(),t&&!a&&!x.ajax){var i=u.$tbodies.eq(0).children("tr").not(u.selectorRemove);x.totalRows=i.length-(x.countChildRows?0:i.filter("."+u.cssChildRow).length),x.totalPages="all"===x.size?1:Math.ceil(x.totalRows/x.size),i.length&&u.rowsCopy&&0===u.rowsCopy.length&&b(t),x.page>=x.totalPages&&m(t,x),c(t,x),g(t,x),o(t,x,!0)}}).bind("pageSize refreshComplete ".split(" ").join(A+" "),function(e,t){e.stopPropagation(),P(s,j(x,t,"get"),x),R(s,x),c(s,x),o(s,x,!1)}).bind("pageSet pagerUpdate ".split(" ").join(A+" "),function(e,t){e.stopPropagation(),"pagerUpdate"===e.type&&(t=void 0===t?x.page+1:t,x.last.page=!0),x.page=(parseInt(t,10)||1)-1,R(s,x,!0),o(s,x,!1)}).bind("pageAndSize"+A,function(e,t,a){e.stopPropagation(),x.page=(parseInt(t,10)||1)-1,P(s,j(x,a,"get"),x),R(s,x,!0),c(s,x),o(s,x,!1)}),l=[x.cssFirst,x.cssPrev,x.cssNext,x.cssLast],p=[v,C,y,m],z&&!F.length&&console.warn('Pager >> "container" not found'),F.find(l.join(",")).attr("tabindex",0).unbind("click"+A).bind("click"+A,function(t){t.stopPropagation();var a,i=e(this),r=l.length;if(!i.hasClass(x.cssDisabled))for(a=0;a<r;a++)if(i.is(l[a])){p[a](s,x);break}}),(f=F.find(x.cssGoto)).length?f.unbind("change"+A).bind("change"+A,function(){x.page=e(this).val()-1,R(s,x,!0),o(s,x,!1)}):z&&console.warn('Pager >> "goto" selector not found'),(f=F.find(x.cssPageSize)).length?(f.find("option").removeAttr("selected"),f.unbind("change"+A).bind("change"+A,function(){if(!e(this).hasClass(x.cssDisabled)){var t=e(this).val();P(s,t,x),R(s,x),g(s,x)}return!1})):z&&console.warn('Pager >> "size" selector not found'),x.initialized=!1,S.triggerHandler("pagerBeforeInitialized",x),N(s,x,!1),"string"==typeof x.ajaxUrl?(x.ajax=!0,u.widgetOptions.filter_serversideFiltering=!0,u.serverSideSorting=!0,R(s,x)):(x.ajax=!1,t.appendCache(u,!0),d(s,x)),x.ajax||x.initialized||(x.initializing=!1,x.initialized=!0,P(s,x.size,x),R(s,x),z&&console.log("Pager >> Triggering pagerInitialized"),u.$table.triggerHandler("pagerInitialized",x),u.widgetOptions.filter_initialized&&t.hasWidget(s,"filter")||o(s,x,!1)),u.widgetInit.pager=!0};i.appender=function(t,a){var i=t.config,s=i.pager;s.ajax||(i.rowsCopy=a,s.totalRows=s.countChildRows?i.$tbodies.eq(0).children("tr").length:a.length,s.size=e.data(t,"pagerLastSize")||s.size||s.settings.size||10,s.totalPages="all"===s.size?1:Math.ceil(s.totalRows/s.size),h(t,a,s),o(t,s,!1))},i.construct=function(e){return this.each(function(){this.config&&this.hasInitialized&&A(this,e)})}}}),t.showError=function(t,a,i,s){var r=e(t),o=r[0].config,n=o&&o.widgetOptions,l=o.pager&&o.pager.cssErrorRow||n&&n.pager_css&&n.pager_css.errorRow||"tablesorter-errorRow",g=typeof a,c=!0,d="",p=function(){o.$table.find("thead").find(o.selectorRemove).remove()};if(r.length){if("function"==typeof o.pager.ajaxError){if(!1===(c=o.pager.ajaxError(o,a,i,s)))return p();d=c}else if("function"==typeof n.pager_ajaxError){if(!1===(c=n.pager_ajaxError(o,a,i,s)))return p();d=c}if(""===d)if("object"===g)d=0===a.status?"Not connected, verify Network":404===a.status?"Requested page not found [404]":500===a.status?"Internal Server Error [500]":"parsererror"===s?"Requested JSON parse failed":"timeout"===s?"Time out error":"abort"===s?"Ajax Request aborted":"Uncaught error: "+a.statusText+" ["+a.status+"]";else{if("string"!==g)return p();d=a}e(/tr\>/.test(d)?d:'<tr><td colspan="'+o.columns+'">'+d+"</td></tr>").click(function(){e(this).remove()}).appendTo(o.$table.find("thead:first")).addClass(l+" "+o.selectorRemove.slice(1)).attr({role:"alert","aria-live":"assertive"})}else console.error("tablesorter showError: no table parameter passed")},e.fn.extend({tablesorterPager:e.tablesorterPager.construct})}(jQuery); |