From 2604cf635634229773049b352d7e17698fa7c440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 6 Dec 2018 20:54:45 -0500 Subject: [PATCH] fix: #7074 --- public/src/modules/topicList.js | 35 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 15db0a6476..a6399d6087 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -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();