remove IS topics on category

ability to specify a container for IS, instead of always assuming
$(document)
v1.18.x
barisusakli 10 years ago
parent 5a77a2c21c
commit 41fb4fe6b5

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

@ -8,17 +8,22 @@ define('forum/infinitescroll', ['translator'], function(translator) {
var callback; var callback;
var previousScrollTop = 0; var previousScrollTop = 0;
var loadingMore = false; var loadingMore = false;
var topOffset = 0; var container;
scroll.init = function(cb, _topOffest) { scroll.init = function(el, cb) {
if (typeof el === 'function') {
cb = el;
el = null;
}
callback = cb; callback = cb;
topOffset = _topOffest || 0; container = el || $(document);
$(window).off('scroll', onScroll).on('scroll', onScroll); $(window).off('scroll', onScroll).on('scroll', onScroll);
}; };
function onScroll() { function onScroll() {
var currentScrollTop = $(window).scrollTop(); var currentScrollTop = $(window).scrollTop();
var scrollPercent = 100 * currentScrollTop / ($(document).height() - $(window).height()); var offsetTop = container.offset() ? container.offset().top : 0;
var scrollPercent = 100 * (currentScrollTop - offsetTop) / (container.height() - $(window).height());
var top = 20, bottom = 80; var top = 20, bottom = 80;
@ -27,6 +32,7 @@ define('forum/infinitescroll', ['translator'], function(translator) {
} else if (scrollPercent > bottom && currentScrollTop > previousScrollTop) { } else if (scrollPercent > bottom && currentScrollTop > previousScrollTop) {
callback(1); callback(1);
} }
previousScrollTop = currentScrollTop; previousScrollTop = currentScrollTop;
} }

@ -192,7 +192,7 @@ define('forum/topic', [
function enableInfiniteLoadingOrPagination() { function enableInfiniteLoadingOrPagination() {
if (!config.usePagination) { if (!config.usePagination) {
infinitescroll.init(posts.loadMorePosts); infinitescroll.init($('[component="topic"]'), posts.loadMorePosts);
} else { } else {
navigator.hide(); navigator.hide();

@ -124,9 +124,9 @@ define('forum/topic/posts', [
var after, before; var after, before;
if (direction === 1 && repliesSelector.length) { if (direction > 0 && repliesSelector.length) {
after = repliesSelector.last(); after = repliesSelector.last();
} else if (direction === -1 && repliesSelector.length) { } else if (direction < 0 && repliesSelector.length) {
before = repliesSelector.first(); before = repliesSelector.first();
} }

@ -1 +1 @@
data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}" data-timestamp="{posts.timestamp}" data-votes="{posts.votes}" itemscope itemtype="http://schema.org/Comment" data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}" itemscope itemtype="http://schema.org/Comment"
Loading…
Cancel
Save