Skip to content

Node.js based forum software built for the modern web

pagination

barisusaklie8afe329a9ef
diff --git a/public/src/client/pagination.js b/public/src/client/pagination.js
index 57bdee7f9e..a94967c7c5 100644
--- a/public/src/client/pagination.js
+++ b/public/src/client/pagination.js
@@ -11,7 +11,7 @@ define('forum/pagination', function() {
pagination.currentPage = parseInt(currentPage, 10);
pagination.pageCount = parseInt(pageCount, 10);
- $('.pagination').on('click', '.select_page', function(e) {
+ $('.pagination').on('click', '.select-page', function(e) {
e.preventDefault();
bootbox.prompt('Enter page number:', function(pageNum) {
pagination.loadPage(pageNum);
diff --git a/src/pagination.js b/src/pagination.js
index d3a3ca9dd9..f8744fbdfc 100644
--- a/src/pagination.js
+++ b/src/pagination.js
@@ -14,10 +14,7 @@ pagination.create = function(currentPage, pageCount, queryObj) {
};
}
- var pagesToShow = [1];
- if (pageCount !== 1) {
- pagesToShow.push(pageCount);
- }
+ var pagesToShow = [1, 2, pageCount - 1, pageCount];
currentPage = parseInt(currentPage, 10) || 1;
var previous = Math.max(1, currentPage - 1);
@@ -25,13 +22,12 @@ pagination.create = function(currentPage, pageCount, queryObj) {
var startPage = currentPage - 2;
for(var i=0; i<5; ++i) {
- var p = startPage + i;
- if (p >= 1 && p <= pageCount && pagesToShow.indexOf(p) === -1) {
- pagesToShow.push(startPage + i);
- }
+ pagesToShow.push(startPage + i);
}
- pagesToShow.sort(function(a, b) {
+ pagesToShow = pagesToShow.filter(function(page, index, array) {
+ return page > 0 && page <= pageCount && array.indexOf(page) === index;
+ }).sort(function(a, b) {
return a - b;
});
@@ -42,6 +38,12 @@ pagination.create = function(currentPage, pageCount, queryObj) {
return {page: page, active: page === currentPage, qs: qs.stringify(queryObj)};
});
+ for (i=pages.length - 1; i>0; --i) {
+ if (pages[i - 1].page !== pages[i].page - 1) {
+ pages.splice(i, 0, {separator: true});
+ }
+ }
+
var data = {
prev: {page: previous, active: currentPage > 1},
next: {page: next, active: currentPage < pageCount},