Don’t copy the value, the input field is disabled anyway.
[Sone.git] / src / main / resources / static / javascript / sone.js
1 /* Sone JavaScript functions. */
2
3 function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName) {
4         $(inputSelector).each(function() {
5                 textarea = $("<textarea name=\"" + inputFieldName + "\"></textarea>").blur(function() {
6                         if ($(this).val() == "") {
7                                 $(this).hide();
8                                 $(this).data("inputField").show().removeAttr("disabled");
9                         }
10                 }).hide().data("inputField", $(this));
11                 $(this).after(textarea);
12                 (function(inputField, textarea) {
13                         $(inputField).focus(function() {
14                                 $(this).hide().attr("disabled", "disabled");
15                                 textarea.show().focus();
16                         }).addClass("default").val(defaultText);
17                         $(inputField.form).submit(function() {
18                                 if (textarea.val() == "") {
19                                         return false;
20                                 }
21                         });
22                 })(this, textarea);
23         });
24 }
25
26 /* hide all the “create reply” forms until a link is clicked. */
27 function addCommentLinks() {
28         $("#sone .post").each(function() {
29                 postId = $(this).attr("id");
30                 commentElement = (function(postId) {
31                         var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
32                                 replyElement = $("#sone .post#" + postId + " .create-reply");
33                                 replyElement.removeClass("hidden");
34                                 replyElement.removeClass("light");
35                                 (function(replyElement) {
36                                         replyElement.find("input.reply-input").blur(function() {
37                                                 if ($(this).hasClass("default")) {
38                                                         replyElement.addClass("light");
39                                                 }
40                                         }).focus(function() {
41                                                 replyElement.removeClass("light");
42                                         });
43                                 })(replyElement);
44                                 replyElement.find("input.reply-input").focus();
45                         });
46                         return commentElement;
47                 })(postId);
48                 $(this).find(".create-reply").addClass("hidden");
49                 $(this).find(".status-line .time").each(function() {
50                         $(this).after(commentElement.clone(true));
51                 });
52         });
53 }