hsbook_back.js
author amit
Thu, 30 Sep 2010 15:59:32 +0530
changeset 1 5574cfc2b28d
parent 0 54f784230511
child 2 f5e18f8ed036
permissions -rw-r--r--
Adding the sphinx builder script simplecomment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     1
function qid(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     2
  return id.replace(/([.:])/g, "\\$1");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     3
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     4
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     5
function beforeComment(formData, jqForm, options) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     6
  var form = jqForm[0];
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     7
  if (!form.comment.value) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     8
    $(options.target + " span.comment_error").empty().append(
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
     9
      "<span class=\"comment_error\">Your comment is empty</span>");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    10
    return false;
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    11
  }
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    12
  if (!form.name.value) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    13
    $(options.target + " span.comment_error").empty().append(
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    14
      "<span class=\"comment_error\">Please provide a name</span>");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    15
    return false;
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    16
  }
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    17
  $(options.target + " span.comment_error").empty().after(
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    18
    "<img src=\"/support/icons/throbber.gif\" style=\"vertical-align: middle\"/>");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    19
  $(options.target + " input[@name=submit]").attr("disabled", true);
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    20
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    21
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    22
function ajaxifyForm(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    23
  var q = qid(id);
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    24
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    25
  $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment,
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    26
			     success: function() { ajaxifyForm(id); },
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    27
			     target: "#comments_" + q });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    28
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    29
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    30
function toggleComment(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    31
  $("#toggle_" + qid(id)).nextAll().toggle();
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    32
  return false;
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    33
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    34
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    35
function loadComments(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    36
  $("#comments_" + qid(id)).load(location.protocol + "//" + location.host +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    37
				 "/comments/single/" + id + "/", function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    38
    ajaxifyForm(id);
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    39
  });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    40
  return false;
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    41
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    42
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    43
function loadAllComments() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    44
  $("a.commenttoggle").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    45
    var id = $(this).attr("pid");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    46
    if (id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    47
      loadComments(id);
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    48
    }
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    49
  });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    50
}
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    51
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    52
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    53
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    54
$(document).ready(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    55
  function loading(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    56
    return " <span id=\"comments_" + id + "\" class=\"comment\">" +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    57
      "<span pid=\"" + id + "\" class=\"commenttoggle\"><p>Loading...." +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    58
      "</span>";
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    59
  }
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    60
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    61
$("p[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    62
    $(this).append(loading($(this).attr("id")));
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    63
		   });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    64
$("p[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    65
		   var url_string=window.location.pathname;
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    66
		   var temp = new Array();
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    67
		   temp = url_string.split('/');
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    68
		   var chap_name=temp[temp.length-1].split('.')[0];
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    69
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    70
		   $.getJSON("http://127.0.0.1:8000/count/"+chap_name, function(data) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    71
	      $.each(data , function(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    72
		       $("span.commenttoggle").replaceWith("<a class='commenttoggle'" + "href='comments: show / hide'>" + data.count +" "+"comments" + "</a>");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    73
 		   });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    74
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    75
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    76
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    77
	    });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    78
		  });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    79
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    80
		  });