From c5a35de8788f544ec9509e0454e435151ee61579 Mon Sep 17 00:00:00 2001 From: Taha Shashtari Date: Tue, 17 Jan 2017 20:05:28 +0200 Subject: [PATCH] Build v3.4.0 --- dist/vue-paginate.js | 122 ++++++++++++++++++++++++++++++--------- dist/vue-paginate.min.js | 6 +- package.json | 2 +- 3 files changed, 100 insertions(+), 30 deletions(-) diff --git a/dist/vue-paginate.js b/dist/vue-paginate.js index ce3eb8b..741085b 100644 --- a/dist/vue-paginate.js +++ b/dist/vue-paginate.js @@ -1,5 +1,5 @@ /** - * vue-paginate v3.3.1 + * vue-paginate v3.4.0 * (c) 2017 Taha Shashtari * @license MIT */ @@ -5851,11 +5851,10 @@ this._currentChunkIndex(), this._currentChunkIndex() + this.limit ) - // Add left arrow if needed + // Add backward ellipses with first page if needed if (this.currentPage >= this.limit) { firstHalf.unshift(ELLIPSES) firstHalf.unshift(0) - firstHalf.unshift(LEFT_ARROW) } // Add ellipses if needed if (this.lastPage - this.limit > this._currentChunkIndex()) { @@ -5866,10 +5865,6 @@ LimitedLinksGenerator.prototype._buildSecondHalf = function _buildSecondHalf () { var secondHalf = [this.lastPage] - // Add right arrow if needed - if (this._currentChunkIndex() + this.limit < this.lastPage) { - secondHalf.push(RIGHT_ARROW) - } return secondHalf }; @@ -5899,9 +5894,27 @@ type: Object, default: null, validator: function validator (obj) { - return obj.next && obj.prev + return obj.prev && obj.next } }, + stepLinks: { + type: Object, + default: function () { + return { + prev: LEFT_ARROW, + next: RIGHT_ARROW + } + }, + validator: function validator$1 (obj) { + return obj.prev && obj.next + } + }, + showStepLinks: { + type: Boolean + }, + hideSinglePage: { + type: Boolean + }, classes: { type: Object, default: null @@ -5909,7 +5922,8 @@ }, data: function data () { return { - listOfPages: [] + listOfPages: [], + numberOfPages: 0 } }, computed: { @@ -5936,6 +5950,12 @@ if (this.simple && !this.simple.prev) { warn((" 'simple' prop doesn't contain 'prev' value."), this.$parent) } + if (this.stepLinks && !this.stepLinks.next) { + warn((" 'step-links' prop doesn't contain 'next' value."), this.$parent) + } + if (this.stepLinks && !this.stepLinks.prev) { + warn((" 'step-links' prop doesn't contain 'prev' value."), this.$parent) + } vue_runtime_common.nextTick(function () { this$1.updateListOfPages() }) @@ -5958,8 +5978,8 @@ warn((" can't be used without its companion "), this.$parent) return } - var numberOfPages = Math.ceil(target.list.length / target.per) - this.listOfPages = getListOfPageNumbers(numberOfPages) + this.numberOfPages = Math.ceil(target.list.length / target.per) + this.listOfPages = getListOfPageNumbers(this.numberOfPages) } }, render: function render (h) { @@ -5971,6 +5991,10 @@ ? getLimitedLinks(this, h) : getFullLinks(this, h) + if (this.hideSinglePage && this.numberOfPages <= 1) { + return null + } + var el = h('ul', { class: ['paginate-links', this.for] }, links) @@ -5980,23 +6004,39 @@ addAdditionalClasses(el.elm, this$1.classes) }) } - return el } } function getFullLinks (vm, h) { - return vm.listOfPages.map(function (number) { + var allLinks = vm.showStepLinks + ? [vm.stepLinks.prev ].concat( vm.listOfPages, [vm.stepLinks.next]) + : vm.listOfPages + return allLinks.map(function (link) { var data = { on: { click: function (e) { e.preventDefault() - vm.currentPage = number + vm.currentPage = getTargetPageForLink( + link, + vm.limit, + vm.currentPage, + vm.listOfPages, + vm.stepLinks + ) } } } - var liClass = vm.currentPage === number ? 'active' : '' - return h('li', { class: liClass }, [h('a', data, number + 1)]) + var liClasses = getClassesForLink( + link, + vm.currentPage, + vm.listOfPages.length - 1, + vm.stepLinks + ) + var linkText = link === vm.stepLinks.next || link === vm.stepLinks.prev + ? link + : link + 1 // it means it's a number + return h('li', { class: liClasses }, [h('a', data, linkText)]) }) } @@ -6004,9 +6044,14 @@ var limitedLinks = new LimitedLinksGenerator( vm.listOfPages, vm.currentPage, - vm.limit + vm.limit, + vm.stepLinks ).generate() + limitedLinks = vm.showStepLinks + ? [vm.stepLinks.prev ].concat( limitedLinks, [vm.stepLinks.next]) + : limitedLinks + var limitedLinksMetadata = getLimitedLinksMetadata(limitedLinks) return limitedLinks.map(function (link, index) { @@ -6018,13 +6063,19 @@ link, vm.limit, vm.currentPage, - limitedLinksMetadata[index], - vm.listOfPages + vm.listOfPages, + vm.stepLinks, + limitedLinksMetadata[index] ) } } } - var liClasses = getClassesForLink(link, vm.currentPage) + var liClasses = getClassesForLink( + link, + vm.currentPage, + vm.listOfPages.length - 1, + vm.stepLinks + ) // If the link is a number, // then incremented by 1 (since it's 0 based). // otherwise, do nothing (so, it's a symbol). @@ -6072,11 +6123,14 @@ .map(function (val, index) { return index; }) } - function getClassesForLink(link, currentPage) { + function getClassesForLink(link, currentPage, lastPage, ref) { + var prev = ref.prev; + var next = ref.next; + var liClass = [] - if (link === LEFT_ARROW) { + if (link === prev) { liClass.push('left-arrow') - } else if (link === RIGHT_ARROW) { + } else if (link === next) { liClass.push('right-arrow') } else if (link === ELLIPSES) { liClass.push('ellipses') @@ -6087,14 +6141,30 @@ if (link === currentPage) { liClass.push('active') } + + if (link === prev && currentPage <= 0) { + liClass.push('disabled') + } else if (link === next && currentPage >= lastPage) { + liClass.push('disabled') + } return liClass } - function getTargetPageForLink (link, limit, currentPage, metaData, listOfPages) { + function getTargetPageForLink (link, limit, currentPage, listOfPages, ref, metaData) { + var prev = ref.prev; + var next = ref.next; + if ( metaData === void 0 ) metaData = null; + var currentChunk = Math.floor(currentPage / limit) - if (link === RIGHT_ARROW || metaData === 'right-ellipses') { + if (link === prev) { + return (currentPage - 1) < 0 ? 0 : currentPage - 1 + } else if (link === next) { + return (currentPage + 1 > listOfPages.length - 1) + ? listOfPages.length - 1 + : currentPage + 1 + } else if (metaData && metaData === 'right-ellipses') { return (currentChunk + 1) * limit - } else if (link === LEFT_ARROW || metaData === 'left-ellipses') { + } else if (metaData && metaData === 'left-ellipses') { var chunkContent = listOfPages.slice(currentChunk * limit, currentChunk * limit + limit) var isLastPage = currentPage === listOfPages.length - 1 if (isLastPage && chunkContent.length === 1) { diff --git a/dist/vue-paginate.min.js b/dist/vue-paginate.min.js index 01fd0a1..929050d 100644 --- a/dist/vue-paginate.min.js +++ b/dist/vue-paginate.min.js @@ -1,7 +1,7 @@ /** - * vue-paginate v3.3.1 + * vue-paginate v3.4.0 * (c) 2017 Taha Shashtari * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VuePaginate=e()}(this,function(){"use strict";function t(t){return null==t?"":"object"==typeof t?JSON.stringify(t,null,2):String(t)}function e(t){var e=parseFloat(t,10);return e||0===e?e:t}function n(t,e){for(var n=Object.create(null),r=t.split(","),i=0;i-1)return t.splice(n,1)}}function i(t,e){return Nn.call(t,e)}function o(t){return"string"==typeof t||"number"==typeof t}function a(t){var e=Object.create(null);return function(n){var r=e[n];return r||(e[n]=t(n))}}function s(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n}function u(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function c(t,e){for(var n in e)t[n]=e[n];return t}function l(t){return null!==t&&"object"==typeof t}function f(t){return Hn.call(t)===Rn}function p(t){for(var e={},n=0;n=0&&gr[n].id>t.id;)n--;gr.splice(Math.max(n,wr)+1,0,t)}else gr.push(t);_r||(_r=!0,rr(R))}}function z(t){xr.clear(),q(t,xr)}function q(t,e){var n,r,i=Array.isArray(t);if((i||l(t))&&Object.isExtensible(t)){if(t.__ob__){var o=t.__ob__.dep.id;if(e.has(o))return;e.add(o)}if(i)for(n=t.length;n--;)q(t[n],e);else for(r=Object.keys(t),n=r.length;n--;)q(t[r[n]],e)}}function K(t){t._watchers=[];var e=t.$options;e.props&&W(t,e.props),e.methods&&Q(t,e.methods),e.data?J(t):x(t._data={},!0),e.computed&&G(t,e.computed),e.watch&&X(t,e.watch)}function W(t,e){var n=t.$options.propsData||{},r=t.$options._propKeys=Object.keys(e),i=!t.$parent;pr.shouldConvert=i;for(var o=function(i){var o=r[i];A(t,o,I(o,e,n,t))},a=0;a1?u(n):n;for(var r=u(arguments,1),i=0,o=n.length;i-1:t.test(e)}function Jt(t){var e={};e.get=function(){return qn},Object.defineProperty(t,"config",e),t.util=mr,t.set=O,t.delete=S,t.nextTick=rr,t.options=Object.create(null),qn._assetTypes.forEach(function(e){t.options[e+"s"]=Object.create(null)}),t.options._base=t,c(t.options.components,Ir),Ft(t),zt(t),qt(t),Kt(t)}function Gt(t){for(var e=t.data,n=t,r=t;r.child;)r=r.child._vnode,r.data&&(e=Zt(r.data,e));for(;n=n.parent;)n.data&&(e=Zt(e,n.data));return Qt(e)}function Zt(t,e){return{staticClass:Xt(t.staticClass,e.staticClass),class:t.class?[t.class,e.class]:e.class}}function Qt(t){var e=t.class,n=t.staticClass;return n||e?Xt(n,Yt(e)):""}function Xt(t,e){return t?e?t+" "+e:t:e||""}function Yt(t){var e="";if(!t)return e;if("string"==typeof t)return t;if(Array.isArray(t)){for(var n,r=0,i=t.length;r-1?Xr[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:Xr[t]=/HTMLUnknownElement/.test(e.toString())}function ne(t){if("string"==typeof t){if(t=document.querySelector(t),!t)return document.createElement("div")}return t}function re(t,e){var n=document.createElement(t);return"select"!==t?n:(e.data&&e.data.attrs&&"multiple"in e.data.attrs&&n.setAttribute("multiple","multiple"),n)}function ie(t,e){return document.createElementNS(Jr[t],e)}function oe(t){return document.createTextNode(t)}function ae(t){return document.createComment(t)}function se(t,e,n){t.insertBefore(e,n)}function ue(t,e){t.removeChild(e)}function ce(t,e){t.appendChild(e)}function le(t){return t.parentNode}function fe(t){return t.nextSibling}function pe(t){return t.tagName}function de(t,e){t.textContent=e}function he(t,e,n){t.setAttribute(e,n)}function ve(t,e){var n=t.data.ref;if(n){var i=t.context,o=t.child||t.elm,a=i.$refs;e?Array.isArray(a[n])?r(a[n],o):a[n]===o&&(a[n]=void 0):t.data.refInFor?Array.isArray(a[n])&&a[n].indexOf(o)<0?a[n].push(o):a[n]=[o]:a[n]=o}}function me(t){return null==t}function ge(t){return null!=t}function ye(t,e){return t.key===e.key&&t.tag===e.tag&&t.isComment===e.isComment&&!t.data==!e.data}function _e(t,e,n){var r,i,o={};for(r=e;r<=n;++r)i=t[r].key,ge(i)&&(o[i]=r);return o}function be(t){function e(t){return new Or(O.tagName(t).toLowerCase(),{},[],void 0,t)}function r(t,e){function n(){0===--n.listeners&&i(t)}return n.listeners=e,n}function i(t){var e=O.parentNode(t);e&&O.removeChild(e,t)}function a(t,e,n,r,i){if(t.isRootInsert=!i,!s(t,e,n,r)){var o=t.data,a=t.children,u=t.tag;ge(u)?(t.elm=t.ns?O.createElementNS(t.ns,u):O.createElement(u,t),h(t),l(t,a,e),ge(o)&&p(t,e),c(n,t.elm,r)):t.isComment?(t.elm=O.createComment(t.text),c(n,t.elm,r)):(t.elm=O.createTextNode(t.text),c(n,t.elm,r))}}function s(t,e,n,r){var i=t.data;if(ge(i)){var o=ge(t.child)&&i.keepAlive;if(ge(i=i.hook)&&ge(i=i.init)&&i(t,!1,n,r),ge(t.child))return d(t,e),o&&u(t,e,n,r),!0}}function u(t,e,n,r){for(var i,o=t;o.child;)if(o=o.child._vnode,ge(i=o.data)&&ge(i=i.transition)){for(i=0;ip?(c=me(n[m+1])?null:n[m+1].elm,v(t,c,n,f,m,r)):f>m&&g(t,e,l,p)}function b(t,e,n,r){if(t!==e){if(e.isStatic&&t.isStatic&&e.key===t.key&&(e.isCloned||e.isOnce))return e.elm=t.elm,void(e.child=t.child);var i,o=e.data,a=ge(o);a&&ge(i=o.hook)&&ge(i=i.prepatch)&&i(t,e);var s=e.elm=t.elm,u=t.children,c=e.children;if(a&&f(e)){for(i=0;i-1?e.split(/\s+/).forEach(function(e){return t.classList.add(e)}):t.classList.add(e);else{var n=" "+t.getAttribute("class")+" ";n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function He(t,e){if(e&&e.trim())if(t.classList)e.indexOf(" ")>-1?e.split(/\s+/).forEach(function(e){return t.classList.remove(e)}):t.classList.remove(e);else{for(var n=" "+t.getAttribute("class")+" ",r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");t.setAttribute("class",n.trim())}}function Re(t){ki(function(){ki(t)})}function Fe(t,e){(t._transitionClasses||(t._transitionClasses=[])).push(e),Be(t,e)}function ze(t,e){t._transitionClasses&&r(t._transitionClasses,e),He(t,e)}function qe(t,e,n){var r=Ke(t,e),i=r.type,o=r.timeout,a=r.propCount;if(!i)return n();var s=i===yi?wi:$i,u=0,c=function(){t.removeEventListener(s,l),n()},l=function(e){e.target===t&&++u>=a&&c()};setTimeout(function(){u0&&(n=yi,l=a,f=o.length):e===_i?c>0&&(n=_i,l=c,f=u.length):(l=Math.max(a,c),n=l>0?a>c?yi:_i:null,f=n?n===yi?o.length:u.length:0);var p=n===yi&&xi.test(r[bi+"Property"]);return{type:n,timeout:l,propCount:f,hasTransform:p}}function We(t,e){for(;t.length1,j=n._enterCb=Xe(function(){E&&(ze(n,x),ze(n,k)),j.cancelled?(E&&ze(n,$),P&&P(n)):S&&S(n),n._enterCb=null});t.data.show||ot(t.data.hook||(t.data.hook={}),"insert",function(){var e=n.parentNode,r=e&&e._pending&&e._pending[t.key];r&&r.context===t.context&&r.tag===t.tag&&r.elm._leaveCb&&r.elm._leaveCb(),O&&O(n,j)},"transition-insert"),A&&A(n),E&&(Fe(n,$),Fe(n,k),Re(function(){Fe(n,x),ze(n,$),j.cancelled||T||qe(n,o,j)})),t.data.show&&(e&&e(),O&&O(n,j)),E||T||j()}}}function Ze(t,e){function n(){g.cancelled||(t.data.show||((r.parentNode._pending||(r.parentNode._pending={}))[t.key]=t),l&&l(r),v&&(Fe(r,s),Fe(r,c),Re(function(){Fe(r,u),ze(r,s),g.cancelled||m||qe(r,a,g)})),f&&f(r,g),v||m||g())}var r=t.elm;r._enterCb&&(r._enterCb.cancelled=!0,r._enterCb());var i=Qe(t.data.transition);if(!i)return e();if(!r._leaveCb&&1===r.nodeType){var o=i.css,a=i.type,s=i.leaveClass,u=i.leaveToClass,c=i.leaveActiveClass,l=i.beforeLeave,f=i.leave,p=i.afterLeave,d=i.leaveCancelled,h=i.delayLeave,v=o!==!1&&!Qn,m=f&&(f._length||f.length)>1,g=r._leaveCb=Xe(function(){r.parentNode&&r.parentNode._pending&&(r.parentNode._pending[t.key]=null),v&&(ze(r,u),ze(r,c)),g.cancelled?(v&&ze(r,s),d&&d(r)):(e(),p&&p(r)),r._leaveCb=null});h?h(n):n()}}function Qe(t){if(t){if("object"==typeof t){var e={};return t.css!==!1&&c(e,Ai(t.name||"v")),c(e,t),e}return"string"==typeof t?Ai(t):void 0}}function Xe(t){var e=!1;return function(){e||(e=!0,t())}}function Ye(t,e){e.data.show||Ge(e)}function tn(t,e,n){var r=e.value,i=t.multiple;if(!i||Array.isArray(r)){for(var o,a,s=0,u=t.options.length;s-1,a.selected!==o&&(a.selected=o);else if(v(nn(a),r))return void(t.selectedIndex!==s&&(t.selectedIndex=s));i||(t.selectedIndex=-1)}}function en(t,e){for(var n=0,r=e.length;n0&&(t.currentPage-=1)}}},i={on:{click:function(e){e.preventDefault(),t.currentPage=n?"disabled":""]},a={class:["prev",t.currentPage<=0?"disabled":""]},s=e("li",a,[e("a",r,t.simple.prev)]),u=e("li",o,[e("a",i,t.simple.next)]);return[s,u]}function _n(t,e){return t.filter(function(t){return"paginate"===t.$vnode.componentOptions.tag}).find(function(t){return t.name===e})}function bn(t){return Array.apply(null,{length:t}).map(function(t,e){return e})}function wn(t,e){var n=[];return t===Bi?n.push("left-arrow"):t===Hi?n.push("right-arrow"):t===Ri?n.push("ellipses"):n.push("number"),t===e&&n.push("active"),n}function Cn(t,e,n,r,i){var o=Math.floor(n/e);if(t===Hi||"right-ellipses"===r)return(o+1)*e;if(t===Bi||"left-ellipses"===r){var a=i.slice(o*e,o*e+e),s=n===i.length-1;return s&&1===a.length&&o--,(o-1)*e+e-1}return t}function $n(t){return t.map(function(e,n){return e===Ri&&0===t[n-1]?"left-ellipses":e===Ri&&0!==t[n-1]?"right-ellipses":e})}function kn(t,e){Object.keys(e).forEach(function(n){if("ul"===n){var r=e.ul;Array.isArray(r)?r.forEach(function(e){return t.classList.add(e)}):t.classList.add(r)}t.querySelectorAll(n).forEach(function(t){var r=e[n];Array.isArray(r)?r.forEach(function(e){return t.classList.add(e)}):t.classList.add(r)})})}function xn(t){return void 0===t&&(t=[]),t.reduce(function(t,e){return t[e]={list:[],page:0},t},{})}var An,On=function(){},Sn="undefined"!=typeof console;On=function(t,e,n){void 0===n&&(n="error"),Sn&&console[n]("[vue-paginate]: "+t+" "+(e?Tn(An(e)):""))},An=function(t){if(t.$root===t)return"root instance";var e=t._isVue?t.$options.name||t.$options._componentTag:t.name;return(e?"component <"+e+">":"anonymous component")+(t._isVue&&t.$options.__file?" at "+t.$options.__file:"")};var Pn,En,Tn=function(t){return"anonymous component"===t&&(t+=' - use the "name" option for better debugging messages.'),"\n(found in "+t+")"},jn={name:"paginate",props:{name:{type:String,required:!0},list:{type:Array,required:!0},per:{type:Number,default:3,validator:function(t){return t>0}},tag:{type:String,default:"ul"},class:{type:String}},data:function(){return{}},computed:{currentPage:{get:function(){if(this.$parent.paginate[this.name])return this.$parent.paginate[this.name].page},set:function(t){this.$parent.paginate[this.name].page=t}}},mounted:function(){return this.per<=0&&On(' 'per' prop can't be 0 or less.",this.$parent),this.$parent.paginate[this.name]?void this.paginateList():void On("'"+this.name+"' is not registered in 'paginate' array.",this.$parent)},watch:{currentPage:function(){this.paginateList()},list:function(){this.currentPage=0,this.paginateList()},per:function(){this.currentPage=0,this.paginateList()}},methods:{paginateList:function(){var t=this.currentPage*this.per,e=this.list.slice(t,t+this.per);this.$parent.paginate[this.name].list=e}},render:function(t){var e=this.class?this.class:"";return t(this.tag,{class:e},this.$slots.default)}},Dn="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},Ln=n("slot,component",!0),Nn=Object.prototype.hasOwnProperty,Mn=/-(\w)/g,In=a(function(t){return t.replace(Mn,function(t,e){return e?e.toUpperCase():""})}),Un=a(function(t){return t.charAt(0).toUpperCase()+t.slice(1)}),Vn=/([^-])([A-Z])/g,Bn=a(function(t){return t.replace(Vn,"$1-$2").replace(Vn,"$1-$2").toLowerCase()}),Hn=Object.prototype.toString,Rn="[object Object]",Fn=function(){return!1},zn=function(t){return t},qn={optionMergeStrategies:Object.create(null),silent:!1,devtools:!1,errorHandler:null,ignoredElements:[],keyCodes:Object.create(null),isReservedTag:Fn,isUnknownElement:Fn,getTagNamespace:d,parsePlatformTagName:zn,mustUseProp:Fn,_assetTypes:["component","directive","filter"],_lifecycleHooks:["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated"],_maxUpdateCount:100},Kn=/[^\w.$]/,Wn="__proto__"in{},Jn="undefined"!=typeof window,Gn=Jn&&window.navigator.userAgent.toLowerCase(),Zn=Gn&&/msie|trident/.test(Gn),Qn=Gn&&Gn.indexOf("msie 9.0")>0,Xn=Gn&&Gn.indexOf("edge/")>0,Yn=Gn&&Gn.indexOf("android")>0,tr=Gn&&/iphone|ipad|ipod|ios/.test(Gn),er=function(){return void 0===Pn&&(Pn=!Jn&&"undefined"!=typeof Dn&&"server"===Dn.process.env.VUE_ENV),Pn},nr=Jn&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,rr=function(){function t(){r=!1;var t=n.slice(0);n.length=0;for(var e=0;e1&&(e[n[0].trim()]=n[1].trim())}}),e}),fi=/^--/,pi=/\s*!important$/,di=function(t,e,n){fi.test(e)?t.style.setProperty(e,n):pi.test(n)?t.style.setProperty(e,n.replace(pi,""),"important"):t.style[vi(e)]=n},hi=["Webkit","Moz","ms"],vi=a(function(t){if(Vr=Vr||document.createElement("div"),t=In(t),"filter"!==t&&t in Vr.style)return t;for(var e=t.charAt(0).toUpperCase()+t.slice(1),n=0;n=this.limit&&(t.unshift(Ri),t.unshift(0),t.unshift(Bi)),this.lastPage-this.limit>this._currentChunkIndex()&&t.push(Ri),t},Fi.prototype._buildSecondHalf=function(){var t=[this.lastPage];return this._currentChunkIndex()+this.limit 'simple' and 'limit' props can't be used at the same time. In this case, 'simple' will take precedence, and 'limit' will be ignored.",this.$parent,"warn"),this.simple&&!this.simple.next&&On(' 'simple' prop doesn't contain 'next' value.",this.$parent),this.simple&&!this.simple.prev&&On(' 'simple' prop doesn't contain 'prev' value.",this.$parent),Vi.nextTick(function(){t.updateListOfPages()})},watch:{"$parent.paginate":{handler:function(){this.updateListOfPages()},deep:!0},currentPage:function(t,e){this.$emit("change",t+1,e+1)}},methods:{updateListOfPages:function(){var t=_n(this.$parent.$children,this.for);if(!t)return void On(' can\'t be used without its companion ',this.$parent);var e=Math.ceil(t.list.length/t.per);this.listOfPages=bn(e)}},render:function(t){var e=this,n=this.simple?yn(this,t):this.limit>1?gn(this,t):mn(this,t),r=t("ul",{class:["paginate-links",this.for]},n);return this.classes&&Vi.nextTick(function(){kn(r.elm,e.classes)}),r}},qi={};return qi.install=function(t){t.mixin({created:function(){"undefined"!==this.paginate&&this.paginate instanceof Array&&(this.paginate=xn(this.paginate))},methods:{paginated:function(t){return this.paginate&&this.paginate[t]?this.paginate[t].list:void On("'"+t+"' is not registered in 'paginate' array.",this)}}}),t.component("paginate",jn),t.component("paginate-links",zi)},"undefined"!=typeof window&&window.Vue&&window.Vue.use(qi),qi}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VuePaginate=e()}(this,function(){"use strict";function t(t){return null==t?"":"object"==typeof t?JSON.stringify(t,null,2):String(t)}function e(t){var e=parseFloat(t,10);return e||0===e?e:t}function n(t,e){for(var n=Object.create(null),r=t.split(","),i=0;i-1)return t.splice(n,1)}}function i(t,e){return Nn.call(t,e)}function o(t){return"string"==typeof t||"number"==typeof t}function a(t){var e=Object.create(null);return function(n){var r=e[n];return r||(e[n]=t(n))}}function s(t,e){function n(n){var r=arguments.length;return r?r>1?t.apply(e,arguments):t.call(e,n):t.call(e)}return n._length=t.length,n}function u(t,e){e=e||0;for(var n=t.length-e,r=new Array(n);n--;)r[n]=t[n+e];return r}function l(t,e){for(var n in e)t[n]=e[n];return t}function c(t){return null!==t&&"object"==typeof t}function f(t){return Hn.call(t)===Rn}function p(t){for(var e={},n=0;n=0&&mr[n].id>t.id;)n--;mr.splice(Math.max(n,kr)+1,0,t)}else mr.push(t);_r||(_r=!0,rr(R))}}function z(t){xr.clear(),q(t,xr)}function q(t,e){var n,r,i=Array.isArray(t);if((i||c(t))&&Object.isExtensible(t)){if(t.__ob__){var o=t.__ob__.dep.id;if(e.has(o))return;e.add(o)}if(i)for(n=t.length;n--;)q(t[n],e);else for(r=Object.keys(t),n=r.length;n--;)q(t[r[n]],e)}}function K(t){t._watchers=[];var e=t.$options;e.props&&W(t,e.props),e.methods&&Q(t,e.methods),e.data?J(t):x(t._data={},!0),e.computed&&G(t,e.computed),e.watch&&X(t,e.watch)}function W(t,e){var n=t.$options.propsData||{},r=t.$options._propKeys=Object.keys(e),i=!t.$parent;pr.shouldConvert=i;for(var o=function(i){var o=r[i];A(t,o,I(o,e,n,t))},a=0;a1?u(n):n;for(var r=u(arguments,1),i=0,o=n.length;i-1:t.test(e)}function Jt(t){var e={};e.get=function(){return qn},Object.defineProperty(t,"config",e),t.util=gr,t.set=O,t.delete=P,t.nextTick=rr,t.options=Object.create(null),qn._assetTypes.forEach(function(e){t.options[e+"s"]=Object.create(null)}),t.options._base=t,l(t.options.components,Ir),Ft(t),zt(t),qt(t),Kt(t)}function Gt(t){for(var e=t.data,n=t,r=t;r.child;)r=r.child._vnode,r.data&&(e=Zt(r.data,e));for(;n=n.parent;)n.data&&(e=Zt(e,n.data));return Qt(e)}function Zt(t,e){return{staticClass:Xt(t.staticClass,e.staticClass),class:t.class?[t.class,e.class]:e.class}}function Qt(t){var e=t.class,n=t.staticClass;return n||e?Xt(n,Yt(e)):""}function Xt(t,e){return t?e?t+" "+e:t:e||""}function Yt(t){var e="";if(!t)return e;if("string"==typeof t)return t;if(Array.isArray(t)){for(var n,r=0,i=t.length;r-1?Xr[t]=e.constructor===window.HTMLUnknownElement||e.constructor===window.HTMLElement:Xr[t]=/HTMLUnknownElement/.test(e.toString())}function ne(t){if("string"==typeof t){if(t=document.querySelector(t),!t)return document.createElement("div")}return t}function re(t,e){var n=document.createElement(t);return"select"!==t?n:(e.data&&e.data.attrs&&"multiple"in e.data.attrs&&n.setAttribute("multiple","multiple"),n)}function ie(t,e){return document.createElementNS(Jr[t],e)}function oe(t){return document.createTextNode(t)}function ae(t){return document.createComment(t)}function se(t,e,n){t.insertBefore(e,n)}function ue(t,e){t.removeChild(e)}function le(t,e){t.appendChild(e)}function ce(t){return t.parentNode}function fe(t){return t.nextSibling}function pe(t){return t.tagName}function de(t,e){t.textContent=e}function he(t,e,n){t.setAttribute(e,n)}function ve(t,e){var n=t.data.ref;if(n){var i=t.context,o=t.child||t.elm,a=i.$refs;e?Array.isArray(a[n])?r(a[n],o):a[n]===o&&(a[n]=void 0):t.data.refInFor?Array.isArray(a[n])&&a[n].indexOf(o)<0?a[n].push(o):a[n]=[o]:a[n]=o}}function ge(t){return null==t}function me(t){return null!=t}function ye(t,e){return t.key===e.key&&t.tag===e.tag&&t.isComment===e.isComment&&!t.data==!e.data}function _e(t,e,n){var r,i,o={};for(r=e;r<=n;++r)i=t[r].key,me(i)&&(o[i]=r);return o}function be(t){function e(t){return new Or(O.tagName(t).toLowerCase(),{},[],void 0,t)}function r(t,e){function n(){0===--n.listeners&&i(t)}return n.listeners=e,n}function i(t){var e=O.parentNode(t);e&&O.removeChild(e,t)}function a(t,e,n,r,i){if(t.isRootInsert=!i,!s(t,e,n,r)){var o=t.data,a=t.children,u=t.tag;me(u)?(t.elm=t.ns?O.createElementNS(t.ns,u):O.createElement(u,t),h(t),c(t,a,e),me(o)&&p(t,e),l(n,t.elm,r)):t.isComment?(t.elm=O.createComment(t.text),l(n,t.elm,r)):(t.elm=O.createTextNode(t.text),l(n,t.elm,r))}}function s(t,e,n,r){var i=t.data;if(me(i)){var o=me(t.child)&&i.keepAlive;if(me(i=i.hook)&&me(i=i.init)&&i(t,!1,n,r),me(t.child))return d(t,e),o&&u(t,e,n,r),!0}}function u(t,e,n,r){for(var i,o=t;o.child;)if(o=o.child._vnode,me(i=o.data)&&me(i=i.transition)){for(i=0;ip?(l=ge(n[g+1])?null:n[g+1].elm,v(t,l,n,f,g,r)):f>g&&m(t,e,c,p)}function b(t,e,n,r){if(t!==e){if(e.isStatic&&t.isStatic&&e.key===t.key&&(e.isCloned||e.isOnce))return e.elm=t.elm,void(e.child=t.child);var i,o=e.data,a=me(o);a&&me(i=o.hook)&&me(i=i.prepatch)&&i(t,e);var s=e.elm=t.elm,u=t.children,l=e.children;if(a&&f(e)){for(i=0;i-1?e.split(/\s+/).forEach(function(e){return t.classList.add(e)}):t.classList.add(e);else{var n=" "+t.getAttribute("class")+" ";n.indexOf(" "+e+" ")<0&&t.setAttribute("class",(n+e).trim())}}function He(t,e){if(e&&e.trim())if(t.classList)e.indexOf(" ")>-1?e.split(/\s+/).forEach(function(e){return t.classList.remove(e)}):t.classList.remove(e);else{for(var n=" "+t.getAttribute("class")+" ",r=" "+e+" ";n.indexOf(r)>=0;)n=n.replace(r," ");t.setAttribute("class",n.trim())}}function Re(t){$i(function(){$i(t)})}function Fe(t,e){(t._transitionClasses||(t._transitionClasses=[])).push(e),Ve(t,e)}function ze(t,e){t._transitionClasses&&r(t._transitionClasses,e),He(t,e)}function qe(t,e,n){var r=Ke(t,e),i=r.type,o=r.timeout,a=r.propCount;if(!i)return n();var s=i===yi?ki:Ci,u=0,l=function(){t.removeEventListener(s,c),n()},c=function(e){e.target===t&&++u>=a&&l()};setTimeout(function(){u0&&(n=yi,c=a,f=o.length):e===_i?l>0&&(n=_i,c=l,f=u.length):(c=Math.max(a,l),n=c>0?a>l?yi:_i:null,f=n?n===yi?o.length:u.length:0);var p=n===yi&&xi.test(r[bi+"Property"]);return{type:n,timeout:c,propCount:f,hasTransform:p}}function We(t,e){for(;t.length1,T=n._enterCb=Xe(function(){E&&(ze(n,x),ze(n,$)),T.cancelled?(E&&ze(n,C),S&&S(n)):P&&P(n),n._enterCb=null});t.data.show||ot(t.data.hook||(t.data.hook={}),"insert",function(){var e=n.parentNode,r=e&&e._pending&&e._pending[t.key];r&&r.context===t.context&&r.tag===t.tag&&r.elm._leaveCb&&r.elm._leaveCb(),O&&O(n,T)},"transition-insert"),A&&A(n),E&&(Fe(n,C),Fe(n,$),Re(function(){Fe(n,x),ze(n,C),T.cancelled||L||qe(n,o,T)})),t.data.show&&(e&&e(),O&&O(n,T)),E||L||T()}}}function Ze(t,e){function n(){m.cancelled||(t.data.show||((r.parentNode._pending||(r.parentNode._pending={}))[t.key]=t),c&&c(r),v&&(Fe(r,s),Fe(r,l),Re(function(){Fe(r,u),ze(r,s),m.cancelled||g||qe(r,a,m)})),f&&f(r,m),v||g||m())}var r=t.elm;r._enterCb&&(r._enterCb.cancelled=!0,r._enterCb());var i=Qe(t.data.transition);if(!i)return e();if(!r._leaveCb&&1===r.nodeType){var o=i.css,a=i.type,s=i.leaveClass,u=i.leaveToClass,l=i.leaveActiveClass,c=i.beforeLeave,f=i.leave,p=i.afterLeave,d=i.leaveCancelled,h=i.delayLeave,v=o!==!1&&!Qn,g=f&&(f._length||f.length)>1,m=r._leaveCb=Xe(function(){r.parentNode&&r.parentNode._pending&&(r.parentNode._pending[t.key]=null),v&&(ze(r,u),ze(r,l)),m.cancelled?(v&&ze(r,s),d&&d(r)):(e(),p&&p(r)),r._leaveCb=null});h?h(n):n()}}function Qe(t){if(t){if("object"==typeof t){var e={};return t.css!==!1&&l(e,Ai(t.name||"v")),l(e,t),e}return"string"==typeof t?Ai(t):void 0}}function Xe(t){var e=!1;return function(){e||(e=!0,t())}}function Ye(t,e){e.data.show||Ge(e)}function tn(t,e,n){var r=e.value,i=t.multiple;if(!i||Array.isArray(r)){for(var o,a,s=0,u=t.options.length;s-1,a.selected!==o&&(a.selected=o);else if(v(nn(a),r))return void(t.selectedIndex!==s&&(t.selectedIndex=s));i||(t.selectedIndex=-1)}}function en(t,e){for(var n=0,r=e.length;n0&&(t.currentPage-=1)}}},i={on:{click:function(e){e.preventDefault(),t.currentPage=n?"disabled":""]},a={class:["prev",t.currentPage<=0?"disabled":""]},s=e("li",a,[e("a",r,t.simple.prev)]),u=e("li",o,[e("a",i,t.simple.next)]);return[s,u]}function _n(t,e){return t.filter(function(t){return"paginate"===t.$vnode.componentOptions.tag}).find(function(t){return t.name===e})}function bn(t){return Array.apply(null,{length:t}).map(function(t,e){return e})}function kn(t,e,n,r){var i=r.prev,o=r.next,a=[];return t===i?a.push("left-arrow"):t===o?a.push("right-arrow"):t===Ri?a.push("ellipses"):a.push("number"),t===e&&a.push("active"),t===i&&e<=0?a.push("disabled"):t===o&&e>=n&&a.push("disabled"),a}function wn(t,e,n,r,i,o){var a=i.prev,s=i.next;void 0===o&&(o=null);var u=Math.floor(n/e);if(t===a)return n-1<0?0:n-1;if(t===s)return n+1>r.length-1?r.length-1:n+1;if(o&&"right-ellipses"===o)return(u+1)*e;if(o&&"left-ellipses"===o){var l=r.slice(u*e,u*e+e),c=n===r.length-1;return c&&1===l.length&&u--,(u-1)*e+e-1}return t}function Cn(t){return t.map(function(e,n){return e===Ri&&0===t[n-1]?"left-ellipses":e===Ri&&0!==t[n-1]?"right-ellipses":e})}function $n(t,e){Object.keys(e).forEach(function(n){if("ul"===n){var r=e.ul;Array.isArray(r)?r.forEach(function(e){return t.classList.add(e)}):t.classList.add(r)}t.querySelectorAll(n).forEach(function(t){var r=e[n];Array.isArray(r)?r.forEach(function(e){return t.classList.add(e)}):t.classList.add(r)})})}function xn(t){return void 0===t&&(t=[]),t.reduce(function(t,e){return t[e]={list:[],page:0},t},{})}var An,On=function(){},Pn="undefined"!=typeof console;On=function(t,e,n){void 0===n&&(n="error"),Pn&&console[n]("[vue-paginate]: "+t+" "+(e?Ln(An(e)):""))},An=function(t){if(t.$root===t)return"root instance";var e=t._isVue?t.$options.name||t.$options._componentTag:t.name;return(e?"component <"+e+">":"anonymous component")+(t._isVue&&t.$options.__file?" at "+t.$options.__file:"")};var Sn,En,Ln=function(t){return"anonymous component"===t&&(t+=' - use the "name" option for better debugging messages.'),"\n(found in "+t+")"},Tn={name:"paginate",props:{name:{type:String,required:!0},list:{type:Array,required:!0},per:{type:Number,default:3,validator:function(t){return t>0}},tag:{type:String,default:"ul"},class:{type:String}},data:function(){return{}},computed:{currentPage:{get:function(){if(this.$parent.paginate[this.name])return this.$parent.paginate[this.name].page},set:function(t){this.$parent.paginate[this.name].page=t}}},mounted:function(){return this.per<=0&&On(' 'per' prop can't be 0 or less.",this.$parent),this.$parent.paginate[this.name]?void this.paginateList():void On("'"+this.name+"' is not registered in 'paginate' array.",this.$parent)},watch:{currentPage:function(){this.paginateList()},list:function(){this.currentPage=0,this.paginateList()},per:function(){this.currentPage=0,this.paginateList()}},methods:{paginateList:function(){var t=this.currentPage*this.per,e=this.list.slice(t,t+this.per);this.$parent.paginate[this.name].list=e}},render:function(t){var e=this.class?this.class:"";return t(this.tag,{class:e},this.$slots.default)}},jn="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},Dn=n("slot,component",!0),Nn=Object.prototype.hasOwnProperty,Mn=/-(\w)/g,In=a(function(t){return t.replace(Mn,function(t,e){return e?e.toUpperCase():""})}),Un=a(function(t){return t.charAt(0).toUpperCase()+t.slice(1)}),Bn=/([^-])([A-Z])/g,Vn=a(function(t){return t.replace(Bn,"$1-$2").replace(Bn,"$1-$2").toLowerCase()}),Hn=Object.prototype.toString,Rn="[object Object]",Fn=function(){return!1},zn=function(t){return t},qn={optionMergeStrategies:Object.create(null),silent:!1,devtools:!1,errorHandler:null,ignoredElements:[],keyCodes:Object.create(null),isReservedTag:Fn,isUnknownElement:Fn,getTagNamespace:d,parsePlatformTagName:zn,mustUseProp:Fn,_assetTypes:["component","directive","filter"],_lifecycleHooks:["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated"],_maxUpdateCount:100},Kn=/[^\w.$]/,Wn="__proto__"in{},Jn="undefined"!=typeof window,Gn=Jn&&window.navigator.userAgent.toLowerCase(),Zn=Gn&&/msie|trident/.test(Gn),Qn=Gn&&Gn.indexOf("msie 9.0")>0,Xn=Gn&&Gn.indexOf("edge/")>0,Yn=Gn&&Gn.indexOf("android")>0,tr=Gn&&/iphone|ipad|ipod|ios/.test(Gn),er=function(){return void 0===Sn&&(Sn=!Jn&&"undefined"!=typeof jn&&"server"===jn.process.env.VUE_ENV),Sn},nr=Jn&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,rr=function(){function t(){r=!1;var t=n.slice(0);n.length=0;for(var e=0;e1&&(e[n[0].trim()]=n[1].trim())}}),e}),fi=/^--/,pi=/\s*!important$/,di=function(t,e,n){fi.test(e)?t.style.setProperty(e,n):pi.test(n)?t.style.setProperty(e,n.replace(pi,""),"important"):t.style[vi(e)]=n},hi=["Webkit","Moz","ms"],vi=a(function(t){if(Br=Br||document.createElement("div"),t=In(t),"filter"!==t&&t in Br.style)return t;for(var e=t.charAt(0).toUpperCase()+t.slice(1),n=0;n=this.limit&&(t.unshift(Ri),t.unshift(0)),this.lastPage-this.limit>this._currentChunkIndex()&&t.push(Ri),t},Fi.prototype._buildSecondHalf=function(){var t=[this.lastPage];return t},Fi.prototype._currentChunkIndex=function(){var t=Math.floor(this.currentPage/this.limit);return t*this.limit},Fi.prototype._allPagesButLast=function(){var t=this;return this.listOfPages.filter(function(e){return e!==t.lastPage})};var zi={name:"paginate-links",props:{for:{type:String,required:!0},limit:{type:Number,default:0},simple:{type:Object,default:null,validator:function(t){return t.prev&&t.next}},stepLinks:{type:Object,default:function(){return{prev:Vi,next:Hi}},validator:function(t){return t.prev&&t.next}},showStepLinks:{type:Boolean},hideSinglePage:{type:Boolean},classes:{type:Object,default:null}},data:function(){return{listOfPages:[],numberOfPages:0}},computed:{currentPage:{get:function(){if(this.$parent.paginate[this.for])return this.$parent.paginate[this.for].page},set:function(t){this.$parent.paginate[this.for].page=t}}},mounted:function(){var t=this;this.simple&&this.limit&&On(' 'simple' and 'limit' props can't be used at the same time. In this case, 'simple' will take precedence, and 'limit' will be ignored.",this.$parent,"warn"),this.simple&&!this.simple.next&&On(' 'simple' prop doesn't contain 'next' value.",this.$parent),this.simple&&!this.simple.prev&&On(' 'simple' prop doesn't contain 'prev' value.",this.$parent),this.stepLinks&&!this.stepLinks.next&&On(' 'step-links' prop doesn't contain 'next' value.",this.$parent),this.stepLinks&&!this.stepLinks.prev&&On(' 'step-links' prop doesn't contain 'prev' value.",this.$parent),Bi.nextTick(function(){t.updateListOfPages()})},watch:{"$parent.paginate":{handler:function(){this.updateListOfPages()},deep:!0},currentPage:function(t,e){this.$emit("change",t+1,e+1)}},methods:{updateListOfPages:function(){var t=_n(this.$parent.$children,this.for);return t?(this.numberOfPages=Math.ceil(t.list.length/t.per),void(this.listOfPages=bn(this.numberOfPages))):void On(' can\'t be used without its companion ',this.$parent)}},render:function(t){var e=this,n=this.simple?yn(this,t):this.limit>1?mn(this,t):gn(this,t);if(this.hideSinglePage&&this.numberOfPages<=1)return null;var r=t("ul",{class:["paginate-links",this.for]},n);return this.classes&&Bi.nextTick(function(){$n(r.elm,e.classes)}),r}},qi={};return qi.install=function(t){t.mixin({created:function(){"undefined"!==this.paginate&&this.paginate instanceof Array&&(this.paginate=xn(this.paginate))},methods:{paginated:function(t){return this.paginate&&this.paginate[t]?this.paginate[t].list:void On("'"+t+"' is not registered in 'paginate' array.",this)}}}),t.component("paginate",Tn),t.component("paginate-links",zi)},"undefined"!=typeof window&&window.Vue&&window.Vue.use(qi),qi}); \ No newline at end of file diff --git a/package.json b/package.json index 713cc0a..9a94813 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-paginate", - "version": "3.3.1", + "version": "3.4.0", "description": "A simple vue.js plugin to paginate data", "main": "dist/vue-paginate.js", "scripts": {