mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closes #1758
This commit is contained in:
@@ -35,7 +35,7 @@ define('forum/category', ['composer', 'forum/pagination', 'forum/infinitescroll'
|
|||||||
enableInfiniteLoadingOrPagination();
|
enableInfiniteLoadingOrPagination();
|
||||||
|
|
||||||
if (!config.usePagination) {
|
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() {
|
$('#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) {
|
$(window).on('action:popstate', function(ev, data) {
|
||||||
if(data.url.indexOf('category/') === 0) {
|
if(data.url.indexOf('category/') === 0) {
|
||||||
var bookmark = localStorage.getItem('category:bookmark');
|
var bookmark = localStorage.getItem('category:bookmark');
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
|
|
||||||
handleBookmark(tid);
|
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);
|
socket.on('event:new_post', onNewPost);
|
||||||
|
|
||||||
@@ -74,6 +74,16 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
socket.emit('topics.increaseViewCount', tid);
|
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) {
|
function handleBookmark(tid) {
|
||||||
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
|
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
|
||||||
var postIndex = getPostIndex();
|
var postIndex = getPostIndex();
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ define('navigator', function() {
|
|||||||
var index = 1;
|
var index = 1;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
navigator.init = function(selector, count, callback) {
|
navigator.init = function(selector, count, callback, toTop, toBottom) {
|
||||||
|
|
||||||
navigator.selector = selector;
|
navigator.selector = selector;
|
||||||
navigator.callback = callback;
|
navigator.callback = callback;
|
||||||
|
toTop = toTop || function() {};
|
||||||
|
toBottom = toBottom || function() {};
|
||||||
|
|
||||||
$(window).on('scroll', navigator.update);
|
$(window).on('scroll', navigator.update);
|
||||||
|
|
||||||
@@ -21,21 +23,10 @@ define('navigator', function() {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.pagination-block .pageup').off('click').on('click', function() {
|
$('.pagination-block .pageup').off('click').on('click', navigator.scrollUp);
|
||||||
navigator.scrollToTop();
|
$('.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 .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 input').on('keydown', function(e) {
|
$('.pagination-block input').on('keydown', function(e) {
|
||||||
if (e.which === 13) {
|
if (e.which === 13) {
|
||||||
@@ -107,18 +98,35 @@ define('navigator', function() {
|
|||||||
$('.pagination-block .progress-bar').width((index / count * 100) + '%');
|
$('.pagination-block .progress-bar').width((index / count * 100) + '%');
|
||||||
};
|
};
|
||||||
|
|
||||||
navigator.scrollToTop = function () {
|
navigator.scrollUp = function () {
|
||||||
$('body,html').animate({
|
$('body,html').animate({
|
||||||
scrollTop: 0
|
scrollTop: 0
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
navigator.scrollToBottom = function () {
|
navigator.scrollDown = function () {
|
||||||
$('body,html').animate({
|
$('body,html').animate({
|
||||||
scrollTop: $('html').height() - 100
|
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) {
|
function elementInView(el) {
|
||||||
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
|
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
|
||||||
var scrollBottom = scrollTop + $(window).height();
|
var scrollBottom = scrollTop + $(window).height();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ middleware.checkPostIndex = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
middleware.checkTopicIndex = 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) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
|
db = require('../database'),
|
||||||
categories = require('../categories'),
|
categories = require('../categories'),
|
||||||
privileges = require('../privileges'),
|
privileges = require('../privileges'),
|
||||||
meta = require('./../meta'),
|
meta = require('../meta'),
|
||||||
user = require('./../user'),
|
user = require('../user'),
|
||||||
|
|
||||||
SocketCategories = {};
|
SocketCategories = {};
|
||||||
|
|
||||||
@@ -65,4 +66,8 @@ SocketCategories.getTopicCount = function(socket, cid, callback) {
|
|||||||
categories.getCategoryField(cid, 'topic_count', callback);
|
categories.getCategoryField(cid, 'topic_count', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketCategories.lastTopicIndex = function(socket, cid, callback) {
|
||||||
|
db.sortedSetCard('categories:' + cid + ':tid', callback);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = SocketCategories;
|
module.exports = SocketCategories;
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ SocketTopics.postcount = function(socket, tid, callback) {
|
|||||||
topics.getTopicField(tid, 'postcount', callback);
|
topics.getTopicField(tid, 'postcount', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketTopics.lastPostIndex = function(socket, tid, callback) {
|
||||||
|
db.sortedSetCard('tid:' + tid + ':posts', callback);
|
||||||
|
};
|
||||||
|
|
||||||
SocketTopics.increaseViewCount = function(socket, tid) {
|
SocketTopics.increaseViewCount = function(socket, tid) {
|
||||||
topics.increaseViewCount(tid);
|
topics.increaseViewCount(tid);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user