fix for infinite scroll crashing, issue #187

v1.18.x
Baris Soner Usakli 12 years ago
parent b43e12a42a
commit 1c95ef4060

@ -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() {

@ -628,10 +628,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:topic.loadMore', function(data, callback) {
var start = data.after,
var start = data.after,
end = start + 9;
topics.getTopicPosts(data.tid, start, end, uid, function(posts) {
console.log('sending back tid: '+data.tid, posts);
callback({posts:posts});
});
});

Loading…
Cancel
Save