mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-02 05:40:43 +01:00
fix: #7074
This commit is contained in:
@@ -20,12 +20,15 @@ define('topicList', [
|
||||
var newPostCount = 0;
|
||||
|
||||
var loadTopicsCallback;
|
||||
var topicListEl;
|
||||
|
||||
$(window).on('action:ajaxify.start', function () {
|
||||
TopicList.removeListeners();
|
||||
});
|
||||
|
||||
TopicList.init = function (template, cb) {
|
||||
topicListEl = findTopicListElement();
|
||||
|
||||
templateName = template;
|
||||
loadTopicsCallback = cb || loadTopicsAfter;
|
||||
|
||||
@@ -46,7 +49,7 @@ define('topicList', [
|
||||
});
|
||||
});
|
||||
|
||||
if ($('body').height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
|
||||
if ($('body').height() <= $(window).height() && topicListEl.children().length >= 20) {
|
||||
$('#load-more-btn').show();
|
||||
}
|
||||
|
||||
@@ -57,6 +60,12 @@ define('topicList', [
|
||||
$(window).trigger('action:topics.loaded', { topics: ajaxify.data.topics });
|
||||
};
|
||||
|
||||
function findTopicListElement() {
|
||||
return $('[component="category"]').filter(function (i, e) {
|
||||
return !$(e).parents('[widget-area]').length;
|
||||
});
|
||||
}
|
||||
|
||||
TopicList.watchForNewPosts = function () {
|
||||
$('#new-topics-alert').on('click', function () {
|
||||
$(this).addClass('hide');
|
||||
@@ -204,14 +213,14 @@ define('topicList', [
|
||||
};
|
||||
|
||||
TopicList.loadMoreTopics = function (direction) {
|
||||
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
|
||||
if (!topicListEl.length || !topicListEl.children().length) {
|
||||
return;
|
||||
}
|
||||
var topics = $('[component="category/topic"]');
|
||||
var topics = topicListEl.find('[component="category/topic"]');
|
||||
var afterEl = direction > 0 ? topics.last() : topics.first();
|
||||
var after = (parseInt(afterEl.attr('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||
|
||||
if (!utils.isNumber(after) || (after === 0 && $('[component="category/topic"][data-index="0"]').length)) {
|
||||
if (!utils.isNumber(after) || (after === 0 && topicListEl.find('[component="category/topic"][data-index="0"]').length)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -232,13 +241,13 @@ define('topicList', [
|
||||
query: query,
|
||||
term: ajaxify.data.selectedTerm.term,
|
||||
filter: ajaxify.data.selectedFilter.filter,
|
||||
set: $('[component="category"]').attr('data-set') ? $('[component="category"]').attr('data-set') : 'topics:recent',
|
||||
set: topicListEl.attr('data-set') ? topicListEl.attr('data-set') : 'topics:recent',
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function filterTopicsOnDom(topics) {
|
||||
return topics.filter(function (topic) {
|
||||
return !$('[component="category/topic"][data-tid="' + topic.tid + '"]').length;
|
||||
return !topicListEl.find('[component="category/topic"][data-tid="' + topic.tid + '"]').length;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -256,12 +265,12 @@ define('topicList', [
|
||||
|
||||
var after;
|
||||
var before;
|
||||
var topicsList = $('[component="category/topic"]');
|
||||
var topicEls = topicListEl.find('[component="category/topic"]');
|
||||
|
||||
if (direction > 0 && topics.length) {
|
||||
after = topicsList.last();
|
||||
after = topicEls.last();
|
||||
} else if (direction < 0 && topics.length) {
|
||||
before = topicsList.first();
|
||||
before = topicEls.first();
|
||||
}
|
||||
|
||||
var tplData = {
|
||||
@@ -274,7 +283,7 @@ define('topicList', [
|
||||
tplData.template[templateName] = true;
|
||||
|
||||
app.parseAndTranslate(templateName, 'topics', tplData, function (html) {
|
||||
$('[component="category"]').removeClass('hidden');
|
||||
topicListEl.removeClass('hidden');
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
if (after && after.length) {
|
||||
@@ -287,15 +296,15 @@ define('topicList', [
|
||||
|
||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||
} else {
|
||||
$('[component="category"]').append(html);
|
||||
topicListEl.append(html);
|
||||
}
|
||||
|
||||
if (!topicSelect.getSelectedTids().length) {
|
||||
infinitescroll.removeExtra($('[component="category/topic"]'), direction, config.topicsPerPage * 3);
|
||||
infinitescroll.removeExtra(topicListEl.find('[component="category/topic"]'), direction, config.topicsPerPage * 3);
|
||||
}
|
||||
|
||||
html.find('.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.createUserTooltips(html);
|
||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
$(window).trigger('action:topics.loaded', { topics: topics, template: templateName });
|
||||
callback();
|
||||
|
||||
Reference in New Issue
Block a user