From 5b918606faefea2616033d4e377af38f521d440e Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 29 Aug 2015 11:39:54 +0200 Subject: [PATCH] Display mobile reaction box only once --- app/assets/javascripts/mobile/mobile_comments.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js index ed50b4d7f..fbe557102 100644 --- a/app/assets/javascripts/mobile/mobile_comments.js +++ b/app/assets/javascripts/mobile/mobile_comments.js @@ -20,6 +20,7 @@ $(document).ready(function() { }); function toggleComments(toggleReactionsLink) { + if(toggleReactionsLink.hasClass("loading")) { return; } if (toggleReactionsLink.hasClass("active")) { hideComments(toggleReactionsLink); } else { @@ -48,21 +49,25 @@ $(document).ready(function() { } function showLoadedComments(toggleReactionsLink, existingCommentsContainer, commentActionLink) { + toggleReactionsLink.addClass("active"); existingCommentsContainer.show(); showCommentBox(commentActionLink); - toggleReactionsLink.addClass("active"); existingCommentsContainer.find("time.timeago").timeago(); } function showUnloadedComments(toggleReactionsLink, bottomBar, commentActionLink) { + toggleReactionsLink.addClass("loading"); var commentsContainer = commentsContainerLazy(bottomBar); $.ajax({ url: toggleReactionsLink.attr("href"), success: function (data) { + toggleReactionsLink.addClass("active").removeClass("loading"); $(data).insertAfter(bottomBar.children(".show_comments").first()); showCommentBox(commentActionLink); - toggleReactionsLink.addClass("active"); commentsContainer().find("time.timeago").timeago(); + }, + error: function() { + toggleReactionsLink.removeClass("loading"); } }); }