diff -r 5574cfc2b28d -r f5e18f8ed036 hsbook_back.js --- a/hsbook_back.js Thu Sep 30 15:59:32 2010 +0530 +++ b/hsbook_back.js Fri Oct 15 15:59:28 2010 +0530 @@ -3,43 +3,52 @@ } function beforeComment(formData, jqForm, options) { - var form = jqForm[0]; - if (!form.comment.value) { - $(options.target + " span.comment_error").empty().append( - "Your comment is empty"); + var form=jqForm[0]; + + if (form.comment.textLength.toString()=='0') { + $("span.comment_error").empty().append( + " Your comment is empty"); return false; } - if (!form.name.value) { - $(options.target + " span.comment_error").empty().append( - "Please provide a name"); + if (form.name.textLength.toString()=='0') { + $("span.comment_error").empty().append( + " Please provide a name"); return false; } $(options.target + " span.comment_error").empty().after( ""); - $(options.target + " input[@name=submit]").attr("disabled", true); + $("input[@name=submit]").attr("disabled", true); } function ajaxifyForm(id) { - var q = qid(id); + +// $('#form_func_1').replaceWith('something'); - $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment, - success: function() { ajaxifyForm(id); }, - target: "#comments_" + q }); -} + var substring=id.substr(9); + $('#form_'+substring).ajaxForm({beforeSubmit: beforeComment, + success: function(){ loadComments(id);} + + });} + function toggleComment(id) { $("#toggle_" + qid(id)).nextAll().toggle(); return false; } -function loadComments(id) { - $("#comments_" + qid(id)).load(location.protocol + "//" + location.host + - "/comments/single/" + id + "/", function() { - ajaxifyForm(id); - }); - return false; + +function loadComments(id) +{ + + var substring=id.substr(9); + $('#comments_'+substring).load("http://127.0.0.1:8000/single/"+ substring +'/',function() { ajaxifyForm(id);} + ); + } + + + function loadAllComments() { $("a.commenttoggle").each(function() { var id = $(this).attr("pid"); @@ -61,20 +70,37 @@ $("p[@id]").each(function() { $(this).append(loading($(this).attr("id"))); }); -$("p[@id]").each(function() { - var url_string=window.location.pathname; - var temp = new Array(); - temp = url_string.split('/'); - var chap_name=temp[temp.length-1].split('.')[0]; + + +var url_string=window.location.pathname; +var temp = new Array(); +temp = url_string.split('/'); +var chap_name=temp[temp.length-1].split('.')[0]; + +jQuery.getJSON("http://127.0.0.1:8000/count/"+chap_name, function(data) { - $.getJSON("http://127.0.0.1:8000/count/"+chap_name, function(data) { - $.each(data , function(id) { - $("span.commenttoggle").replaceWith("" + data.count +" "+"comments" + ""); - }); + $("span.comment").each(function(data_val) { + var id = $(this).attr("id"); + var substring=id.substr(9); + + $(this).replaceWith("" + data.count[substring] +' comments'+ ""); + + }); + + + }); + + }); - }); - }); + + + + - }); + + + + +