summaryrefslogtreecommitdiff
path: root/modules/comment/js/comment.js
blob: 3c8097c69d42730408bef80935452e0890db9201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$("document").ready(function() {
  $("#g-admin-comment-button").click(function(event) {
    event.preventDefault();
    if (!$("#g-comment-form").length) {
      $.get($(this).attr("href"),
	    {},
	    function(data) {
	      $("#g-comment-detail").append(data);
	      ajaxify_comment_form();
	    });
    }
  });
  $("#g-no-comments").click(function(event) {
    event.preventDefault();
    if (!$("#g-comment-form").length) {
      $.get($(this).attr("href"),
	    {},
	    function(data) {
	      $("#g-comment-detail").append(data);
	      ajaxify_comment_form();
	    });
      $("#g-no-comments-yet").remove();
    }
  });
});

function ajaxify_comment_form() {
  $("#g-comments form").ajaxForm({
    dataType: "json",
    success: function(data) {
      if (data.result == "success") {
        $("#g-comments #g-comment-detail ul").append(data.view);
        $("#g-comments #g-comment-detail ul li:last").effect("highlight", {color: "#cfc"}, 8000);
        $("#g-comment-form").hide(2000).remove();
        $("#g-no-comments-yet").hide(2000);
      } else {
        if (data.form) {
          $("#g-comments form").replaceWith(data.form);
          ajaxify_comment_form();
        }
      }
    }
  });
}