sphinx_django/static/simplecomment.js~
changeset 3 de4a2ed2f34b
equal deleted inserted replaced
2:f5e18f8ed036 3:de4a2ed2f34b
       
     1 function qid(id) {
       
     2   return id.replace(/([.:])/g, "\\$1");
       
     3 }
       
     4 
       
     5 function beforeComment(formData, jqForm, options) {
       
     6   var form=jqForm[0];
       
     7 
       
     8   if (form.comment.textLength.toString()=='0') {
       
     9     $("span.comment_error").empty().append(
       
    10       "<span class=\"comment_error\">  Your comment is empty</span>");
       
    11     return false;
       
    12   }
       
    13   if (form.name.textLength.toString()=='0') {
       
    14     $("span.comment_error").empty().append(
       
    15       "<span class=\"comment_error\">   Please provide a name</span>");
       
    16     return false;
       
    17   }
       
    18   $(options.target + " span.comment_error").empty().after(
       
    19     "<img src=\"/support/icons/throbber.gif\" style=\"vertical-align: middle\"/>");
       
    20   $("input[@name=submit]").attr("disabled", true);
       
    21 }
       
    22 
       
    23 function ajaxifyForm(id) {
       
    24 
       
    25 // $(' #form_basic_python_func_2').replaceWith('something');
       
    26   alert("ajaxified");
       
    27    var substring=id.substr(9);
       
    28 
       
    29    $('#form_'+substring).ajaxForm({beforeSubmit: beforeComment,
       
    30   			      success: function(){ loadComments(id);}
       
    31 
       
    32   			     });}
       
    33 
       
    34 
       
    35 function toggleComment(id) {
       
    36   $("#toggle_" + qid(id)).nextAll().toggle();
       
    37   return false;
       
    38 }
       
    39 
       
    40 
       
    41 function loadComments(id)
       
    42 {
       
    43 
       
    44   var substring=id.substr(9);
       
    45 
       
    46   $('#comments_'+substring).load(location.protocol+"//" + location.host+":8000/single/"+ substring +'/',function() { ajaxifyForm(id);}
       
    47 				);
       
    48 
       
    49 }
       
    50 
       
    51 
       
    52 
       
    53 
       
    54 function loadAllComments() {
       
    55   $("a.commenttoggle").each(function() {
       
    56     var id = $(this).attr("pid");
       
    57     if (id) {
       
    58       loadComments(id);
       
    59     }
       
    60   });
       
    61 }
       
    62 
       
    63 
       
    64 
       
    65 $(document).ready(function() {
       
    66   function loading(id) {
       
    67     return " <span id=\"comments_" + id + "\" class=\"comment\">" +
       
    68     "<span pid=\"" + id + "\" class=\"commenttoggle\"><p>Loading...." +
       
    69       "</span>";
       
    70   }
       
    71 
       
    72 $("p[@id]").each(function() {
       
    73     $(this).append(loading($(this).attr("id")));
       
    74 
       
    75 	});
       
    76 
       
    77 
       
    78  var url_string=window.location.pathname;
       
    79  var temp = new Array();
       
    80  temp = url_string.split('/pages/');
       
    81  var chap_name=temp[1].split('.')[0];
       
    82 
       
    83  jQuery.getJSON(location.protocol+"//" + location.host+":8000/count/"+chap_name, function(data) {
       
    84 
       
    85  		 $("span.comment").each(function(data_val) {
       
    86  		 var id = $(this).attr("id");
       
    87  		var substring=id.substr(9);
       
    88 
       
    89  					  if (data.count[substring]){
       
    90 
       
    91 
       
    92 		$(this).replaceWith("<span class='comment'" +  ' id='+ id+ " <a   +  href=javascript:loadComments('"+id+"');>" + data.count[substring] +' comments'+ "</a>");
       
    93 					    }
       
    94 
       
    95 					else {$(this).replaceWith("<span class='comment'" +  ' id='+ id+ " <a   +  href=javascript:loadComments('"+id+"');>" + 'No comments'+ "</a>");
       
    96 }
       
    97 
       
    98 
       
    99 					});
       
   100 
       
   101 
       
   102  	       });
       
   103 
       
   104  		  });
       
   105 
       
   106 
       
   107 
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 
       
   115 
       
   116 
       
   117