mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 09:55:47 +01:00
recent unread cleanup
This commit is contained in:
@@ -1,53 +1,15 @@
|
||||
define(function() {
|
||||
define(['forum/recent'], function(recent) {
|
||||
var Unread = {},
|
||||
loadingMoreTopics = false;
|
||||
|
||||
Unread.init = function() {
|
||||
app.enterRoom('recent_posts');
|
||||
|
||||
ajaxify.register_events([
|
||||
'event:new_topic',
|
||||
'event:new_post',
|
||||
'topics.markAllRead'
|
||||
]);
|
||||
|
||||
var newTopicCount = 0,
|
||||
newPostCount = 0;
|
||||
|
||||
$('#new-topics-alert').on('click', function() {
|
||||
$(this).addClass('hide');
|
||||
});
|
||||
|
||||
socket.on('event:new_topic', function(data) {
|
||||
++newTopicCount;
|
||||
updateAlertText();
|
||||
});
|
||||
|
||||
function updateAlertText() {
|
||||
var text = 'There';
|
||||
|
||||
if (newTopicCount > 1) {
|
||||
text += ' are ' + newTopicCount + ' new topics';
|
||||
} else if (newTopicCount === 1) {
|
||||
text += ' is a new topic';
|
||||
}
|
||||
|
||||
if (newPostCount > 1) {
|
||||
text += (newTopicCount?' and ':' are ') + newPostCount + ' new posts';
|
||||
} else if(newPostCount === 1) {
|
||||
text += (newTopicCount?' and ':' is ') + ' a new post';
|
||||
}
|
||||
|
||||
text += '. Click here to reload.';
|
||||
|
||||
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
|
||||
$('#category-no-topics').addClass('hidden');
|
||||
}
|
||||
|
||||
socket.on('event:new_post', function(data) {
|
||||
++newPostCount;
|
||||
updateAlertText();
|
||||
});
|
||||
recent.watchForNewPosts();
|
||||
|
||||
$('#mark-allread-btn').on('click', function() {
|
||||
var btn = $(this);
|
||||
@@ -67,25 +29,20 @@ define(function() {
|
||||
});
|
||||
});
|
||||
|
||||
function onTopicsLoaded(topics) {
|
||||
|
||||
var html = templates.prepare(templates['unread'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var container = $('#topics-container');
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
html = $(translatedHTML);
|
||||
container.append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
});
|
||||
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
||||
$('#load-more-btn').show();
|
||||
}
|
||||
|
||||
$('#load-more-btn').on('click', function() {
|
||||
loadMoreTopics();
|
||||
});
|
||||
|
||||
app.enableInfiniteLoading(function() {
|
||||
if(!loadingMoreTopics) {
|
||||
loadMoreTopics();
|
||||
}
|
||||
});
|
||||
|
||||
function loadMoreTopics() {
|
||||
loadingMoreTopics = true;
|
||||
socket.emit('topics.loadMoreUnreadTopics', {
|
||||
@@ -96,7 +53,7 @@ define(function() {
|
||||
}
|
||||
|
||||
if (data.topics && data.topics.length) {
|
||||
onTopicsLoaded(data.topics);
|
||||
recent.onTopicsLoaded('unread', data.topics);
|
||||
$('#topics-container').attr('data-next-start', data.nextStart);
|
||||
} else {
|
||||
$('#load-more-btn').hide();
|
||||
@@ -105,23 +62,6 @@ define(function() {
|
||||
loadingMoreTopics = false;
|
||||
});
|
||||
}
|
||||
|
||||
$(window).off('scroll').on('scroll', function() {
|
||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
||||
|
||||
if ($(window).scrollTop() > bottom && !loadingMoreTopics) {
|
||||
loadMoreTopics();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
||||
$('#load-more-btn').show();
|
||||
}
|
||||
|
||||
$('#load-more-btn').on('click', function() {
|
||||
loadMoreTopics();
|
||||
});
|
||||
};
|
||||
|
||||
return Unread;
|
||||
|
||||
Reference in New Issue
Block a user