X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=7f0908997cacd415cb1fa9fc50a56edff51cb8fd;hb=dab7b61577baa725e3b9343f69787153b6375196;hp=3b61e29b561deb87cb2608fbb5f717db7501ef67;hpb=45abd9c2c690c31e2c251072f9e7633f02977e22;p=Sone.git
diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js
index 3b61e29..7f09089 100644
--- a/src/main/resources/static/javascript/sone.js
+++ b/src/main/resources/static/javascript/sone.js
@@ -69,6 +69,7 @@ function addCommentLink(postId, element) {
}
commentElement = (function(postId) {
var commentElement = $("
Comment
").addClass("show-reply-form").click(function() {
+ markPostAsKnown(getPostElement(this));
replyElement = $("#sone .post#" + postId + " .create-reply");
replyElement.removeClass("hidden");
replyElement.removeClass("light");
@@ -454,8 +455,7 @@ function ajaxifyPost(postElement) {
postReply(postId, text, function(success, error, replyId) {
if (success) {
loadNewReply(replyId);
- markPostAsKnown(postElement);
- markReplyAsKnown($(postElement).find(".reply"));
+ markPostAsKnown(getPostElement(inputField));
$("#sone .post#" + postId + " .create-reply").addClass("hidden");
} else {
alert(error);
@@ -475,10 +475,12 @@ 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;
});
@@ -511,10 +513,12 @@ 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) {
@@ -565,6 +569,7 @@ function getStatus() {
$("#sone #notification-area").append(notification);
notification.slideDown();
}
+ setActivity();
});
$.each(data.removedNotifications, function(index, value) {
$("#sone #notification-area .notification#" + value.id).slideUp();
@@ -614,6 +619,7 @@ function loadNewPost(postId) {
}
ajaxifyPost(newPost);
newPost.slideDown();
+ setActivity();
}
});
}
@@ -646,6 +652,7 @@ function loadNewReply(replyId) {
}
ajaxifyReply(newReply);
newReply.slideDown();
+ setActivity();
});
}
});
@@ -655,9 +662,11 @@ function markPostAsKnown(postElements) {
$(postElements).each(function() {
postElement = this;
if ($(postElement).hasClass("new")) {
- $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
- $(postElement).removeClass("new");
- });
+ (function(postElement) {
+ $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
+ $(postElement).removeClass("new");
+ });
+ })(postElement);
}
});
markReplyAsKnown($(postElements).find(".reply"));
@@ -667,13 +676,29 @@ function markReplyAsKnown(replyElements) {
$(replyElements).each(function() {
replyElement = this;
if ($(replyElement).hasClass("new")) {
- $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
- $(replyElement).removeClass("new");
- });
+ (function(replyElement) {
+ $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
+ $(replyElement).removeClass("new");
+ });
+ })(replyElement);
}
});
}
+function resetActivity() {
+ title = document.title;
+ if (title.indexOf('(') == 0) {
+ document.title = title.substr(title.indexOf(' ') + 1);
+ }
+}
+
+function setActivity() {
+ title = document.title;
+ if (title.indexOf('(') != 0) {
+ document.title = "(!) " + title;
+ }
+}
+
/**
* Creates a new notification.
*
@@ -717,6 +742,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) {
@@ -799,4 +839,10 @@ $(document).ready(function() {
/* activate status polling. */
setTimeout(getStatus, 5000);
+
+ /* reset activity counter when the page has focus. */
+ $(window).focus(function() {
+ resetActivity();
+ });
+
});