Store Sone ID in a variable.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 1df8d42..05aab1d 100644 (file)
@@ -283,6 +283,18 @@ function getSoneElement(element) {
 }
 
 /**
+ * Returns the ID of the sone of the context menu that contains the given
+ * element.
+ *
+ * @param element
+ *            The element within a context menu to get the Sone ID for
+ * @return The Sone ID
+ */
+function getMenuSone(element) {
+       return $(element).closest(".sone-menu").find(".sone-id").text();
+}
+
+/**
  * Generates a list of Sones by concatening the names of the given sones with a
  * new line character (ā€œ\nā€).
  *
@@ -811,9 +823,10 @@ function ajaxifyPost(postElement) {
                return false;
        });
        (function(postElement) {
+               var soneId = $(".sone-id", postElement).text();
                $(".sone-post-menu .follow", postElement).click(function() {
                        var followElement = this;
-                       ajaxGet("followSone.ajax", { "sone": $(".sone-id", postElement).text(), "formPassword": getFormPassword() }, function() {
+                       ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
                                $(followElement).addClass("hidden");
                                $(followElement).parent().find(".unfollow").removeClass("hidden");
                        });
@@ -821,7 +834,7 @@ function ajaxifyPost(postElement) {
                });
                $(".sone-post-menu .unfollow", postElement).click(function() {
                        var unfollowElement = this;
-                       ajaxGet("unfollowSone.ajax", { "sone": $(".sone-id", postElement).text(), "formPassword": getFormPassword() }, function() {
+                       ajaxGet("unfollowSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
                                $(unfollowElement).addClass("hidden");
                                $(unfollowElement).parent().find(".follow").removeClass("hidden");
                        });