X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=f19b0d137629823bc735222398902228180d00a2;hb=68f8e5e5c34fad6086af0c82d1dde64f67814297;hp=63b8361f5169c25cdafdbc84add012fa3150e827;hpb=c8f518f638aa16cf37145561b709d28252de213a;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 63b8361..f19b0d1 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -251,3 +251,35 @@ function getSoneElement(element) { function getSoneId(element) { return getSoneElement(element).find(".id").text(); } + +function getPostElement(element) { + return $(element).parents(".post"); +} + +function getPostId(element) { + return getPostElement(element).attr("id"); +} + +function likePost(postId) { + $.getJSON("ajax/likePost.ajax", { "post" : postId, "formPassword": getFormPassword() }, function() { + $("#sone .post#" + postId + " > .status-line .like").addClass("hidden"); + $("#sone .post#" + postId + " > .status-line .unlike").removeClass("hidden"); + updatePostLikes(postId); + }); +} + +function unlikePost(postId) { + $.getJSON("ajax/unlikePost.ajax", { "post" : postId, "formPassword": getFormPassword() }, function() { + $("#sone .post#" + postId + " > .status-line .unlike").addClass("hidden"); + $("#sone .post#" + postId + " > .status-line .like").removeClass("hidden"); + updatePostLikes(postId); + }); +} + +function updatePostLikes(postId) { + $.getJSON("ajax/getPostLikes.ajax", { "post": postId }, function(data, textStatus) { + if (data.success) { + $("#sone .post#" + postId + " > .status-line .likes span.like-count").text(data.likes); + } + }); +}