Merge commit '0.3.1-RC3' into message-recipient
[Sone.git] / src / main / resources / static / javascript / sone.js
index 3a84d9c..75facb3 100644 (file)
@@ -63,7 +63,7 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op
  * @param element
  *            The element to add a “comment” link to
  */
-function addCommentLink(postId, element) {
+function addCommentLink(postId, element, insertAfterThisElement) {
        if ($(element).find(".show-reply-form").length > 0) {
                return;
        }
@@ -86,9 +86,7 @@ function addCommentLink(postId, element) {
                });
                return commentElement;
        })(postId);
-       $(element).find(".status-line .time").each(function() {
-               $(this).after(commentElement.clone(true));
-       });
+       $(insertAfterThisElement).after(commentElement.clone(true));
 }
 
 var translations = {};
@@ -484,6 +482,9 @@ function ajaxifyPost(postElement) {
                return false;
        });
 
+       /* add “comment” link. */
+       addCommentLink(getPostId(postElement), postElement, $(postElement).find(".post-status-line .time"));
+
        /* process all replies. */
        $(postElement).find(".reply").each(function() {
                ajaxifyReply(this);
@@ -496,8 +497,10 @@ function ajaxifyPost(postElement) {
                });
        });
 
-       /* add “comment” link. */
-       addCommentLink(getPostId(postElement), postElement);
+       /* mark everything as known on click. */
+       $(postElement).click(function() {
+               markPostAsKnown(this);
+       });
 
        /* hide reply input field. */
        $(postElement).find(".create-reply").addClass("hidden");
@@ -527,7 +530,12 @@ function ajaxifyReply(replyElement) {
                        });
                });
        })(replyElement);
-       addCommentLink(getPostId(replyElement), replyElement);
+       addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time"));
+
+       /* mark post and all replies as known on click. */
+       $(replyElement).click(function() {
+               markPostAsKnown(getPostElement(replyElement));
+       });
 }
 
 /**
@@ -692,9 +700,11 @@ function resetActivity() {
 }
 
 function setActivity() {
-       title = document.title;
-       if (title.indexOf('(') != 0) {
-               document.title = "(!) " + title;
+       if (!focus) {
+               title = document.title;
+               if (title.indexOf('(') != 0) {
+                       document.title = "(!) " + title;
+               }
        }
 }
 
@@ -724,6 +734,8 @@ function createNotification(id, text, dismissable) {
 // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE
 //
 
+var focus = true;
+
 $(document).ready(function() {
 
        /* this initializes the status update input field. */
@@ -741,6 +753,21 @@ $(document).ready(function() {
                });
        });
 
+       /* ajaxify input field on “view Sone” page. */
+       getTranslation("WebInterface.DefaultText.Message", function(defaultText) {
+               registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false);
+               $("#sone #post-message").submit(function() {
+                       text = $(this).find(":input:enabled").val();
+                       $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "recipient": $("#sone #sone-id").text(), "text": text }, function(data, textStatus) {
+                               if ((data != null) && data.success) {
+                                       loadNewPost(data.postId);
+                               }
+                       });
+                       $(this).find(":input:enabled").val("").blur();
+                       return false;
+               });
+       });
+
        /* Ajaxifies all posts. */
        /* calling getTranslation here will cache the necessary values. */
        getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {
@@ -826,7 +853,10 @@ $(document).ready(function() {
 
        /* reset activity counter when the page has focus. */
        $(window).focus(function() {
+               focus = true;
                resetActivity();
-       });
+       }).blur(function() {
+               focus = false;
+       })
 
 });