From: David ‘Bombe’ Roden Date: Thu, 20 Jan 2011 08:45:55 +0000 (+0100) Subject: Move ajaxification of a Sone to its own function. X-Git-Tag: 0.4.2^2~17 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=653193f3a6b61257cb295f985cb8da55645c00ff;p=Sone.git Move ajaxification of a Sone to its own function. --- diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 06e5daf..9eef811 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -537,6 +537,51 @@ function getReply(replyId, callbackFunction) { } /** + * Ajaxifies the given Sone by enhancing all eligible elements with AJAX. + * + * @param soneElement + * The Sone to ajaxify + */ +function ajaxifySone(soneElement) { + /* + * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something + * nicer. + */ + $(".follow", soneElement).submit(function() { + var followElement = this; + $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $(followElement).addClass("hidden"); + $(followElement).parent().find(".unfollow").removeClass("hidden"); + }); + return false; + }); + $(".unfollow", soneElement).submit(function() { + var unfollowElement = this; + $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $(unfollowElement).addClass("hidden"); + $(unfollowElement).parent().find(".follow").removeClass("hidden"); + }); + return false; + }); + $(".lock", soneElement).submit(function() { + var lockElement = this; + $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $(lockElement).addClass("hidden"); + $(lockElement).parent().find(".unlock").removeClass("hidden"); + }); + return false; + }); + $(".unlock", soneElement).submit(function() { + var unlockElement = this; + $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $(unlockElement).addClass("hidden"); + $(unlockElement).parent().find(".lock").removeClass("hidden"); + }); + return false; + }); +} + +/** * Ajaxifies the given post by enhancing all eligible elements with AJAX. * * @param postElement @@ -944,6 +989,20 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { }); } +/** + * Marks the given Sone as known if it is still new. + * + * @param soneElement + * The Sone to mark as known + */ +function markSoneAsKnown(soneElement) { + if ($(".new", soneElement).length > 0) { + $.getJSON("maskAsKnown.ajax", {"formPassword": getFormPassword(), "type": "sone", "id": getSoneId(soneElement)}, function(data, textStatus) { + $(soneElement).removeClass("new"); + }); + } +} + function markPostAsKnown(postElements) { $(postElements).each(function() { postElement = this; @@ -1187,41 +1246,8 @@ $(document).ready(function() { }); } - /* - * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something - * nicer. - */ - $("#sone .follow").submit(function() { - var followElement = this; - $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { - $(followElement).addClass("hidden"); - $(followElement).parent().find(".unfollow").removeClass("hidden"); - }); - return false; - }); - $("#sone .unfollow").submit(function() { - var unfollowElement = this; - $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { - $(unfollowElement).addClass("hidden"); - $(unfollowElement).parent().find(".follow").removeClass("hidden"); - }); - return false; - }); - $("#sone .lock").submit(function() { - var lockElement = this; - $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { - $(lockElement).addClass("hidden"); - $(lockElement).parent().find(".unlock").removeClass("hidden"); - }); - return false; - }); - $("#sone .unlock").submit(function() { - var unlockElement = this; - $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { - $(unlockElement).addClass("hidden"); - $(unlockElement).parent().find(".lock").removeClass("hidden"); - }); - return false; + $("#sone .sone").each(function() { + ajaxifySone($(this)); }); /* process all existing notifications, ajaxify dismiss buttons. */