X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=333d9d1fb65ff005a48887de7c8df396b4a7e8b5;hp=8e599ae1a881bbd311f42a2c7e4a2847a8146e9c;hb=HEAD;hpb=d0088e8e7dc1c3ca3feb29ad2f3e73f550d35a16 diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 8e599ae..333d9d1 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -495,74 +495,6 @@ function unlikeReply(replyId) { } /** - * Trusts the Sone with the given ID. - * - * @param soneId - * The ID of the Sone to trust - */ -function trustSone(soneId) { - ajaxGet("trustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data) { - if ((data != null) && data.success) { - updateTrustControls(soneId, data.trustValue); - } - }); -} - -/** - * Distrusts the Sone with the given ID, i.e. assigns a negative trust value. - * - * @param soneId - * The ID of the Sone to distrust - */ -function distrustSone(soneId) { - ajaxGet("distrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data) { - if ((data != null) && data.success) { - updateTrustControls(soneId, data.trustValue); - } - }); -} - -/** - * Untrusts the Sone with the given ID, i.e. removes any trust assignment. - * - * @param soneId - * The ID of the Sone to untrust - */ -function untrustSone(soneId) { - ajaxGet("untrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data) { - if ((data != null) && data.success) { - updateTrustControls(soneId, data.trustValue); - } - }); -} - -/** - * Updates the trust controls for all posts and replies of the given Sone, - * according to the given trust value. - * - * @param soneId - * The ID of the Sone to update all trust controls for - * @param trustValue - * The trust value for the Sone - */ -function updateTrustControls(soneId, trustValue) { - sone.find(".post").each(function() { - if (getPostAuthor(this) === soneId) { - getPostElement(this).find(".post-trust").toggleClass("hidden", trustValue != null); - getPostElement(this).find(".post-distrust").toggleClass("hidden", trustValue != null); - getPostElement(this).find(".post-untrust").toggleClass("hidden", trustValue == null); - } - }); - sone.find(".reply").each(function() { - if (getReplyAuthor(this) === soneId) { - getReplyElement(this).find(".reply-trust").toggleClass("hidden", trustValue != null); - getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null); - getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null); - } - }); -} - -/** * Bookmarks the post with the given ID. * * @param postId @@ -685,34 +617,38 @@ function ajaxifySone(soneElement) { }); } -const followSone = function(soneId) { - const followElement = this; - ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() { - $(followElement).addClass("hidden"); - $(followElement).parent().find(".unfollow").removeClass("hidden"); - sone.find(".sone-menu").each(function() { - if (getMenuSone(this) === soneId) { - $(".follow", this).toggleClass("hidden", true); - $(".unfollow", this).toggleClass("hidden", false); - } +function followSone(soneId) { + return function() { + const followElement = this; + ajaxGet("followSone.ajax", {"sone": soneId, "formPassword": getFormPassword()}, function () { + $(followElement).addClass("hidden"); + $(followElement).parent().find(".unfollow").removeClass("hidden"); + sone.find(".sone-menu").each(function () { + if (getMenuSone(this) === soneId) { + $(".follow", this).toggleClass("hidden", true); + $(".unfollow", this).toggleClass("hidden", false); + } + }); }); - }); - return false; -}; + return false; + } +} -const unfollowSone = function (soneId) { - const unfollowElement = this; - ajaxGet("unfollowSone.ajax", {"sone": soneId, "formPassword": getFormPassword()}, function () { - $(unfollowElement).addClass("hidden"); - $(unfollowElement).parent().find(".follow").removeClass("hidden"); - sone.find(".sone-menu").each(function () { - if (getMenuSone(this) === soneId) { - $(".follow", this).toggleClass("hidden", false); - $(".unfollow", this).toggleClass("hidden", true); - } +function unfollowSone(soneId) { + return function() { + const unfollowElement = this; + ajaxGet("unfollowSone.ajax", {"sone": soneId, "formPassword": getFormPassword()}, function () { + $(unfollowElement).addClass("hidden"); + $(unfollowElement).parent().find(".follow").removeClass("hidden"); + sone.find(".sone-menu").each(function () { + if (getMenuSone(this) === soneId) { + $(".follow", this).toggleClass("hidden", false); + $(".unfollow", this).toggleClass("hidden", true); + } + }); }); - }); - return false; + return false; + } }; /** @@ -769,20 +705,6 @@ function ajaxifyPost(postElement) { return false; }); - /* convert trust control buttons to javascript functions. */ - $(postElement).find(".post-trust").submit(function() { - trustSone(getPostAuthor(this)); - return false; - }); - $(postElement).find(".post-distrust").submit(function() { - distrustSone(getPostAuthor(this)); - return false; - }); - $(postElement).find(".post-untrust").submit(function() { - untrustSone(getPostAuthor(this)); - return false; - }); - /* convert bookmark/unbookmark buttons to javascript functions. */ $(postElement).find(".bookmark").submit(function() { bookmarkPost(getPostId(this)); @@ -968,20 +890,6 @@ function ajaxifyReply(replyElement) { $(replyElement).find(".expand-reply-text").each(toggleShowMore); $(replyElement).find(".shrink-reply-text").each(toggleShowMore); - /* convert trust control buttons to javascript functions. */ - $(replyElement).find(".reply-trust").submit(function() { - trustSone(getReplyAuthor(this)); - return false; - }); - $(replyElement).find(".reply-distrust").submit(function() { - distrustSone(getReplyAuthor(this)); - return false; - }); - $(replyElement).find(".reply-untrust").submit(function() { - untrustSone(getReplyAuthor(this)); - return false; - }); - /* show Sone menu when hovering over the avatar. */ $(replyElement).find(".reply-avatar").mouseover(function() { if (typeof currentSoneMenuTimeoutHandler !== undefined) { @@ -1273,7 +1181,7 @@ function getCurrentSoneId() { /** * Returns the content of the page-id attribute. * - * @returns The page ID + * @returns String The page ID */ function getPageId() { return sone.find(".page-id").text(); @@ -1617,7 +1525,7 @@ function updatePostTimes(postIds) { /** * Updates the time of the reply with the given ID. * - * @param postId + * @param replyId * The ID of the reply to update * @param timeText * The text of the time to show @@ -1638,7 +1546,7 @@ function updateReplyTime(replyId, timeText, refreshTime, tooltip) { /** * Requests new rendered times for the posts with the given IDs. * - * @param postIds + * @param replyIds * Comma-separated post IDs */ function updateReplyTimes(replyIds) {