}
function getSoneElement(element) {
- return $(element).parents(".sone");
+ return $(element).closest(".sone");
}
/**
inputField = $(this.form).find(":input:enabled").get(0);
postId = getPostId(this);
text = $(inputField).val();
- $(inputField).val("");
- postReply(postId, text, function(success, error, replyId) {
- if (success) {
- loadNewReply(replyId);
- markPostAsKnown(getPostElement(inputField));
- $("#sone .post#" + postId + " .create-reply").addClass("hidden");
- } else {
- alert(error);
- }
- });
+ (function(postId, text, inputField) {
+ postReply(postId, text, function(success, error, replyId) {
+ if (success) {
+ $(inputField).val("");
+ loadNewReply(replyId);
+ markPostAsKnown(getPostElement(inputField));
+ $("#sone .post#" + postId + " .create-reply").addClass("hidden");
+ } else {
+ alert(error);
+ }
+ });
+ })(postId, text, inputField);
return false;
});
/* mark post and all replies as known on click. */
$(replyElement).click(function() {
- markPostAsKnown(getPostElement(replyElement));
+ markPostAsKnown(getPostElement(this));
});
}
if (postId in loadedPosts) {
return;
}
- loadedPosts[postId] = true;
$.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
- if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) {
+ if (data.post.id in loadedPosts) {
+ return;
+ }
+ loadedPosts[data.post.id] = true;
+ if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
return;
}
var firstOlderPost = null;
if (firstOlderPost != null) {
newPost.insertBefore(firstOlderPost);
} else {
- $("#sone .post:last").append(newPost);
+ $("#sone #posts").append(newPost);
}
ajaxifyPost(newPost);
newPost.slideDown();
if (replyId in loadedReplies) {
return;
}
- loadedReplies[replyId] = true;
$.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
+ if (data.reply.id in loadedReplies) {
+ return;
+ }
+ loadedReplies[data.reply.id] = true;
$("#sone .post#" + data.reply.postId).each(function() {
var firstNewerReply = null;
$(this).find(".replies .reply").each(function() {
ajaxifyReply(newReply);
newReply.slideDown();
setActivity();
+ return false;
});
}
});
});
});
+ /* 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("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "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) {