Don’t copy the value, the input field is disabled anyway.
[Sone.git] / src / main / resources / static / javascript / sone.js
index 7fbdab9..200c870 100644 (file)
@@ -1,25 +1,26 @@
 /* Sone JavaScript functions. */
 
-function registerInputTextareaSwap(inputSelector, defaultText) {
-       (function(inputSelector, defaultText) {
-               $(inputSelector).focus(function() {
-                       if ($(this).hasClass("default")) {
-                               $(this).removeClass("default").val("");
-                       }
-               }).blur(function() {
-                       alert($(this).val());
+function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName) {
+       $(inputSelector).each(function() {
+               textarea = $("<textarea name=\"" + inputFieldName + "\"></textarea>").blur(function() {
                        if ($(this).val() == "") {
-                               alert("setting default");
-                               $(this).val(defaultText).addClass("default");
-                       }
-               }).addClass("default").val(defaultText);
-               $($(inputSelector).get(0).form).submit(function() {
-                       if ($(inputSelector).hasClass("default")) {
-                               $(inputSelector).val("");
+                               $(this).hide();
+                               $(this).data("inputField").show().removeAttr("disabled");
                        }
-                       alert(($(inputSelector).hasClass("default") ? "def: ": "ok: ") + $(inputSelector).val());
-               });
-       })(inputSelector, defaultText);
+               }).hide().data("inputField", $(this));
+               $(this).after(textarea);
+               (function(inputField, textarea) {
+                       $(inputField).focus(function() {
+                               $(this).hide().attr("disabled", "disabled");
+                               textarea.show().focus();
+                       }).addClass("default").val(defaultText);
+                       $(inputField.form).submit(function() {
+                               if (textarea.val() == "") {
+                                       return false;
+                               }
+                       });
+               })(this, textarea);
+       });
 }
 
 /* hide all the “create reply” forms until a link is clicked. */
@@ -27,7 +28,7 @@ function addCommentLinks() {
        $("#sone .post").each(function() {
                postId = $(this).attr("id");
                commentElement = (function(postId) {
-                       var commentElement = $("<div>Comment</div>").addClass("show-reply-form").click(function() {
+                       var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
                                replyElement = $("#sone .post#" + postId + " .create-reply");
                                replyElement.removeClass("hidden");
                                replyElement.removeClass("light");