UNPKG

pagination-ui-less

Version:
3 lines (2 loc) 1.34 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e||self).paginationUiLess=n()}(this,function(){return function(e){var n=e.pagesLength,t=void 0===n?1:n,r=e.currentPage,u=void 0===r?1:r,a=e.onChange,i=function(e){u=Number(e);var n=o();return"function"==typeof a&&a(n),n},o=function(){var e=function(){if(u-2<=0)return 1;var e=u+2-t;return e>0?u-2-e:u-2}(),n=Array(5).fill(e).map(function(e,n){var t=e+n;return{isActive:t===u,action:"setPage",value:t}}).filter(function(e){var n=e.value;return n>=1&&n<=t}),r=n.some(function(e){return 1===e.value})?[]:[{action:"setPage",value:1}],a=n.some(function(e){return e.value===t})?[]:[{action:"setPage",value:t}],i=1===u?[]:[{action:"previousPage",value:"Prev"}],o=u===t?[]:[{action:"nextPage",value:"Next"}],f=function(e){return e?[{action:null,value:"..."}]:[]},c=Array.from(n,function(e){return e.value});return{currentPage:u,pages:[].concat(i,r,f(Math.min.apply(Math,c)>2),n,f(Math.max.apply(Math,c)<t-1),a,o)}};return{setPage:i,setPagesLength:function(e,n){return t=e,n&&(u=n),o()},getPages:o,getCurrentPage:function(){return u},nextPage:function(){return i(u+1)},previousPage:function(){return i(u-1)},firstPage:function(){return i(1)},lastPage:function(){return i(t)}}}}); //# sourceMappingURL=index.umd.js.map