Node.js based forum software built for the modern web
remove IS topics on category
barisusakli41fb4fe6b5c9
diff --git a/public/src/client/category.js b/public/src/client/category.jsindex 11b80a59f5..9c383cabcc 100644--- a/public/src/client/category.js+++ b/public/src/client/category.js@@ -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;});\ No newline at end of filediff --git a/public/src/client/infinitescroll.js b/public/src/client/infinitescroll.jsindex 6aa9d203b1..4c79c52757 100644--- a/public/src/client/infinitescroll.js+++ b/public/src/client/infinitescroll.js@@ -8,17 +8,22 @@ define('forum/infinitescroll', ['translator'], function(translator) {var callback;var previousScrollTop = 0;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;- topOffset = _topOffest || 0;+ container = el || $(document);$(window).off('scroll', onScroll).on('scroll', onScroll);};function onScroll() {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;@@ -27,6 +32,7 @@ define('forum/infinitescroll', ['translator'], function(translator) {} else if (scrollPercent > bottom && currentScrollTop > previousScrollTop) {callback(1);}+previousScrollTop = currentScrollTop;}diff --git a/public/src/client/topic.js b/public/src/client/topic.jsindex bf83b7f8cd..da845b61d0 100644--- a/public/src/client/topic.js+++ b/public/src/client/topic.js@@ -192,7 +192,7 @@ define('forum/topic', [function enableInfiniteLoadingOrPagination() {if (!config.usePagination) {- infinitescroll.init(posts.loadMorePosts);+ infinitescroll.init($('[component="topic"]'), posts.loadMorePosts);} else {navigator.hide();diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex 55df9f54f3..d6fef49176 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -124,9 +124,9 @@ define('forum/topic/posts', [var after, before;- if (direction === 1 && repliesSelector.length) {+ if (direction > 0 && repliesSelector.length) {after = repliesSelector.last();- } else if (direction === -1 && repliesSelector.length) {+ } else if (direction < 0 && repliesSelector.length) {before = repliesSelector.first();}diff --git a/src/views/partials/data/topic.tpl b/src/views/partials/data/topic.tplindex 2a77407f48..d7fd1deb50 100644--- a/src/views/partials/data/topic.tpl+++ b/src/views/partials/data/topic.tpl@@ -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"\ No newline at end of file+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"\ No newline at end of file