Remove the “new” class from clicked items immediately.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 8f0aef7..251105a 100644 (file)
@@ -71,7 +71,6 @@ function addCommentLink(postId, element, insertAfterThisElement) {
        commentElement = (function(postId) {
                separator = $("<span> · </span>").addClass("separator");
                var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
-                       markPostAsKnown(getPostElement(this));
                        replyElement = $("#sone .post#" + postId + " .create-reply");
                        replyElement.removeClass("hidden");
                        replyElement.removeClass("light");
@@ -582,7 +581,7 @@ function ajaxifySone(soneElement) {
 
        /* mark Sone as known when clicking it. */
        $(soneElement).click(function() {
-               markSoneAsKnown(getSoneId(this));
+               markSoneAsKnown(soneElement);
        });
 }
 
@@ -606,7 +605,6 @@ function ajaxifyPost(postElement) {
                                if (success) {
                                        $(inputField).val("");
                                        loadNewReply(replyId, soneId, postId);
-                                       markPostAsKnown(getPostElement(inputField));
                                        $("#sone .post#" + postId + " .create-reply").addClass("hidden");
                                        $("#sone .post#" + postId + " .create-reply .sender").hide();
                                        $("#sone .post#" + postId + " .create-reply .select-sender").show();
@@ -630,12 +628,10 @@ function ajaxifyPost(postElement) {
        /* convert all “like” buttons to javascript functions. */
        $(postElement).find(".like-post").submit(function() {
                likePost(getPostId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        $(postElement).find(".unlike-post").submit(function() {
                unlikePost(getPostId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
 
@@ -698,12 +694,10 @@ function ajaxifyPost(postElement) {
 function ajaxifyReply(replyElement) {
        $(replyElement).find(".like-reply").submit(function() {
                likeReply(getReplyId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        $(replyElement).find(".unlike-reply").submit(function() {
                unlikeReply(getReplyId(this));
-               markPostAsKnown(getPostElement(this));
                return false;
        });
        (function(replyElement) {
@@ -728,11 +722,6 @@ function ajaxifyReply(replyElement) {
                untrustSone(getReplyAuthor(this));
                return false;
        });
-
-       /* mark post and all replies as known on click. */
-       $(replyElement).click(function() {
-               markPostAsKnown(getPostElement(this));
-       });
 }
 
 /**
@@ -776,8 +765,8 @@ function getStatus() {
                                oldNotification = $("#sone #notification-area .notification#" + value.id);
                                notification = ajaxifyNotification(createNotification(value.id, value.text, value.dismissable)).hide();
                                if (oldNotification.length != 0) {
-                                       if (oldNotification.find(".short-text").length > 0) {
-                                               opened = !oldNotification.find(".short-text").hasClass("hidden");
+                                       if ((oldNotification.find(".short-text").length > 0) && (notification.find(".short-text").length > 0)) {
+                                               opened = oldNotification.is(":visible") && oldNotification.find(".short-text").hasClass("hidden");
                                                notification.find(".short-text").toggleClass("hidden", opened);
                                                notification.find(".text").toggleClass("hidden", !opened);
                                        }
@@ -1013,10 +1002,9 @@ function markPostAsKnown(postElements) {
                postElement = this;
                if ($(postElement).hasClass("new")) {
                        (function(postElement) {
-                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) {
-                                       $(postElement).removeClass("new");
-                                       $(".click-to-show", postElement).removeClass("new");
-                               });
+                               $(postElement).removeClass("new");
+                               $(".click-to-show", postElement).removeClass("new");
+                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)});
                        })(postElement);
                }
        });
@@ -1028,9 +1016,8 @@ function markReplyAsKnown(replyElements) {
                replyElement = this;
                if ($(replyElement).hasClass("new")) {
                        (function(replyElement) {
-                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) {
-                                       $(replyElement).removeClass("new");
-                               });
+                               $(replyElement).removeClass("new");
+                               $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)});
                        })(replyElement);
                }
        });
@@ -1081,8 +1068,8 @@ function createNotification(id, text, dismissable) {
  *            The ID of the notification
  */
 function showNotificationDetails(notificationId) {
-       $("#sone .notification#" + notificationId + " .text").show();
-       $("#sone .notification#" + notificationId + " .short-text").hide();
+       $("#sone .notification#" + notificationId + " .text").removeClass("hidden");
+       $("#sone .notification#" + notificationId + " .short-text").addClass("hidden");
 }
 
 /**