Created
February 15, 2012 17:29
-
-
Save jehugaleahsa/1837472 to your computer and use it in GitHub Desktop.
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
// page: the currently selected page (1 <= page <= pageCount) | |
// pageCount: the total number of pages (1 <= pageCount) | |
// pagesToDisplay: the number of pages displayed at a time (1 <= pagesToDisplay) | |
function paginate(page, pageCount, pagesToDisplay) { | |
var buffer = Math.floor(pagesToDisplay / 2); | |
return { | |
start: Math.max(1, Math.min(page - buffer, pageCount - pagesToDisplay)), | |
stop: Math.min(pageCount, Math.max(page + buffer, pagesToDisplay)) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment