Last active
May 14, 2020 07:38
-
-
Save romanzaycev/0fd07414cd59ba0a5a4cf60b95fe9f18 to your computer and use it in GitHub Desktop.
Jade (Pug) Bootstrap pagination mixin (Digg-like pagination)
This file contains 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(adjacents, numPages, display, currentPage, base) | |
- adjacents = (adjacents || 1) * 1; | |
- numPages = (numPages || 10) * 1; | |
- currentPage = (currentPage || 1) * 1; | |
- base = base || '#'; | |
- display = (display || 7) * 1; | |
ul.pagination | |
if numPages < display + adjacents * 2 | |
- var p = 1; | |
while p <= numPages | |
if currentPage == p | |
li.active | |
a(href=base + p) | |
| #{p} | |
else | |
li.page | |
a(href=base + p) | |
| #{p} | |
- p++; | |
else if numPages >= 7 + adjacents * 2 | |
if currentPage < 1 + adjacents * 3 | |
- var p = 1; | |
while p < display - 3 + adjacents * 2 | |
if currentPage == p | |
li.active | |
a(href=base + p) | |
| #{p} | |
else | |
li.page | |
a(href=base + p) | |
| #{p} | |
- p++; | |
li.disabled | |
a(href="#") | |
| … | |
li.page | |
a(href=base + (numPages - 1)) | |
| #{numPages - 1} | |
li.page | |
a(href=base + numPages) | |
| #{numPages} | |
else if numPages - adjacents * 2 > currentPage && currentPage > adjacents * 2 | |
li.page | |
a(href=base + 1) | |
| 1 | |
li.page | |
a(href=base + 2) | |
| 2 | |
li.disabled | |
a(href="#") | |
| … | |
- var p = currentPage - adjacents; | |
while p <= currentPage + adjacents | |
if currentPage == p | |
li.active | |
a(href=base + p) | |
| #{p} | |
else | |
li.page | |
a(href=base + p) | |
| #{p} | |
- p++; | |
li.disabled | |
a(href="#") | |
| … | |
li.page | |
a(href=base + (numPages - 1)) | |
| #{numPages - 1} | |
li.page | |
a(href=base + numPages) | |
| #{numPages} | |
else | |
li.page | |
a(href=base + 1) | |
| 1 | |
li.page | |
a(href=base + 2) | |
| 2 | |
li.disabled | |
a(href="#") | |
| … | |
- var p = numPages - (1 + (adjacents * 3)); | |
while p <= numPages | |
if currentPage == p | |
li.active | |
a(href=base + p) | |
| #{p} | |
else | |
li.page | |
a(href=base + p) | |
| #{p} | |
- p++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it please:
- adjacents = (adjacents || 3)*1;
- numPages = (numPages || 10)*1;
- currentPage = (currentPage || 1)*1;
- base = base || '#';
- display = (display || 7) *1;
this will help to avoid string problems: 27 + 1 = 271