hsbook_back.js
changeset 3 de4a2ed2f34b
parent 2 f5e18f8ed036
child 4 e6e33366df0f
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_func_1').replaceWith('something');
       
    26 
       
    27   var substring=id.substr(9);
       
    28   $('#form_'+substring).ajaxForm({beforeSubmit: beforeComment,
       
    29 			      success: function(){ loadComments(id);}
       
    30 
       
    31 			     });}
       
    32 
       
    33 
       
    34 function toggleComment(id) {
       
    35   $("#toggle_" + qid(id)).nextAll().toggle();
       
    36   return false;
       
    37 }
       
    38 
       
    39 
       
    40 function loadComments(id)
       
    41 {
       
    42 
       
    43   var substring=id.substr(9);
       
    44   $('#comments_'+substring).load("http://127.0.0.1:8000/single/"+ substring +'/',function() { ajaxifyForm(id);}
       
    45 				);
       
    46 
       
    47 }
       
    48 
       
    49 
       
    50 
       
    51 
       
    52 function loadAllComments() {
       
    53   $("a.commenttoggle").each(function() {
       
    54     var id = $(this).attr("pid");
       
    55     if (id) {
       
    56       loadComments(id);
       
    57     }
       
    58   });
       
    59 }
       
    60 
       
    61 
       
    62 
       
    63 $(document).ready(function() {
       
    64   function loading(id) {
       
    65     return " <span id=\"comments_" + id + "\" class=\"comment\">" +
       
    66       "<span pid=\"" + id + "\" class=\"commenttoggle\"><p>Loading...." +
       
    67       "</span>";
       
    68   }
       
    69 
       
    70 $("p[@id]").each(function() {
       
    71     $(this).append(loading($(this).attr("id")));
       
    72 		   });
       
    73 
       
    74 
       
    75 var url_string=window.location.pathname;
       
    76 var temp = new Array();
       
    77 temp = url_string.split('/');
       
    78 var chap_name=temp[temp.length-1].split('.')[0];
       
    79 
       
    80 jQuery.getJSON("http://127.0.0.1:8000/count/"+chap_name, function(data) {
       
    81 
       
    82 		 $("span.comment").each(function(data_val) {
       
    83 		 var id = $(this).attr("id");
       
    84 		var substring=id.substr(9);
       
    85 
       
    86 		$(this).replaceWith("<span class='comment'" +  ' id='+ id+ " <a   +  href=javascript:loadComments('"+id+"');>" + data.count[substring] +' comments'+ "</a>");
       
    87 
       
    88 					});
       
    89 
       
    90 
       
    91 	       });
       
    92 
       
    93 		  });
       
    94 
       
    95 
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 
       
   105 
       
   106