v1.18.x
Barış Soner Uşaklı 6 years ago
parent aa877e7e0f
commit 2604cf6356

@ -20,12 +20,15 @@ define('topicList', [
var newPostCount = 0; var newPostCount = 0;
var loadTopicsCallback; var loadTopicsCallback;
var topicListEl;
$(window).on('action:ajaxify.start', function () { $(window).on('action:ajaxify.start', function () {
TopicList.removeListeners(); TopicList.removeListeners();
}); });
TopicList.init = function (template, cb) { TopicList.init = function (template, cb) {
topicListEl = findTopicListElement();
templateName = template; templateName = template;
loadTopicsCallback = cb || loadTopicsAfter; 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(); $('#load-more-btn').show();
} }
@ -57,6 +60,12 @@ define('topicList', [
$(window).trigger('action:topics.loaded', { topics: ajaxify.data.topics }); $(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 () { TopicList.watchForNewPosts = function () {
$('#new-topics-alert').on('click', function () { $('#new-topics-alert').on('click', function () {
$(this).addClass('hide'); $(this).addClass('hide');
@ -204,14 +213,14 @@ define('topicList', [
}; };
TopicList.loadMoreTopics = function (direction) { TopicList.loadMoreTopics = function (direction) {
if (!$('[component="category"]').length || !$('[component="category"]').children().length) { if (!topicListEl.length || !topicListEl.children().length) {
return; return;
} }
var topics = $('[component="category/topic"]'); var topics = topicListEl.find('[component="category/topic"]');
var afterEl = direction > 0 ? topics.last() : topics.first(); var afterEl = direction > 0 ? topics.last() : topics.first();
var after = (parseInt(afterEl.attr('data-index'), 10) || 0) + (direction > 0 ? 1 : 0); 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; return;
} }
@ -232,13 +241,13 @@ define('topicList', [
query: query, query: query,
term: ajaxify.data.selectedTerm.term, term: ajaxify.data.selectedTerm.term,
filter: ajaxify.data.selectedFilter.filter, 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); }, callback);
} }
function filterTopicsOnDom(topics) { function filterTopicsOnDom(topics) {
return topics.filter(function (topic) { 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 after;
var before; var before;
var topicsList = $('[component="category/topic"]'); var topicEls = topicListEl.find('[component="category/topic"]');
if (direction > 0 && topics.length) { if (direction > 0 && topics.length) {
after = topicsList.last(); after = topicEls.last();
} else if (direction < 0 && topics.length) { } else if (direction < 0 && topics.length) {
before = topicsList.first(); before = topicEls.first();
} }
var tplData = { var tplData = {
@ -274,7 +283,7 @@ define('topicList', [
tplData.template[templateName] = true; tplData.template[templateName] = true;
app.parseAndTranslate(templateName, 'topics', tplData, function (html) { app.parseAndTranslate(templateName, 'topics', tplData, function (html) {
$('[component="category"]').removeClass('hidden'); topicListEl.removeClass('hidden');
$('#category-no-topics').remove(); $('#category-no-topics').remove();
if (after && after.length) { if (after && after.length) {
@ -287,15 +296,15 @@ define('topicList', [
$(window).scrollTop(scrollTop + ($(document).height() - height)); $(window).scrollTop(scrollTop + ($(document).height() - height));
} else { } else {
$('[component="category"]').append(html); topicListEl.append(html);
} }
if (!topicSelect.getSelectedTids().length) { 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(); html.find('.timeago').timeago();
app.createUserTooltips(); app.createUserTooltips(html);
utils.makeNumbersHumanReadable(html.find('.human-readable-number')); utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
$(window).trigger('action:topics.loaded', { topics: topics, template: templateName }); $(window).trigger('action:topics.loaded', { topics: topics, template: templateName });
callback(); callback();

Loading…
Cancel
Save