v1.18.x
barisusakli 11 years ago
parent 181613e946
commit a9e5e82431

@ -35,7 +35,7 @@ define('forum/category', ['composer', 'forum/pagination', 'forum/infinitescroll'
enableInfiniteLoadingOrPagination();
if (!config.usePagination) {
navigator.init('#topics-container > .category-item', ajaxify.variables.get('topic_count'));
navigator.init('#topics-container > .category-item', ajaxify.variables.get('topic_count'), undefined, Category.toTop, Category.toBottom);
}
$('#topics-container').on('click', '.topic-title', function() {
@ -50,6 +50,16 @@ define('forum/category', ['composer', 'forum/pagination', 'forum/infinitescroll'
});
};
Category.toTop = function() {
navigator.scrollTop(0);
};
Category.toBottom = function() {
socket.emit('categories.lastTopicIndex', ajaxify.variables.get('category_id'), function(err, index) {
navigator.scrollBottom(index);
});
};
$(window).on('action:popstate', function(ev, data) {
if(data.url.indexOf('category/') === 0) {
var bookmark = localStorage.getItem('category:bookmark');

@ -62,7 +62,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
handleBookmark(tid);
navigator.init('.posts > .post-row', postCount, Topic.navigatorCallback);
navigator.init('.posts > .post-row', postCount, Topic.navigatorCallback, Topic.toTop, Topic.toBottom);
socket.on('event:new_post', onNewPost);
@ -74,6 +74,16 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
socket.emit('topics.increaseViewCount', tid);
};
Topic.toTop = function() {
navigator.scrollTop(1);
};
Topic.toBottom = function() {
socket.emit('topics.lastPostIndex', ajaxify.variables.get('topic_id'), function(err, index) {
navigator.scrollBottom(index);
});
};
function handleBookmark(tid) {
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
var postIndex = getPostIndex();

@ -10,10 +10,12 @@ define('navigator', function() {
var index = 1;
var count = 0;
navigator.init = function(selector, count, callback) {
navigator.init = function(selector, count, callback, toTop, toBottom) {
navigator.selector = selector;
navigator.callback = callback;
toTop = toTop || function() {};
toBottom = toBottom || function() {};
$(window).on('scroll', navigator.update);
@ -21,21 +23,10 @@ define('navigator', function() {
e.stopPropagation();
});
$('.pagination-block .pageup').off('click').on('click', function() {
navigator.scrollToTop();
});
$('.pagination-block .pagedown').off('click').on('click', function() {
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 .pageup').off('click').on('click', navigator.scrollUp);
$('.pagination-block .pagedown').off('click').on('click', navigator.scrollDown);
$('.pagination-block .pagetop').off('click').on('click', toTop);
$('.pagination-block .pagebottom').off('click').on('click', toBottom);
$('.pagination-block input').on('keydown', function(e) {
if (e.which === 13) {
@ -107,18 +98,35 @@ define('navigator', function() {
$('.pagination-block .progress-bar').width((index / count * 100) + '%');
};
navigator.scrollToTop = function () {
navigator.scrollUp = function () {
$('body,html').animate({
scrollTop: 0
});
};
navigator.scrollToBottom = function () {
navigator.scrollDown = function () {
$('body,html').animate({
scrollTop: $('html').height() - 100
});
};
navigator.scrollTop = function(index) {
if ($('li[data-index="' + index + '"]').length) {
navigator.scrollUp();
} else {
ajaxify.go(generateUrl());
}
};
navigator.scrollBottom = function(index) {
if ($('li[data-index="' + index + '"]').length) {
navigator.scrollDown();
} else {
index = parseInt(index, 10) + 1;
ajaxify.go(generateUrl(index));
}
};
function elementInView(el) {
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
var scrollBottom = scrollTop + $(window).height();

@ -100,7 +100,7 @@ middleware.checkPostIndex = function(req, res, next) {
};
middleware.checkTopicIndex = function(req, res, next) {
categories.getCategoryField(req.params.category_id, 'topic_count', function(err, topicCount) {
db.sortedSetCard('categories:' + req.params.category_id + ':tid', function(err, topicCount) {
if (err) {
return next(err);
}

@ -1,10 +1,11 @@
'use strict';
var async = require('async'),
db = require('../database'),
categories = require('../categories'),
privileges = require('../privileges'),
meta = require('./../meta'),
user = require('./../user'),
meta = require('../meta'),
user = require('../user'),
SocketCategories = {};
@ -65,4 +66,8 @@ SocketCategories.getTopicCount = function(socket, cid, callback) {
categories.getCategoryField(cid, 'topic_count', callback);
};
SocketCategories.lastTopicIndex = function(socket, cid, callback) {
db.sortedSetCard('categories:' + cid + ':tid', callback);
};
module.exports = SocketCategories;

@ -57,6 +57,10 @@ SocketTopics.postcount = function(socket, tid, callback) {
topics.getTopicField(tid, 'postcount', callback);
};
SocketTopics.lastPostIndex = function(socket, tid, callback) {
db.sortedSetCard('tid:' + tid + ':posts', callback);
};
SocketTopics.increaseViewCount = function(socket, tid) {
topics.increaseViewCount(tid);
};

Loading…
Cancel
Save