fixes to infinite load and paginator

v1.18.x
Baris Usakli 11 years ago
parent dd36cce329
commit b2074c6dda

@ -786,7 +786,7 @@ define(function() {
if (scrollTop < 50 && Topic.postCount > 1) { if (scrollTop < 50 && Topic.postCount > 1) {
localStorage.removeItem("topic:" + tid + ":bookmark"); localStorage.removeItem("topic:" + tid + ":bookmark");
pagination.innerHTML = '0 out of ' + Topic.postCount; pagination.innerHTML = '1 out of ' + Topic.postCount;
return; return;
} }
@ -812,7 +812,7 @@ define(function() {
smallestNonNegative = Number.MAX_VALUE; smallestNonNegative = Number.MAX_VALUE;
} }
pagination.innerHTML = this.postnumber + ' out of ' + Topic.postCount; pagination.innerHTML = (this.postnumber-1) + ' out of ' + Topic.postCount;
} }
}); });
@ -863,8 +863,9 @@ define(function() {
} }
function createNewPosts(data, infiniteLoaded) { function createNewPosts(data, infiniteLoaded) {
if(!data || (data.posts && !data.posts.length)) if(!data || (data.posts && !data.posts.length)) {
return; return;
}
function removeAlreadyAddedPosts() { function removeAlreadyAddedPosts() {
data.posts = data.posts.filter(function(post) { data.posts = data.posts.filter(function(post) {
@ -944,7 +945,7 @@ define(function() {
socket.emit('api:topic.loadMore', { socket.emit('api:topic.loadMore', {
tid: tid, tid: tid,
after: $('#post-container .post-row.infiniteloaded').length after: $('#post-container .post-row.infiniteloaded').last().attr('data-index') + 1
}, function (data) { }, function (data) {
infiniteLoaderActive = false; infiniteLoaderActive = false;
if (data.posts.length) { if (data.posts.length) {

@ -26,7 +26,7 @@
<ul id="post-container" class="container posts" data-tid="{topic_id}"> <ul id="post-container" class="container posts" data-tid="{topic_id}">
<!-- BEGIN posts --> <!-- BEGIN posts -->
<li class="row post-row infiniteloaded" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-deleted="{posts.deleted}" itemscope itemtype="http://schema.org/Comment"> <li class="row post-row infiniteloaded" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-index="{posts.index}" data-deleted="{posts.deleted}" itemscope itemtype="http://schema.org/Comment">
<a id="post_anchor_{posts.pid}" name="{posts.pid}"></a> <a id="post_anchor_{posts.pid}" name="{posts.pid}"></a>
<meta itemprop="datePublished" content="{posts.relativeTime}"> <meta itemprop="datePublished" content="{posts.relativeTime}">

@ -160,8 +160,17 @@ var RDB = require('./redis'),
Topics.getTopicPosts = function(tid, start, end, current_user, callback) { Topics.getTopicPosts = function(tid, start, end, current_user, callback) {
posts.getPostsByTid(tid, start, end, function(postData) { posts.getPostsByTid(tid, start, end, function(postData) {
if (Array.isArray(postData) && !postData.length) if (Array.isArray(postData) && !postData.length) {
return callback([]); return callback([]);
}
for(var i=0; i<postData.length; ++i) {
postData[i].index = start + i;
}
postData = postData.filter(function(post) {
return parseInt(current_user, 10) !== 0 || post.deleted === "0";
});
function getFavouritesData(next) { function getFavouritesData(next) {
var pids = []; var pids = [];
@ -482,8 +491,9 @@ var RDB = require('./redis'),
Topics.getTopicWithPosts = function(tid, current_user, start, end, callback) { Topics.getTopicWithPosts = function(tid, current_user, start, end, callback) {
threadTools.exists(tid, function(exists) { threadTools.exists(tid, function(exists) {
if (!exists) if (!exists) {
return callback(new Error('Topic tid \'' + tid + '\' not found')); return callback(new Error('Topic tid \'' + tid + '\' not found'));
}
Topics.markAsRead(tid, current_user); Topics.markAsRead(tid, current_user);
Topics.increaseViewCount(tid); Topics.increaseViewCount(tid);

Loading…
Cancel
Save