mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
pagination
This commit is contained in:
@@ -11,7 +11,7 @@ define('forum/pagination', function() {
|
|||||||
pagination.currentPage = parseInt(currentPage, 10);
|
pagination.currentPage = parseInt(currentPage, 10);
|
||||||
pagination.pageCount = parseInt(pageCount, 10);
|
pagination.pageCount = parseInt(pageCount, 10);
|
||||||
|
|
||||||
$('.pagination').on('click', '.select_page', function(e) {
|
$('.pagination').on('click', '.select-page', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
bootbox.prompt('Enter page number:', function(pageNum) {
|
bootbox.prompt('Enter page number:', function(pageNum) {
|
||||||
pagination.loadPage(pageNum);
|
pagination.loadPage(pageNum);
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ pagination.create = function(currentPage, pageCount, queryObj) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var pagesToShow = [1];
|
var pagesToShow = [1, 2, pageCount - 1, pageCount];
|
||||||
if (pageCount !== 1) {
|
|
||||||
pagesToShow.push(pageCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentPage = parseInt(currentPage, 10) || 1;
|
currentPage = parseInt(currentPage, 10) || 1;
|
||||||
var previous = Math.max(1, currentPage - 1);
|
var previous = Math.max(1, currentPage - 1);
|
||||||
@@ -25,13 +22,12 @@ pagination.create = function(currentPage, pageCount, queryObj) {
|
|||||||
|
|
||||||
var startPage = currentPage - 2;
|
var startPage = currentPage - 2;
|
||||||
for(var i=0; i<5; ++i) {
|
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;
|
return a - b;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,6 +38,12 @@ pagination.create = function(currentPage, pageCount, queryObj) {
|
|||||||
return {page: page, active: page === currentPage, qs: qs.stringify(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 = {
|
var data = {
|
||||||
prev: {page: previous, active: currentPage > 1},
|
prev: {page: previous, active: currentPage > 1},
|
||||||
next: {page: next, active: currentPage < pageCount},
|
next: {page: next, active: currentPage < pageCount},
|
||||||
|
|||||||
Reference in New Issue
Block a user