mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
fix for infinite scroll crashing, issue #187
This commit is contained in:
@@ -333,13 +333,15 @@ var socket,
|
|||||||
app.infiniteLoaderActive = false;
|
app.infiniteLoaderActive = false;
|
||||||
if(data.posts.length) {
|
if(data.posts.length) {
|
||||||
app.createNewPosts(data);
|
app.createNewPosts(data);
|
||||||
if(callback)
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(callback)
|
||||||
|
callback(data.posts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
app.scrollToPost = function(pid) {
|
app.scrollToPost = function(pid) {
|
||||||
|
|
||||||
if(!pid)
|
if(!pid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -347,17 +349,31 @@ var socket,
|
|||||||
scrollTo = $('#post_anchor_' + pid),
|
scrollTo = $('#post_anchor_' + pid),
|
||||||
tid = $('#post-container').attr('data-tid');
|
tid = $('#post-container').attr('data-tid');
|
||||||
|
|
||||||
while(!scrollTo.length && tid) {
|
function animateScroll() {
|
||||||
app.loadMorePosts(tid, function() {
|
|
||||||
scrollTo = $('#post_anchor_' + pid);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tid) {
|
|
||||||
$('body,html').animate({
|
$('body,html').animate({
|
||||||
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()
|
scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop() - $('#header-menu').height()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!scrollTo.length && tid) {
|
||||||
|
|
||||||
|
var intervalID = setInterval(function() {
|
||||||
|
app.loadMorePosts(tid, function(posts) {
|
||||||
|
scrollTo = $('#post_anchor_' + pid);
|
||||||
|
|
||||||
|
if(tid && scrollTo.length) {
|
||||||
|
animateScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!posts.length || scrollTo.length)
|
||||||
|
clearInterval(intervalID);
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
} else if(tid) {
|
||||||
|
animateScroll();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery('document').ready(function() {
|
jQuery('document').ready(function() {
|
||||||
|
|||||||
@@ -628,10 +628,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topic.loadMore', function(data, callback) {
|
socket.on('api:topic.loadMore', function(data, callback) {
|
||||||
var start = data.after,
|
var start = data.after,
|
||||||
end = start + 9;
|
end = start + 9;
|
||||||
|
|
||||||
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
|
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
|
||||||
|
console.log('sending back tid: '+data.tid, posts);
|
||||||
callback({posts:posts});
|
callback({posts:posts});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user