X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=715f6c37e8f94f8cedec4c28fa8a29f1c63867b0;hb=cb0b0e06ada73b22db31a37b0ba49d950bc7aeef;hp=f19b0d137629823bc735222398902228180d00a2;hpb=68f8e5e5c34fad6086af0c82d1dde64f67814297;p=Sone.git
diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js
index f19b0d1..715f6c3 100644
--- a/src/main/resources/static/javascript/sone.js
+++ b/src/main/resources/static/javascript/sone.js
@@ -1,8 +1,12 @@
/* Sone JavaScript functions. */
-function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName, optional) {
+function isOnline() {
+ return $("#sone").hasClass("online");
+}
+
+function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName, optional, dontUseTextarea) {
$(inputSelector).each(function() {
- textarea = $("").blur(function() {
+ textarea = $(dontUseTextarea ? "" : "").blur(function() {
if ($(this).val() == "") {
$(this).hide();
inputField = $(this).data("inputField");
@@ -42,6 +46,9 @@ function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName, o
/* hide all the âcreate replyâ forms until a link is clicked. */
function addCommentLinks() {
+ if (!isOnline()) {
+ return;
+ }
$("#sone .post").each(function() {
postId = $(this).attr("id");
commentElement = (function(postId) {
@@ -238,7 +245,7 @@ function getFormPassword() {
}
function getSoneElement(element) {
- return $(element).parent(".sone");
+ return $(element).parents(".sone");
}
/**
@@ -260,8 +267,16 @@ function getPostId(element) {
return getPostElement(element).attr("id");
}
+function getReplyElement(element) {
+ return $(element).parents(".reply");
+}
+
+function getReplyId(element) {
+ return getReplyElement(element).attr("id");
+}
+
function likePost(postId) {
- $.getJSON("ajax/likePost.ajax", { "post" : postId, "formPassword": getFormPassword() }, function() {
+ $.getJSON("ajax/like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function() {
$("#sone .post#" + postId + " > .status-line .like").addClass("hidden");
$("#sone .post#" + postId + " > .status-line .unlike").removeClass("hidden");
updatePostLikes(postId);
@@ -269,7 +284,7 @@ function likePost(postId) {
}
function unlikePost(postId) {
- $.getJSON("ajax/unlikePost.ajax", { "post" : postId, "formPassword": getFormPassword() }, function() {
+ $.getJSON("ajax/unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function() {
$("#sone .post#" + postId + " > .status-line .unlike").addClass("hidden");
$("#sone .post#" + postId + " > .status-line .like").removeClass("hidden");
updatePostLikes(postId);
@@ -277,9 +292,35 @@ function unlikePost(postId) {
}
function updatePostLikes(postId) {
- $.getJSON("ajax/getPostLikes.ajax", { "post": postId }, function(data, textStatus) {
+ $.getJSON("ajax/getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
if (data.success) {
+ $("#sone .post#" + postId + " > .status-line .likes").toggleClass("hidden", data.likes == 0)
$("#sone .post#" + postId + " > .status-line .likes span.like-count").text(data.likes);
}
});
}
+
+function likeReply(replyId) {
+ $.getJSON("ajax/like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function() {
+ $("#sone .reply#" + replyId + " .status-line .like").addClass("hidden");
+ $("#sone .reply#" + replyId + " .status-line .unlike").removeClass("hidden");
+ updateReplyLikes(replyId);
+ });
+}
+
+function unlikeReply(replyId) {
+ $.getJSON("ajax/unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function() {
+ $("#sone .reply#" + replyId + " .status-line .unlike").addClass("hidden");
+ $("#sone .reply#" + replyId + " .status-line .like").removeClass("hidden");
+ updateReplyLikes(replyId);
+ });
+}
+
+function updateReplyLikes(replyId) {
+ $.getJSON("ajax/getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
+ if (data.success) {
+ $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0)
+ $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
+ }
+ });
+}