mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
fixes to infinitescroll
This commit is contained in:
@@ -20,21 +20,24 @@ define('forum/account/favourites', ['forum/account/header', 'forum/infinitescrol
|
|||||||
|
|
||||||
infinitescroll.loadMore('posts.loadMoreFavourites', {
|
infinitescroll.loadMore('posts.loadMoreFavourites', {
|
||||||
after: $('.user-favourite-posts').attr('data-nextstart')
|
after: $('.user-favourite-posts').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.posts && data.posts.length) {
|
if (data.posts && data.posts.length) {
|
||||||
onPostsLoaded(data.posts);
|
onPostsLoaded(data.posts, done);
|
||||||
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
|
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPostsLoaded(posts) {
|
function onPostsLoaded(posts, callback) {
|
||||||
infinitescroll.parseAndTranslate('account/favourites', 'posts', {posts: posts}, function(html) {
|
infinitescroll.parseAndTranslate('account/favourites', 'posts', {posts: posts}, function(html) {
|
||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
html.find('img').addClass('img-responsive');
|
html.find('img').addClass('img-responsive');
|
||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,21 +21,24 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'],
|
|||||||
infinitescroll.loadMore('posts.loadMoreUserPosts', {
|
infinitescroll.loadMore('posts.loadMoreUserPosts', {
|
||||||
uid: $('.account-username-box').attr('data-uid'),
|
uid: $('.account-username-box').attr('data-uid'),
|
||||||
after: $('.user-favourite-posts').attr('data-nextstart')
|
after: $('.user-favourite-posts').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.posts && data.posts.length) {
|
if (data.posts && data.posts.length) {
|
||||||
onPostsLoaded(data.posts);
|
onPostsLoaded(data.posts, done);
|
||||||
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
|
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPostsLoaded(posts) {
|
function onPostsLoaded(posts, callback) {
|
||||||
infinitescroll.parseAndTranslate('account/posts', 'posts', {posts: posts}, function(html) {
|
infinitescroll.parseAndTranslate('account/posts', 'posts', {posts: posts}, function(html) {
|
||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
html.find('img').addClass('img-responsive');
|
html.find('img').addClass('img-responsive');
|
||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,21 +19,24 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
|
|||||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||||
set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics',
|
set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics',
|
||||||
after: $('.user-topics').attr('data-nextstart')
|
after: $('.user-topics').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
|
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
onTopicsLoaded(data.topics);
|
onTopicsLoaded(data.topics, done);
|
||||||
$('.user-topics').attr('data-nextstart', data.nextStart);
|
$('.user-topics').attr('data-nextstart', data.nextStart);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTopicsLoaded(topics) {
|
function onTopicsLoaded(topics, callback) {
|
||||||
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
|
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
|
||||||
$('#topics-container').append(html);
|
$('#topics-container').append(html);
|
||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,11 +294,16 @@ define('forum/category', ['composer', 'forum/pagination', 'forum/infinitescroll'
|
|||||||
infinitescroll.loadMore('categories.loadMore', {
|
infinitescroll.loadMore('categories.loadMore', {
|
||||||
cid: ajaxify.variables.get('category_id'),
|
cid: ajaxify.variables.get('category_id'),
|
||||||
after: after
|
after: after
|
||||||
}, function (data) {
|
}, function (data, done) {
|
||||||
|
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
Category.onTopicsLoaded(data, callback);
|
Category.onTopicsLoaded(data, function() {
|
||||||
|
done();
|
||||||
|
callback();
|
||||||
|
});
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).trigger('action:categories.loaded');
|
$(window).trigger('action:categories.loaded');
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ define('forum/infinitescroll', function() {
|
|||||||
loadingMore = true;
|
loadingMore = true;
|
||||||
socket.emit(method, data, function(err, data) {
|
socket.emit(method, data, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
loadingMore = false;
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
callback(data);
|
callback(data, function() {
|
||||||
loadingMore = false;
|
loadingMore = false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ define('forum/popular', ['forum/recent', 'forum/infinitescroll'], function(recen
|
|||||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||||
set: 'topics:' + $('.nav-pills .active a').html().toLowerCase(),
|
set: 'topics:' + $('.nav-pills .active a').html().toLowerCase(),
|
||||||
after: $('#topics-container').attr('data-nextstart')
|
after: $('#topics-container').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
recent.onTopicsLoaded('popular', data.topics, false);
|
recent.onTopicsLoaded('popular', data.topics, false, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
|
done();
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -105,15 +105,17 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
|
|||||||
infinitescroll.loadMore('topics.loadMoreRecentTopics', {
|
infinitescroll.loadMore('topics.loadMoreRecentTopics', {
|
||||||
after: $('#topics-container').attr('data-nextstart'),
|
after: $('#topics-container').attr('data-nextstart'),
|
||||||
term: active
|
term: active
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
Recent.onTopicsLoaded('recent', data.topics, false);
|
Recent.onTopicsLoaded('recent', data.topics, false, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Recent.onTopicsLoaded = function(templateName, topics, showSelect) {
|
Recent.onTopicsLoaded = function(templateName, topics, showSelect, callback) {
|
||||||
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
|
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
@@ -121,6 +123,7 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) {
|
|||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
|
|||||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||||
set: 'tag:' + ajaxify.variables.get('tag') + ':topics',
|
set: 'tag:' + ajaxify.variables.get('tag') + ':topics',
|
||||||
after: $('#topics-container').attr('data-nextstart')
|
after: $('#topics-container').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
recent.onTopicsLoaded('tag', data.topics, false);
|
recent.onTopicsLoaded('tag', data.topics, false, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
|
done();
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -229,6 +229,8 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
|||||||
scrollingToPost = false;
|
scrollingToPost = false;
|
||||||
navigator.update();
|
navigator.update();
|
||||||
highlightPost();
|
highlightPost();
|
||||||
|
$('body').scrollTop($('body').scrollTop() - 1);
|
||||||
|
$('html').scrollTop($('html').scrollTop() - 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,15 +396,19 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
|||||||
infinitescroll.loadMore('topics.loadMore', {
|
infinitescroll.loadMore('topics.loadMore', {
|
||||||
tid: tid,
|
tid: tid,
|
||||||
after: after
|
after: after
|
||||||
}, function (data) {
|
}, function (data, done) {
|
||||||
|
|
||||||
indicatorEl.fadeOut();
|
indicatorEl.fadeOut();
|
||||||
|
|
||||||
if (data && data.posts && data.posts.length) {
|
if (data && data.posts && data.posts.length) {
|
||||||
createNewPosts(data, callback);
|
createNewPosts(data, function() {
|
||||||
|
done();
|
||||||
|
callback();
|
||||||
|
});
|
||||||
hidePostToolsForDeletedPosts();
|
hidePostToolsForDeletedPosts();
|
||||||
} else {
|
} else {
|
||||||
navigator.update();
|
navigator.update();
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,11 +94,12 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
|
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
|
||||||
after: $('#topics-container').attr('data-nextstart')
|
after: $('#topics-container').attr('data-nextstart')
|
||||||
}, function(data) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
recent.onTopicsLoaded('unread', data.topics, true);
|
recent.onTopicsLoaded('unread', data.topics, true, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('#topics-container').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
|
done();
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,45 +21,37 @@ topicsController.get = function(req, res, next) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
privileges.topics.get(tid, uid, function(err, privileges) {
|
privileges.topics.get(tid, uid, next);
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.read) {
|
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
userPrivileges = privileges;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function (next) {
|
function (privileges, next) {
|
||||||
user.getSettings(uid, function(err, settings) {
|
if (!privileges.read) {
|
||||||
if (err) {
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
return next(err);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var postIndex = 0;
|
userPrivileges = privileges;
|
||||||
if (!settings.usePagination) {
|
|
||||||
postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage), 0);
|
|
||||||
} else if (!req.query.page) {
|
|
||||||
var index = Math.max(parseInt((req.params.post_index || 0), 10), 0);
|
|
||||||
page = Math.ceil((index + 1) / settings.postsPerPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
var start = (page - 1) * settings.postsPerPage + postIndex,
|
user.getSettings(uid, next);
|
||||||
end = start + settings.postsPerPage - 1 + postIndex;
|
},
|
||||||
|
function (settings, next) {
|
||||||
|
var postIndex = 0;
|
||||||
|
if (!settings.usePagination) {
|
||||||
|
postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage - 1), 0);
|
||||||
|
} else if (!req.query.page) {
|
||||||
|
var index = Math.max(parseInt((req.params.post_index || 0), 10), 0);
|
||||||
|
page = Math.ceil((index + 1) / settings.postsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
var start = (page - 1) * settings.postsPerPage + postIndex,
|
||||||
if (topicData) {
|
end = start + settings.postsPerPage - 1;
|
||||||
if (parseInt(topicData.deleted, 10) === 1 && !userPrivileges.view_deleted) {
|
|
||||||
return next(new Error('[[error:no-topic]]'));
|
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
||||||
}
|
if (topicData) {
|
||||||
topicData.currentPage = page;
|
if (parseInt(topicData.deleted, 10) === 1 && !userPrivileges.view_deleted) {
|
||||||
|
return next(new Error('[[error:no-topic]]'));
|
||||||
}
|
}
|
||||||
next(err, topicData);
|
topicData.currentPage = page;
|
||||||
});
|
}
|
||||||
|
next(err, topicData);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
|
|||||||
@@ -79,6 +79,21 @@ middleware.addSlug = function(req, res, next) {
|
|||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
middleware.checkPostIndex = function(req, res, next) {
|
||||||
|
topics.getPostCount(req.params.topic_id, function(err, postCount) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
var postIndex = parseInt(req.params.post_index, 10);
|
||||||
|
if (postIndex > postCount) {
|
||||||
|
return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount);
|
||||||
|
} else if (postIndex <= 1) {
|
||||||
|
return res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
middleware.prepareAPI = function(req, res, next) {
|
middleware.prepareAPI = function(req, res, next) {
|
||||||
res.locals.isAPI = true;
|
res.locals.isAPI = true;
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ function staticRoutes(app, middleware, controllers) {
|
|||||||
function topicRoutes(app, middleware, controllers) {
|
function topicRoutes(app, middleware, controllers) {
|
||||||
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
|
app.get('/api/topic/teaser/:topic_id', controllers.topics.teaser);
|
||||||
|
|
||||||
app.get('/topic/:topic_id/:slug/:post_index?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
app.get('/topic/:topic_id/:slug/:post_index?', middleware.buildHeader, middleware.checkPostIndex, controllers.topics.get);
|
||||||
app.get('/api/topic/:topic_id/:slug/:post_index?', controllers.topics.get);
|
app.get('/api/topic/:topic_id/:slug/:post_index?', middleware.checkPostIndex, controllers.topics.get);
|
||||||
|
|
||||||
app.get('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
app.get('/topic/:topic_id/:slug?', middleware.buildHeader, middleware.addSlug, controllers.topics.get);
|
||||||
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
|
app.get('/api/topic/:topic_id/:slug?', controllers.topics.get);
|
||||||
|
|||||||
@@ -157,5 +157,8 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.getPostCount = function(tid, callback) {
|
||||||
|
db.sortedSetCard('tid:' + tid + ':posts', callback);
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user