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