/* * pagination.js 2.6.0 * A jQuery plugin to provide simple yet fully customisable pagination * https://github.com/superRaytin/paginationjs * Homepage: http://pagination.js.org * * Copyright 2014-2100, superRaytin * Released under the MIT license. */ !function(n,u){void 0===u&&l("Pagination requires jQuery.");var r="pagination",s="__pagination-",D=(u.fn.pagination&&l('plugin conflicted, the name "pagination" has been taken by another jQuery plugin.'),u.fn[r]=function(a){if(void 0!==a){var t,c=u(this),J=u.extend({},u.fn[r].defaults,a),e={initialize:function(){var e,t=this;c.data("pagination")||c.data("pagination",{}),!1!==t.callHook("beforeInit")&&(c.data("pagination").initialized&&u(".paginationjs",c).remove(),t.disabled=!!J.disabled,e=t.model={pageRange:J.pageRange,pageSize:J.pageSize},t.parseDataSource(J.dataSource,function(a){t.isAsync=D.isString(a),D.isArray(a)&&(e.totalNumber=J.totalNumber=a.length),t.isDynamicTotalNumber=t.isAsync&&J.totalNumberLocator;a=t.render(!0);J.className&&a.addClass(J.className),e.el=a,c["bottom"===J.position?"append":"prepend"](a),t.observer(),c.data("pagination").initialized=!0,t.callHook("afterInit",a)}))},render:function(a){var e=this,t=e.model,o=t.el||u('
'),a=!0!==a,t=(e.callHook("beforeRender",a),t.pageNumber||J.pageNumber),i=J.pageRange||0,n=e.getTotalPage(),r=t-i,s=t+i;return(r=n${a}`:`${a}`},generatePageNumbersHTML:function(a){var e,t=a.currentPage,o=this.getTotalPage(),i=this.getPageLinkTag,n=a.rangeStart,r=a.rangeEnd,s="",a=J.ellipsisText,l=J.classPrefix,c=J.pageClassName||"",u=J.activeClassName||"",g=J.disableClassName||"";if(null===J.pageRange)for(e=1;e<=o;e++)s+=e==t?`
  • ${e}
  • `:`
  • ${i(e)}
  • `;else{if(n<=3)for(e=1;e${e}`:`
  • ${i(e)}
  • `;else J.hideFirstOnEllipsisShow||(s+=`
  • ${i(1)}
  • `),s+=`
  • ${a}
  • `;for(e=n;e<=r;e++)s+=e==t?`
  • ${e}
  • `:`
  • ${i(e)}
  • `;if(o-2<=r)for(e=r+1;e<=o;e++)s+=`
  • ${i(e)}
  • `;else s+=`
  • ${a}
  • `,J.hideLastOnEllipsisShow||(s+=`
  • ${i(o)}
  • `)}return s},generateHTML:function(a){var e,t=this,o=a.currentPage,i=t.getTotalPage(),n=t.getPageLinkTag,r=t.getTotalNumber(),s=J.pageSize,l=J.showPrevious,c=J.showNext,u=J.showPageNumbers,g=J.showNavigator,p=J.showSizeChanger,f=J.sizeChangerOptions,d=J.showGoInput,m=J.showGoButton,b=J.prevText,h=J.nextText,v=J.goButtonText,y=J.classPrefix,N=J.disableClassName||"",$=J.ulClassName||"",k=J.prevClassName||"",P=J.nextClassName||"",x="",j='',v=``,T="function"==typeof J.formatSizeChanger?J.formatSizeChanger(o,i,r):J.formatSizeChanger,C="function"==typeof J.formatNavigator?J.formatNavigator(o,i,r):J.formatNavigator,H="function"==typeof J.formatGoInput?J.formatGoInput(S,o,i,r):J.formatGoInput,w="function"==typeof J.formatGoButton?J.formatGoButton(v,o,i,r):J.formatGoButton,O="function"==typeof J.autoHidePrevious?J.autoHidePrevious():J.autoHidePrevious,z="function"==typeof J.autoHideNext?J.autoHideNext():J.autoHideNext,L="function"==typeof J.header?J.header(o,i,r):J.header,E="function"==typeof J.footer?J.footer(o,i,r):J.footer;if(L&&(x+=e=t.replaceVariables(L,{currentPage:o,totalPage:i,totalNumber:r})),g&&C&&(x+=`
    ${e=t.replaceVariables(C,{currentPage:o,totalPage:i,totalNumber:r,rangeStart:(o-1)*s+1,rangeEnd:Math.min(o*s,r)})}
    `),(l||u||c)&&(x=x+'
    '+($?`
      `:"
        "),l&&(o<=1?O||(x+=`
      • ${b}
      • `):x+=`
      • ${n(b)}
      • `),u&&(x+=t.generatePageNumbersHTML(a)),c&&(i<=o?z||(x+=`
      • ${h}
      • `):x+=`
      • ${n(h)}
      • `),x+="
    "),p&&D.isArray(f)){-1===f.indexOf(s)&&(f.unshift(s),f.sort((a,e)=>a-e));for(let a=0;a${f[a]} / page`;e=j+="",x+=`
    ${e=T?t.replaceVariables(T,{length:j,total:r}):e}
    `}return d&&H&&(x+=`
    ${e=t.replaceVariables(H,{currentPage:o,totalPage:i,totalNumber:r,input:S})}
    `),m&&w&&(x+=`
    ${e=t.replaceVariables(w,{currentPage:o,totalPage:i,totalNumber:r,button:v})}
    `),E&&(x+=e=t.replaceVariables(E,{currentPage:o,totalPage:i,totalNumber:r})),x},findTotalNumberFromRemoteResponse:function(a){this.model.totalNumber=J.totalNumberLocator(a)},go:function(a,t){var e,o,i,n,r=this,s=r.model;function l(a){var e;!1!==r.callHook("beforePaging",n)&&(s.direction=void 0===s.pageNumber?0:n>s.pageNumber?1:-1,s.pageNumber=n,r.render(),r.disabled&&r.isAsync&&r.enable(),c.data("pagination").model=s,J.formatResult&&(e=u.extend(!0,[],a),D.isArray(a=J.formatResult(e))||(a=e)),c.data("pagination").currentPageData=a,r.doCallback(a,t),r.callHook("afterPaging",n),1==n?r.callHook("afterIsFirstPage"):n==r.getTotalPage()&&r.callHook("afterIsLastPage"))}r.disabled||(n=a,!(n=parseInt(n)))||n<1||(a=J.pageSize,o=r.getTotalNumber(),i=r.getTotalPage(),0","img"),i=(i||a).replace(t,o);return i},getPagingData:function(a){var e=J.pageSize,t=J.dataSource,o=this.getTotalNumber(),i=e*(a-1)+1,a=Math.min(a*e,o);return t.slice(i-1,a)},getTotalNumber:function(){return this.model.totalNumber||J.totalNumber||0},getTotalPage:function(){return Math.ceil(this.getTotalNumber()/J.pageSize)},getLocator:function(a){var e;return"string"==typeof a?e=a:"function"==typeof a?e=a():l('"locator" is incorrect. Expect string or function type.'),e},filterDataWithLocator:function(t){var o,a=this.getLocator(J.locator);if(D.isObject(t)){try{u.each(a.split("."),function(a,e){o=(o||t)[e]})}catch(a){}o?D.isArray(o)||l("dataSource."+a+" should be an Array."):l("dataSource."+a+" is undefined.")}return o||t},parseDataSource:function(a,e){var t=this;D.isObject(a)?e(J.dataSource=t.filterDataWithLocator(a)):D.isArray(a)?e(J.dataSource=a):"function"==typeof a?J.dataSource(function(a){D.isArray(a)||l('The parameter of "done" Function should be an Array.'),t.parseDataSource.call(t,a,e)}):"string"==typeof a?(/^https?|file:/.test(a)&&(J.ajaxDataType="jsonp"),e(a)):l("Unexpected dataSource type")},callHook:function(a){var t,e=c.data("pagination")||{},o=Array.prototype.slice.apply(arguments);return o.shift(),J[a]&&"function"==typeof J[a]&&!1===J[a].apply(n,o)&&(t=!1),e.hooks&&e.hooks[a]&&u.each(e.hooks[a],function(a,e){!1===e.apply(n,o)&&(t=!1)}),!1!==t},observer:function(){var o=this,t=o.model.el,a=(c.on(s+"go",function(a,e,t){(e="string"==typeof e?parseInt(e.trim()):e)&&("number"!=typeof e&&l('"pageNumber" is incorrect. (Number)'),o.go(e,t))}),t.on("click",".J-paginationjs-page",function(a){var e=u(a.currentTarget),t=e.attr("data-num").trim();if(t&&!e.hasClass(J.disableClassName)&&!e.hasClass(J.activeClassName))return!1!==o.callHook("beforePageOnClick",a,t)&&(o.go(t),o.callHook("afterPageOnClick",a,t),!!J.pageLink)&&void 0}),t.on("click",".J-paginationjs-previous",function(a){var e=u(a.currentTarget),t=e.attr("data-num").trim();if(t&&!e.hasClass(J.disableClassName))return!1!==o.callHook("beforePreviousOnClick",a,t)&&(o.go(t),o.callHook("afterPreviousOnClick",a,t),!!J.pageLink)&&void 0}),t.on("click",".J-paginationjs-next",function(a){var e=u(a.currentTarget),t=e.attr("data-num").trim();if(t&&!e.hasClass(J.disableClassName))return!1!==o.callHook("beforeNextOnClick",a,t)&&(o.go(t),o.callHook("afterNextOnClick",a,t),!!J.pageLink)&&void 0}),t.on("click",".J-paginationjs-go-button",function(a){var e=u(".J-paginationjs-go-pagenumber",t).val();if(!1===o.callHook("beforeGoButtonOnClick",a,e))return!1;c.trigger(s+"go",e),o.callHook("afterGoButtonOnClick",a,e)}),t.on("keyup",".J-paginationjs-go-pagenumber",function(a){if(13===a.which){var e=u(a.currentTarget).val();if(!1===o.callHook("beforeGoInputOnEnter",a,e))return!1;c.trigger(s+"go",e),u(".J-paginationjs-go-pagenumber",t).focus(),o.callHook("afterGoInputOnEnter",a,e)}}),t.on("change",".J-paginationjs-size-select",function(a){var e=u(a.currentTarget),e=parseInt(e.val()),t=o.model.pageNumber||J.pageNumber;if("number"==typeof e)return!1!==o.callHook("beforeSizeSelectorChange",a,e)&&(J.pageSize=e,o.model.pageSize=e,o.model.totalPage=o.getTotalPage(),t>o.model.totalPage&&(t=o.model.totalPage),o.go(t),o.callHook("afterSizeSelectorChange",a,e),!!J.pageLink)&&void 0}),c.on(s+"previous",function(a,e){o.previous(e)}),c.on(s+"next",function(a,e){o.next(e)}),c.on(s+"disable",function(){o.disable()}),c.on(s+"enable",function(){o.enable()}),c.on(s+"refresh",function(a,e){o.refresh(e)}),c.on(s+"show",function(){o.show()}),c.on(s+"hide",function(){o.hide()}),c.on(s+"destroy",function(){o.destroy()}),Math.max(o.getTotalPage(),1)),e=J.pageNumber;o.isDynamicTotalNumber&&J.resetPageNumberOnInit&&(e=1),J.triggerPagingOnInit&&c.trigger(s+"go",Math.min(e,a))}};if(c.data("pagination")&&!0===c.data("pagination").initialized){if(g(a))return c.trigger.call(this,s+"go",a,arguments[1]),this;if("string"==typeof a){var o=Array.prototype.slice.apply(arguments);switch(o[0]=s+o[0],a){case"previous":case"next":case"go":case"disable":case"enable":case"refresh":case"show":case"hide":case"destroy":c.trigger.apply(this,o);break;case"getSelectedPageNum":case"getCurrentPageNum":return(c.data("pagination").model?c.data("pagination").model:c.data("pagination").attributes).pageNumber;case"getTotalPage":return Math.ceil(c.data("pagination").model.totalNumber/c.data("pagination").model.pageSize);case"getSelectedPageData":case"getCurrentPageData":return c.data("pagination").currentPageData;case"isDisabled":return!0===c.data("pagination").model.disabled;default:l("Unknown action: "+a)}return this}t=c,u.each(["go","previous","next","disable","enable","refresh","show","hide","destroy"],function(a,e){t.off(s+e)}),t.data("pagination",{}),u(".paginationjs",t).remove()}else D.isObject(a)||l("Illegal options");var i=J;i.dataSource||l('"dataSource" is required.'),"string"==typeof i.dataSource?void 0===i.totalNumberLocator?void 0===i.totalNumber?l('"totalNumber" is required.'):g(i.totalNumber)||l('"totalNumber" is incorrect. Expect numberic type'):"function"!=typeof i.totalNumberLocator&&l('"totalNumberLocator" should be a Function.'):D.isObject(i.dataSource)&&(void 0===i.locator?l('"dataSource" is an Object, please specify a "locator".'):"string"!=typeof i.locator&&"function"!=typeof i.locator&&l(i.locator+" is incorrect. Expect string or function type")),void 0!==i.formatResult&&"function"!=typeof i.formatResult&&l('"formatResult" should be a Function.'),void 0!==i.onError&&"function"!=typeof i.onError&&l('"onError" should be a Function.'),e.initialize()}return this},u.fn[r].defaults={totalNumber:0,pageNumber:1,pageSize:10,pageRange:2,showPrevious:!0,showNext:!0,showPageNumbers:!0,showNavigator:!1,showGoInput:!1,showGoButton:!1,showSizeChanger:!1,sizeChangerOptions:[10,20,50,100],pageLink:"",prevText:"‹",nextText:"›",ellipsisText:"...",goButtonText:"Go",classPrefix:"paginationjs",activeClassName:"active",disableClassName:"disabled",formatNavigator:"Total <%= totalNumber %> items",formatGoInput:"<%= input %>",formatGoButton:"<%= button %>",position:"bottom",autoHidePrevious:!1,autoHideNext:!1,triggerPagingOnInit:!0,resetPageNumberOnInit:!0,hideOnlyOnePage:!1,hideFirstOnEllipsisShow:!1,hideLastOnEllipsisShow:!1,callback:function(){}},u.fn.addHook=function(a,e){arguments.length<2&&l("Expect 2 arguments at least."),"function"!=typeof e&&l("callback should be a function.");var t=u(this),o=t.data("pagination");o||(t.data("pagination",{}),o=t.data("pagination")),o.hooks||(o.hooks={}),o.hooks[a]=o.hooks[a]||[],o.hooks[a].push(e)},u[r]=function(a,e){var t;if(arguments.length<2&&l("Requires two parameters."),(t="string"!=typeof a&&a instanceof jQuery?a:u(a)).length)return t.pagination(e),t},{});function l(a){throw new Error("Pagination: "+a)}function g(a){return!isNaN(parseFloat(a))&&isFinite(a)}u.each(["Object","Array","String"],function(a,t){D["is"+t]=function(a){return("object"==(e=typeof(a=a))?null==a?"null":Object.prototype.toString.call(a).slice(8,-1):e).toLowerCase()===t.toLowerCase();var e}}),"function"==typeof define&&define.amd&&define(function(){return u})}(this,window.jQuery);