|
|
|
@ -172,7 +172,7 @@ define('forum/category', [
|
|
|
|
|
|
|
|
|
|
function enableInfiniteLoadingOrPagination() {
|
|
|
|
|
if (!config.usePagination) {
|
|
|
|
|
infinitescroll.init(Category.loadMoreTopics);
|
|
|
|
|
infinitescroll.init($('[component="category"]'), Category.loadMoreTopics);
|
|
|
|
|
} else {
|
|
|
|
|
navigator.hide();
|
|
|
|
|
pagination.init(ajaxify.data.currentPage, ajaxify.data.pageCount);
|
|
|
|
@ -245,46 +245,67 @@ define('forum/category', [
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Category.onTopicsLoaded = function(data, callback) {
|
|
|
|
|
if(!data || !data.topics.length) {
|
|
|
|
|
Category.loadMoreTopics = function(direction) {
|
|
|
|
|
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeAlreadyAddedTopics(topics) {
|
|
|
|
|
return topics.filter(function(topic) {
|
|
|
|
|
return components.get('category/topic', 'tid', topic.tid).length === 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var topics = $('[component="category/topic"]');
|
|
|
|
|
var afterEl = direction > 0 ? topics.last() : topics.first();
|
|
|
|
|
var after = parseInt(afterEl.attr('data-index'), 10) || 0;
|
|
|
|
|
|
|
|
|
|
var after = null,
|
|
|
|
|
before = null;
|
|
|
|
|
loadTopicsAfter(after, direction);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function findInsertionPoint() {
|
|
|
|
|
var topics = components.get('category/topic');
|
|
|
|
|
function loadTopicsAfter(after, direction, callback) {
|
|
|
|
|
if (!utils.isNumber(after) || (after === 0 && components.get('category/topic', 'index', 0).length)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!topics.length) {
|
|
|
|
|
return;
|
|
|
|
|
$(window).trigger('action:categories.loading');
|
|
|
|
|
infinitescroll.loadMore('categories.loadMore', {
|
|
|
|
|
cid: ajaxify.data.cid,
|
|
|
|
|
after: after,
|
|
|
|
|
direction: direction,
|
|
|
|
|
author: utils.params().author
|
|
|
|
|
}, function (data, done) {
|
|
|
|
|
if (data.topics && data.topics.length) {
|
|
|
|
|
Category.onTopicsLoaded(data, direction, done);
|
|
|
|
|
} else {
|
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var last = topics.last(),
|
|
|
|
|
lastIndex = last.attr('data-index'),
|
|
|
|
|
firstIndex = data.topics[data.topics.length - 1].index;
|
|
|
|
|
$(window).trigger('action:categories.loaded');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (firstIndex > lastIndex) {
|
|
|
|
|
after = last;
|
|
|
|
|
} else {
|
|
|
|
|
before = topics.first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Category.onTopicsLoaded = function(data, direction, callback) {
|
|
|
|
|
if (!data || !data.topics.length) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeAlreadyAddedTopics(topics) {
|
|
|
|
|
return topics.filter(function(topic) {
|
|
|
|
|
return components.get('category/topic', 'tid', topic.tid).length === 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.topics = removeAlreadyAddedTopics(data.topics);
|
|
|
|
|
if(!data.topics.length) {
|
|
|
|
|
return;
|
|
|
|
|
if (!data.topics.length) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.showSelect = data.privileges.editable;
|
|
|
|
|
|
|
|
|
|
findInsertionPoint();
|
|
|
|
|
var after, before;
|
|
|
|
|
var topics = $('[component="category/topic"]');
|
|
|
|
|
|
|
|
|
|
if (direction > 0 && topics.length) {
|
|
|
|
|
after = topics.last();
|
|
|
|
|
} else if (direction < 0 && topics.length) {
|
|
|
|
|
before = topics.first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
templates.parse('category', 'topics', data, function(html) {
|
|
|
|
|
translator.translate(html, function(translatedHTML) {
|
|
|
|
@ -296,21 +317,26 @@ define('forum/category', [
|
|
|
|
|
|
|
|
|
|
$('#category-no-topics').remove();
|
|
|
|
|
|
|
|
|
|
if(config.usePagination) {
|
|
|
|
|
container.empty().append(html);
|
|
|
|
|
|
|
|
|
|
if (after) {
|
|
|
|
|
html.insertAfter(after);
|
|
|
|
|
} else if (before) {
|
|
|
|
|
var height = $(document).height(),
|
|
|
|
|
scrollTop = $(window).scrollTop();
|
|
|
|
|
|
|
|
|
|
html.insertBefore(before);
|
|
|
|
|
|
|
|
|
|
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
|
|
|
|
} else {
|
|
|
|
|
if(after) {
|
|
|
|
|
html.insertAfter(after);
|
|
|
|
|
} else if(before) {
|
|
|
|
|
html.insertBefore(before);
|
|
|
|
|
} else {
|
|
|
|
|
container.append(html);
|
|
|
|
|
}
|
|
|
|
|
container.append(html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeExtraTopics(direction);
|
|
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html.find('.timeago').timeago();
|
|
|
|
|
app.createUserTooltips();
|
|
|
|
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
|
|
|
@ -318,48 +344,23 @@ define('forum/category', [
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Category.loadMoreTopics = function(direction) {
|
|
|
|
|
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
function removeExtraTopics(direction) {
|
|
|
|
|
var topics = $('[component="category/topic"]');
|
|
|
|
|
if (topics.length > 60) {
|
|
|
|
|
var removeCount = topics.length - 60;
|
|
|
|
|
if (direction > 0) {
|
|
|
|
|
var height = $(document).height(),
|
|
|
|
|
scrollTop = $(window).scrollTop();
|
|
|
|
|
|
|
|
|
|
var topics = components.get('category/topic');
|
|
|
|
|
var afterEl = direction > 0 ? topics.last() : topics.first();
|
|
|
|
|
var after = parseInt(afterEl.attr('data-index'), 10) || 0;
|
|
|
|
|
var offset = $('#header-menu').height();
|
|
|
|
|
|
|
|
|
|
loadTopicsAfter(after, direction, function() {
|
|
|
|
|
if (direction < 0 && afterEl.length) {
|
|
|
|
|
Category.scrollToTopic(afterEl.attr('data-index'), null, 0, offset);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function loadTopicsAfter(after, direction, callback) {
|
|
|
|
|
if (!utils.isNumber(after) || (after === 0 && components.get('category/topic', 'index', 0).length)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
topics.slice(0, removeCount).remove();
|
|
|
|
|
|
|
|
|
|
$(window).trigger('action:categories.loading');
|
|
|
|
|
infinitescroll.loadMore('categories.loadMore', {
|
|
|
|
|
cid: ajaxify.data.cid,
|
|
|
|
|
after: after,
|
|
|
|
|
direction: direction,
|
|
|
|
|
author: utils.params().author
|
|
|
|
|
}, function (data, done) {
|
|
|
|
|
if (data.topics && data.topics.length) {
|
|
|
|
|
Category.onTopicsLoaded(data, function() {
|
|
|
|
|
done();
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
|
|
|
|
} else {
|
|
|
|
|
done();
|
|
|
|
|
topics.slice(topics.length - removeCount).remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
|
|
|
|
$(window).trigger('action:categories.loaded');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Category;
|
|
|
|
|
});
|