tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js

7 lines
20 KiB
JavaScript
Raw Normal View History

2018-08-27 16:00:49 +00:00
(function(factory){if (typeof define === 'function' && define.amd){define(['jquery'], factory);} else if (typeof module === 'object' && typeof module.exports === 'object'){module.exports = factory(require('jquery'));} else {factory(jQuery);}}(function(jQuery){
/*!
2016-06-15 16:13:58 +00:00
* tablesorter (FORK) pager plugin
2020-03-03 13:46:03 +00:00
* updated 2020-03-03 (v2.31.3)
2016-06-15 16:13:58 +00:00
*/
2024-08-14 01:18:52 +00:00
!function(E){"use strict";var L=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(e){return e},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:{}};function l(e,t,a,i,s,r){if("function"==typeof a.ajaxProcessing){t.config.$tbodies.eq(0).empty();var o,n,l,g,c,d,p,f,u,h,w,b,R=t.config,z=R.$table,x="",e=a.ajaxProcessing(e,t,i)||[0,[]];if(L.showError(t),r)L.debug(R,"pager")&&console.error("Pager >> Ajax Error",i,s,r),L.showError(t,i,s,r),R.$tbodies.eq(0).children("tr").detach(),a.totalRows=0;else{if(E.isArray(e)?(s=e[(i=isNaN(e[0])&&!isNaN(e[1]))?1:0],a.totalRows=isNaN(s)?a.totalRows||0:s,R.totalRows=R.filteredRows=a.filteredRows=a.totalRows,h=0!==a.totalRows&&e[i?0:1]||[],u=e[2]):(a.ajaxData=e,R.totalRows=a.totalRows=e.total,R.filteredRows=a.filteredRows=void 0!==e.filteredRows?e.filteredRows:e.total,u=e.headers,h=e.rows||[]),w=h&&h.length,h instanceof E)a.processAjaxOnInit&&(R.$tbodies.eq(0).empty(),R.$tbodies.eq(0).append(h));else if(w){for(o=0;o<w;o++){for(x+="<tr>",n=0;n<h[o].length;n++)x+=/^\s*<td/.test(h[o][n])?E.trim(h[o][n]):"<td>"+h[o][n]+"</td>";x+="</tr>"}a.processAjaxOnInit&&R.$tbodies.eq(0).html(x)}if(a.processAjaxOnInit=!0,u)for(c=(l=z.hasClass("hasStickyHeaders"))?R.widgetOptions.$sticky.children("thead:first").children("tr:not(."+R.cssIgnoreRow+")").children():"",g=z.find("tfoot tr:first").children(),b=(d=R.$headers.filter("th ")).length,n=0;n<b;n++)(p=d.eq(n)).find("."+L.css.icon).length?(f=p.find("."+L.css.icon).clone(!0),p.find("."+L.css.headerIn).html(u[n]).append(f),l&&c.length&&(f=c.eq(n).find("."+L.css.icon).clone(!0),c.eq(n).find("."+L.css.headerIn).html(u[n]).append(f))):(p.find("."+L.css.headerIn).html(u[n]),l&&c.length&&(a.$container=a.$container.add(R.widgetOptions.$sticky),c.eq(n).find("."+L.css.headerIn).html(u[n]))),g.eq(n).html(u[n])}R.showProcessing&&L.isProcessing(t),r=N(a,a.size,"get"),a.totalPages="all"===r?1:Math.ceil(a.totalRows/r),a.last.totalRows=a.totalRows,a.last.currentFilters=a.currentFilters,a.last.sortList=(R.sortList||[]).join(","),j(t,a,!1),L.updateCache(R,function(){a.initialized&&setTimeout(function(){L.debug(R,"pager")&&console.log("Pager >> Triggering pagerChange"),z.triggerHandler("pagerChange",a),L.applyWidget(t),j(t,a,!0)},0)})}a.initialized||F(t,a)}function d(e,t){t.page=0,S(e,t)}function u(e,t){t.page=$(e,t)-1,S(e,t)}function p(e,t){t.page++;var a=$(e,t)-1;t.page>=a&&(t.page=a),S(e,t)}function f(e,t){t.page--,t.page<=0&&(t.page=0),S(e,t)}function h(e,t,a){var i,s,r=e.config;t.$container.find(t.cssGoto+","+t.cssPageSize+",.ts-startRow, .ts-page").removeClass(t.cssDisabled).removeAttr("disabled").each(function(){this.ariaDisabled=!1}),t.isDisabled=!1,t.page=E.data(e,"pagerLastPage")||t.page||0,i=(s=t.$container.find(t.cssPageSize)).find("option[selected]").val(),t.size=E.data(e,"pagerLastSize")||N(t,i,"get"),t.totalPages="all"===t.size?1:Math.ceil($(e,t)/t.size),A(e,t.size,t),e.id&&!r.$table.attr("aria-describedby")&&((i=(s=t.$container.find(t.cssPageDisplay)).attr("id"))||(i=e.id+"_pager_info",s.attr("id",i)),r.$table.attr("aria-describedby",i)),P(e,t),a&&(L.update(r),A(e,t.size,t),S(e,t),m(e,t),L.debug(r,"pager"))&&console.log("Pager >> Enabled")}var w=this,b=function(e,t,a){var i="addClass",s="removeClass",r=t.cssDisabled,a=!!a,o=a||0===t.page,e=$(e,t),n=a||t.page===e-1||0===e;t.updateArrows&&((a=t.$container.find(t.cssFirst+","+t.cssPrev))[o?i:s](r),a.each(function(){this.ariaDisabled=o}),(a=t.$container.find(t.cssNext+","+t.c