Skip to content

Node.js based forum software built for the modern web

move removeExtra to IS

barisusakli6457cd02ab7c
diff --git a/public/src/client/category.js b/public/src/client/category.js
index 9c383cabcc..7a295c1b28 100644
--- a/public/src/client/category.js
+++ b/public/src/client/category.js
@@ -10,6 +10,7 @@ define('forum/category', [
'sort',
'components',
'translator'
+
], function(pagination, infinitescroll, share, navigator, categoryTools, sort, components, translator) {
var Category = {};
@@ -307,60 +308,34 @@ define('forum/category', [
before = topics.first();
}
- templates.parse('category', 'topics', data, function(html) {
- translator.translate(html, function(translatedHTML) {
- var container = $('[component="category"]'),
- html = $(translatedHTML);
-
- $('[component="category"]').removeClass('hidden');
- $('.category-sidebar').removeClass('hidden');
-
- $('#category-no-topics').remove();
-
-
- 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 {
- container.append(html);
- }
-
- removeExtraTopics(direction);
+ infinitescroll.parseAndTranslate('category', 'topics', data, function(html) {
+ $('[component="category"]').removeClass('hidden');
+ $('.category-sidebar').removeClass('hidden');
- if (typeof callback === 'function') {
- callback();
- }
+ $('#category-no-topics').remove();
- html.find('.timeago').timeago();
- app.createUserTooltips();
- utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
- });
- });
- };
-
- function removeExtraTopics(direction) {
- var topics = $('[component="category/topic"]');
- if (topics.length > 60) {
- var removeCount = topics.length - 60;
- if (direction > 0) {
+ if (after) {
+ html.insertAfter(after);
+ } else if (before) {
var height = $(document).height(),
- scrollTop = $(window).scrollTop();
+ scrollTop = $(window).scrollTop();
- topics.slice(0, removeCount).remove();
+ html.insertBefore(before);
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
- topics.slice(topics.length - removeCount).remove();
+ $('[component="category"]').append(html);
}
- }
- }
+ infinitescroll.removeExtra($('[component="category/topic"]'), direction, 60);
+
+ html.find('.timeago').timeago();
+ app.createUserTooltips();
+ utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
+
+ callback();
+ });
+ };
return Category;
});
\ No newline at end of file
diff --git a/public/src/client/infinitescroll.js b/public/src/client/infinitescroll.js
index f55b3499df..39ede31eb6 100644
--- a/public/src/client/infinitescroll.js
+++ b/public/src/client/infinitescroll.js
@@ -68,5 +68,23 @@ define('forum/infinitescroll', ['translator'], function(translator) {
});
};
+ scroll.removeExtra = function(els, direction, count) {
+ if (els.length <= count) {
+ return;
+ }
+
+ var removeCount = els.length - count;
+ if (direction > 0) {
+ var height = $(document).height(),
+ scrollTop = $(window).scrollTop();
+
+ els.slice(0, removeCount).remove();
+
+ $(window).scrollTop(scrollTop + ($(document).height() - height));
+ } else {
+ els.slice(els.length - removeCount).remove();
+ }
+ };
+
return scroll;
});
\ No newline at end of file
diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js
index d6fef49176..3faf10fe58 100644
--- a/public/src/client/topic/posts.js
+++ b/public/src/client/topic/posts.js
@@ -152,7 +152,7 @@ define('forum/topic/posts', [
components.get('topic').append(html);
}
- removeExtraPosts(direction);
+ infinitescroll.removeExtra(components.get('posts'), direction, 40);
html.hide().fadeIn('slow');
@@ -167,23 +167,6 @@ define('forum/topic/posts', [
});
}
- function removeExtraPosts(direction) {
- var posts = components.get('post');
- if (posts.length > 40) {
- var removeCount = posts.length - 40;
- if (direction > 0) {
- var height = $(document).height(),
- scrollTop = $(window).scrollTop();
-
- posts.slice(0, removeCount).remove();
-
- $(window).scrollTop(scrollTop + ($(document).height() - height));
- } else {
- posts.slice(posts.length - removeCount).remove();
- }
- }
- }
-
function onNewPostsLoaded(html, pids) {
if (app.user.uid) {
socket.emit('posts.getPrivileges', pids, function(err, privileges) {