mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
@@ -8,7 +8,8 @@
|
||||
deleted: templates.get('deleted'),
|
||||
pinned: templates.get('pinned')
|
||||
},
|
||||
topic_name = templates.get('topic_name');
|
||||
topic_name = templates.get('topic_name'),
|
||||
infiniteLoaderActive = false;
|
||||
|
||||
function addCommasToNumbers() {
|
||||
$('.formatted-number').each(function(index, element) {
|
||||
@@ -204,6 +205,20 @@
|
||||
followEl[0].addEventListener('click', function() {
|
||||
socket.emit('api:topic.follow', tid);
|
||||
}, false);
|
||||
|
||||
// Infinite scrolling of posts
|
||||
window.addEventListener('scroll', function() {
|
||||
var windowHeight = document.body.offsetHeight - $(window).height(),
|
||||
half = windowHeight / 2;
|
||||
|
||||
if (document.body.scrollTop > half && !infiniteLoaderActive) {
|
||||
infiniteLoaderActive = true;
|
||||
socket.emit('api:topic.loadMore', {
|
||||
tid: tid,
|
||||
after: document.querySelectorAll('#post-container li[data-pid]').length
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -304,9 +319,8 @@
|
||||
socket.on('event:new_post', function(data) {
|
||||
data.posts[0].display_moderator_tools = 'none';
|
||||
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data),
|
||||
uniqueid = new Date().getTime();
|
||||
|
||||
jQuery('<div id="' + uniqueid + '"></div>')
|
||||
uniqueid = new Date().getTime(),
|
||||
tempContainer = jQuery('<div id="' + uniqueid + '"></div>')
|
||||
.appendTo("#post-container")
|
||||
.hide()
|
||||
.append(html)
|
||||
@@ -316,6 +330,9 @@
|
||||
socket.emit('api:post.privileges', data.posts[x].pid);
|
||||
}
|
||||
|
||||
tempContainer.replaceWith(tempContainer.contents());
|
||||
infiniteLoaderActive = false;
|
||||
|
||||
set_up_posts(uniqueid);
|
||||
|
||||
addCommasToNumbers();
|
||||
|
||||
11
src/posts.js
11
src/posts.js
@@ -17,16 +17,17 @@ marked.setOptions({
|
||||
Posts.getPostsByTid = function(tid, current_user, start, end, callback) {
|
||||
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
|
||||
RDB.handle(err);
|
||||
|
||||
if (pids.length === 0 ) {
|
||||
throw new Error('Topic should never have 0 posts. tid: ' + tid);
|
||||
}
|
||||
|
||||
topics.markAsRead(tid, current_user);
|
||||
|
||||
if (pids.length) {
|
||||
Posts.getPostsByPids(pids, current_user, function(posts) {
|
||||
callback(posts);
|
||||
});
|
||||
} else {
|
||||
callback({
|
||||
error: 'no-posts'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -410,11 +410,13 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
end = start + 10;
|
||||
|
||||
posts.getPostsByTid(data.tid, uid, start, end, function(posts){
|
||||
if (!posts.error) {
|
||||
postTools.constructPostObject(posts, data.tid, uid, null, function(postObj) {
|
||||
io.sockets.in('topic_' + data.tid).emit('event:new_post', {
|
||||
posts: postObj
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user