BigW Consortium Gitlab

Commit 39a8f1aa by Regis

regex for number check

parent 4dd82e1d
......@@ -9,9 +9,14 @@
'pagenum',
],
methods: {
pagenumberstatus(n) {
if (n - 1 === +this.pagenum) return 'active';
return '';
pagestatus(n) {
if (n - 1 === +this.pagenum) return true;
return false;
},
prevstatus(index) {
if (index > 0) return false;
if (+this.pagenum < 2) return true;
return false;
},
createSection(n) { return Array.from(Array(n)).map((e, i) => i); },
},
......@@ -22,7 +27,7 @@
const pages = this.createSection(+this.last + 1);
pages.shift();
if (+this.pagenum !== 1) items.push({ text: 'Prev' });
items.push({ text: 'Prev', class: this.prevstatus() });
pages.forEach(i => items.push({ text: i }));
......@@ -34,8 +39,8 @@
},
template: `
<div class="gl-pagination">
<ul class="pagination clearfix" v-for='(item, index) in getItems'>
<li :class='pagenumberstatus(index + 1)'>
<ul class="pagination clearfix" v-for='(item, i) in getItems'>
<li :class="{active: pagestatus(i + 1), disabled: prevstatus(i)}">
<span @click='changepage($event, last)'>{{item.text}}</span>
</li>
</ul>
......
......@@ -37,7 +37,7 @@
},
changepage(event, last) {
const text = event.target.innerText;
if (typeof text === 'number') this.pagenum = +text;
if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
if (text === 'Last »') this.pagenum = last;
if (text === 'Next') this.pagenum = +this.pagenum + 1;
if (text === 'Prev') this.pagenum = +this.pagenum - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment