sphinx_django/support/hsbook.js
author amit
Thu, 30 Sep 2010 11:36:30 +0530
changeset 0 54f784230511
permissions -rw-r--r--
Initial commit of django based commenting system for sphinx. Already has most of the boiler plate code.
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
//this part works don't change
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\">Loading..." +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    58
//       "</span></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
//   $("p")
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    61
//     .after("<p style='display: none;'><a onclick='return loadAllComments()'>" +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    62
// 	   "Load all comments (<b>slow</b>)</a></p>")
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    63
//     .toggle(function() { $(this).nextAll().show("normal"); },
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    64
// 	    function() { $(this).nextAll().hide("normal"); })
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    65
//     .hover(function() { $(this).fadeTo("normal", 0.8); },
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    66
// 	   function() { $(this).fadeTo("normal", 0.35); });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    67
//    $(".chapter p[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    68
//      $(this).append(loading($(this).attr("id")));
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
//    // $(".chapter table[@id].equation").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    71
//    //   id = $(this).attr("id");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    72
//    //   $("#" + id + " tr").after('<tr><td colspan="4">' + loading($(this).attr("id")) + '</td></tr>');
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
//    // $(".chapter pre[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    75
//    //   $(this).after(loading($(this).attr("id")));
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
$(document).ready(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    79
  function loading(id) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    80
    return " <span id=\"comments_" + id + "\" class=\"comment\">" +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    81
      "<span pid=\"" + id + "\" class=\"commenttoggle\">bleeding..." +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    82
      "</span></span>";
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    83
  } 
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    84
  $("p")
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    85
    .after("<p style='display: none;'><a onclick='return loadAllComments()'>" +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    86
	   "Load all comments (<b>slow</b>)</a></p>")
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    87
    .toggle(function() { $(this).nextAll().show("normal"); },
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    88
	    function() { $(this).nextAll().hide("normal"); })
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    89
    .hover(function() { $(this).fadeTo("normal", 0.8); },
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    90
	   function() { $(this).fadeTo("normal", 0.35); });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    91
      
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    92
//
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    93
  $("p").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    94
     $(this).append(loading($(this).attr("id")));
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    95
      });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    96
//   // $(".chapter table[@id].equation").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    97
//   //   id = $(this).attr("id");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    98
//   //   $("#" + id + " tr").after('<tr><td colspan="4">' + loading($(this).attr("id")) + '</td></tr>');
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
    99
//   // });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   100
//   // $(".chapter pre[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   101
//   //   $(this).after(loading($(this).attr("id")));
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   102
//   //     });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   103
    
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   104
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   105
//   // var chapid = $("div.preface, div.chapter, div.appendix, div.bibliography").attr("id");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   106
//   // $("#chapterfeed").attr("href",
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   107
//   // 			 $("#chapterfeed").attr("href") + chapid + "/");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   108
//   // $.getJSON(location.protocol + "//" + location.host + "/comments/chapter/" +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   109
//   // 	    chapid + "/count/", function(data) {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   110
$("p").onclick(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   111
//   //   //   var s = item == 1 ? "" : "s";
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   112
      // $(".chapter p[@id]").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   113
       	      $(this).replace(
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   114
       	 "<a class='commenttoggle'"+ "href='comments: show / hide'>" +  " comment"+ "</a>"); 
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   115
//   //   // 	"pid='" + id + "' " +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   116
//   //   // 	"onclick='return loadComments(\"" + id + "\")' " +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   117
    }); }); 
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   118
//   //   });  
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   119
// //     $("span.commenttoggle").each(function() {
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   120
// //       var id = $(this).attr("pid");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   121
// //       $(this).replaceWith("<a class='commenttoggle' id='toggle_" + id + "' " +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   122
// // 			  "onclick='return loadComments(\"" + id + "\")' " +
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   123
// // 			  "href='comment: add'>No comments</a>");
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   124
// //     });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   125
// //   });
54f784230511 Initial commit of django based commenting system for sphinx. Already has
amit
parents:
diff changeset
   126
// // });