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