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