Last active
July 26, 2018 21:24
-
-
Save Alexzanderk/06da7ccbe358036c0b623782d27c40c9 to your computer and use it in GitHub Desktop.
Pagination pug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mixin pagination(totalNewsCount, limit, currentPage, num) | |
- let index = 0; | |
- let pageRange = num || 2; | |
- let totalPages = totalNewsCount / limit; | |
- let rangeStart = () => (currentPage - pageRange > 1) ? currentPage - pageRange : 1; | |
- let rangeEnd = () => (currentPage + pageRange < totalPages) ? currentPage + pageRange : totalPages; | |
- let hasFirst = rangeStart !== 1; | |
- let hasLast = rangeEnd() < totalPages; | |
-console.log(!hasFirst) | |
if totalPages > 1 | |
ul.pagination | |
li.pagination__item | |
a.pagination__link(href='#') | |
span.pagination__previous < | |
if totalPages > 6 && rangeStart() > 1 | |
li.pagination__item | |
a.pagination__link(href='#') 1 | |
li.pagination__item | |
a.pagination__link(data-eclipdse='true' disabled href='#') ... | |
if totalPages <= 6 | |
-for(let index = 1; index <= totalPages; index +=1) | |
li.pagination__item | |
a.pagination__link(href='#')= index | |
else | |
-for(let index = rangeStart(); index <= rangeEnd(); index +=1) | |
li.pagination__item | |
a.pagination__link(href='#')= index | |
if totalPages>6 && hasLast | |
if rangeEnd() + 1 !== totalPages | |
li.pagination__item | |
a.pagination__link(data-eclipdse='true' disabled href='#') ... | |
li.pagination__item | |
a.pagination__link(href='#')= totalPages | |
li.pagination__item | |
a.pagination__link(href='#') | |
span.pagination__next > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment