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;
|
||||
if(data.posts.length) {
|
||||
app.createNewPosts(data);
|
||||
if(callback)
|
||||
callback();
|
||||
}
|
||||
|
||||
if(callback)
|
||||
callback(data.posts);
|
||||
});
|
||||
}
|
||||
|
||||
app.scrollToPost = function(pid) {
|
||||
|
||||
if(!pid)
|
||||
return;
|
||||
|
||||
@@ -347,17 +349,31 @@ var socket,
|
||||
scrollTo = $('#post_anchor_' + pid),
|
||||
tid = $('#post-container').attr('data-tid');
|
||||
|
||||
while(!scrollTo.length && tid) {
|
||||
app.loadMorePosts(tid, function() {
|
||||
scrollTo = $('#post_anchor_' + pid);
|
||||
});
|
||||
}
|
||||
|
||||
if(tid) {
|
||||
function animateScroll() {
|
||||
$('body,html').animate({
|
||||
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() {
|
||||
|
||||
@@ -632,6 +632,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
end = start + 9;
|
||||
|
||||
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
|
||||
console.log('sending back tid: '+data.tid, posts);
|
||||
callback({posts:posts});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user