postCount != lastPostIndex unfortunately, that will need some rethinking
v1.18.x
barisusakli 11 years ago
parent 49a9601a04
commit 1cabf885a2

@ -24,6 +24,7 @@
"pagination": "Pagination", "pagination": "Pagination",
"pagination.out_of": "%1 out of %2", "pagination.out_of": "%1 out of %2",
"pagination.enter_index": "Enter index",
"header.admin": "Admin", "header.admin": "Admin",
"header.recent": "Recent", "header.recent": "Recent",

@ -1,7 +1,7 @@
'use strict'; 'use strict';
/* globals app, define, ajaxify */ /* globals app, define, ajaxify, utils, translator */
define('navigator', function() { define('navigator', function() {
@ -17,22 +17,49 @@ define('navigator', function() {
$(window).on('scroll', navigator.update); $(window).on('scroll', navigator.update);
$('.pagination-block a').off('click').on('click', function() { $('.pagination-block .dropdown-menu').off('click').on('click', function(e) {
return false; e.stopPropagation();
}); });
$('.pagination-block i:first').off('click').on('click', function() { $('.pagination-block .pageup').off('click').on('click', function() {
navigator.scrollToTop(); navigator.scrollToTop();
}); });
$('.pagination-block i:last').off('click').on('click', function() { $('.pagination-block .pagedown').off('click').on('click', function() {
navigator.scrollToBottom(); navigator.scrollToBottom();
}); });
$('.pagination-block .pagetop').off('click').on('click', function() {
ajaxify.go(generateUrl());
});
$('.pagination-block .pagebottom').off('click').on('click', function() {
ajaxify.go(generateUrl(count));
});
$('.pagination-block input').on('keydown', function(e) {
if (e.which === 13) {
var input = $(this);
if (!utils.isNumber(input.val())) {
input.val('');
return;
}
var url = generateUrl(input.val());
input.val('');
$('.pagination-block .dropdown-toggle').trigger('click');
ajaxify.go(url);
}
});
navigator.setCount(count); navigator.setCount(count);
navigator.update(); navigator.update();
}; };
function generateUrl(index) {
var parts = window.location.pathname.split('/');
return parts[1] + '/' + parts[2] + '/' + parts[3] + (index ? '/' + index : '');
}
navigator.setCount = function(value) { navigator.setCount = function(value) {
count = parseInt(value, 10); count = parseInt(value, 10);
navigator.updateTextAndProgressBar(); navigator.updateTextAndProgressBar();

@ -90,7 +90,15 @@ categoriesController.get = function(req, res, next) {
return next(err); return next(err);
} }
var start = (page - 1) * settings.topicsPerPage, var topicIndex = 0;
if (!settings.usePagination) {
topicIndex = Math.max((req.params.topic_index || 1) - (settings.topicsPerPage - 1), 0);
} else if (!req.query.page) {
var index = Math.max(parseInt((req.params.topic_index || 0), 10), 0);
page = Math.ceil((index + 1) / settings.topicsPerPage);
}
var start = (page - 1) * settings.topicsPerPage + topicIndex,
end = start + settings.topicsPerPage - 1; end = start + settings.topicsPerPage - 1;
categories.getCategoryById(cid, start, end, uid, function (err, categoryData) { categories.getCategoryById(cid, start, end, uid, function (err, categoryData) {

@ -99,6 +99,26 @@ middleware.checkPostIndex = function(req, res, next) {
}); });
}; };
middleware.checkTopicIndex = function(req, res, next) {
categories.getCategoryField(req.params.category_id, 'topic_count', function(err, topicCount) {
if (err) {
return next(err);
}
var topicIndex = parseInt(req.params.topic_index, 10);
topicCount = parseInt(topicCount, 10) + 1;
var url = '';
console.log(topicIndex, topicCount);
if (topicIndex > topicCount) {
url = '/category/' + req.params.category_id + '/' + req.params.slug + '/' + topicCount;
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
} else if (topicIndex < 1) {
url = '/category/' + req.params.category_id + '/' + req.params.slug;
return res.locals.isAPI ? res.json(302, url) : res.redirect(url);
}
next();
});
};
middleware.prepareAPI = function(req, res, next) { middleware.prepareAPI = function(req, res, next) {
res.locals.isAPI = true; res.locals.isAPI = true;
next(); next();

@ -79,6 +79,9 @@ function categoryRoutes(app, middleware, controllers) {
app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal); app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal);
app.get('/category/:category_id/:slug/:topic_index', middleware.buildHeader, middleware.checkTopicIndex, controllers.categories.get);
app.get('/api/category/:category_id/:slug/:topic_index', middleware.checkTopicIndex, controllers.categories.get);
app.get('/category/:category_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.categories.get); app.get('/category/:category_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.categories.get);
app.get('/api/category/:category_id/:slug?', controllers.categories.get); app.get('/api/category/:category_id/:slug?', controllers.categories.get);
} }

Loading…
Cancel
Save