Created
May 29, 2018 05:54
-
-
Save waitingallday/e9ab057269adc78593e4be4b8e6a256c to your computer and use it in GitHub Desktop.
Figure out the pagination buttons
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
Handlebars.registerHelper('pagebuttons', function(totalMatching, currStart, query) { | |
var q = query, | |
out = "", | |
pages = (parseInt(totalMatching / 10)) + 1, | |
currPage = currStart <= 1 ? 1 : (currStart + 9) / 10, | |
startPage = (currPage - 2) >= 1 ? (currPage === pages ? currPage - 2 : currPage - 1) : 1, | |
endPage = (currPage + 2) <= pages ? (currPage === 1 ? currPage + 2 : currPage + 1) : pages, | |
i; | |
for (i = startPage; i <= endPage; i++) { | |
out = out + '<a ' + 'class="search__pagination-link'; | |
if (i === currPage) out = out + ' search__pagination-link--current'; | |
out = out + '" href="?query=' + q + '&start-rank=' + parseInt(((i-1) * 10) + 1) + '">' + i + "</a>\n"; | |
} | |
return out; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment