From 6457cd02ab7c27d9a60a45d2499c8d1f7d29ca82 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 27 Sep 2015 15:20:10 -0400 Subject: [PATCH] move removeExtra to IS --- public/src/client/category.js | 65 +++++++++-------------------- public/src/client/infinitescroll.js | 18 ++++++++ public/src/client/topic/posts.js | 19 +-------- 3 files changed, 39 insertions(+), 63 deletions(-) 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) {