From e4fbb31e68caa9ff4e5bbfb2a1e2dd2ec4e5f5b0 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 25 Mar 2014 13:24:51 -0400 Subject: [PATCH] some cleanup --- public/src/forum/topic.js | 28 ++++++++++------------------ src/topics/posts.js | 3 ++- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 45ba58259a..f89e4af806 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -38,14 +38,10 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], $(window).trigger('action:topic.loading'); - function fixDeleteStateForPosts() { - var postEls = $('#post-container li[data-deleted]'); - for (var x = 0, numPosts = postEls.length; x < numPosts; x++) { - if (postEls.eq(x).attr('data-deleted') === '1') { - toggle_post_delete_state(postEls.eq(x).attr('data-pid')); - } - postEls.eq(x).removeAttr('data-deleted'); - } + function hidePostToolsForDeletedPosts() { + $('#post-container li.deleted').each(function() { + toggle_post_tools($(this).attr('data-pid'), true); + }); } $(function() { @@ -70,7 +66,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], postTools.init(tid, thread_state); threadTools.init(tid, thread_state); - fixDeleteStateForPosts(); + hidePostToolsForDeletedPosts(); enableInfiniteLoading(); @@ -121,10 +117,10 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], var after = 0; var el = null; if(direction > 0) { - el = $('#post-container .post-row.infiniteloaded').last(); + el = $('#post-container .post-row').last(); after = parseInt(el.attr('data-index'), 10) + 1; } else { - el = $('#post-container .post-row.infiniteloaded').first(); + el = $('#post-container .post-row').first(); after = parseInt(el.attr('data-index'), 10); after -= config.postsPerPage; if(after < 0) { @@ -135,7 +131,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], var offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height(); loadMorePosts(tid, after, function() { - fixDeleteStateForPosts(); + hidePostToolsForDeletedPosts(); if(direction < 0 && el) { Topic.scrollToPost(el.attr('data-pid'), false, 0, offset); } @@ -702,7 +698,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], }); } - function createNewPosts(data, infiniteLoaded, callback) { + function createNewPosts(data, callback) { if(!data || (data.posts && !data.posts.length)) { return; } @@ -751,10 +747,6 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], parseAndTranslatePosts(data, function(translatedHTML) { var translated = $(translatedHTML); - if(!infiniteLoaded) { - translated.removeClass('infiniteloaded'); - } - if(after) { translated.insertAfter(after); } else if(before) { @@ -851,7 +843,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], } if (data && data.posts && data.posts.length) { - createNewPosts(data, true, callback); + createNewPosts(data, callback); } else { updateHeader(); if (typeof callback === 'function') { diff --git a/src/topics/posts.js b/src/topics/posts.js index a90be8fd0d..f75c9bff3a 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -61,6 +61,7 @@ module.exports = function(Topics) { } for (var i = 0; i < postData.length; ++i) { + postData[i].deleted = parseInt(postData[i].deleted, 10) === 1; postData[i].favourited = results.favourites[i]; postData[i].upvoted = results.voteData[i].upvoted; postData[i].downvoted = results.voteData[i].downvoted; @@ -68,7 +69,7 @@ module.exports = function(Topics) { postData[i].display_moderator_tools = parseInt(uid, 10) !== 0 && results.privileges[i].editable; postData[i].display_move_tools = results.privileges[i].move; - if(parseInt(postData[i].deleted, 10) === 1 && !results.privileges[i].view_deleted) { + if(postData[i].deleted && !results.privileges[i].view_deleted) { postData[i].content = 'This post is deleted!'; } }