|
1 function qid(id) { |
|
2 return id.replace(/([.:])/g, "\\$1"); |
|
3 } |
|
4 |
|
5 function beforeComment(formData, jqForm, options) { |
|
6 var form = jqForm[0]; |
|
7 if (!form.comment.value) { |
|
8 $(options.target + " span.comment_error").empty().append( |
|
9 "<span class=\"comment_error\">Your comment is empty</span>"); |
|
10 return false; |
|
11 } |
|
12 if (!form.name.value) { |
|
13 $(options.target + " span.comment_error").empty().append( |
|
14 "<span class=\"comment_error\">Please provide a name</span>"); |
|
15 return false; |
|
16 } |
|
17 $(options.target + " span.comment_error").empty().after( |
|
18 "<img src=\"/support/icons/throbber.gif\" style=\"vertical-align: middle\"/>"); |
|
19 $(options.target + " input[@name=submit]").attr("disabled", true); |
|
20 } |
|
21 |
|
22 function ajaxifyForm(id) { |
|
23 var q = qid(id); |
|
24 |
|
25 $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment, |
|
26 success: function() { ajaxifyForm(id); }, |
|
27 target: "#comments_" + q }); |
|
28 } |
|
29 |
|
30 function toggleComment(id) { |
|
31 $("#toggle_" + qid(id)).nextAll().toggle(); |
|
32 return false; |
|
33 } |
|
34 |
|
35 function loadComments(id) { |
|
36 $("#comments_" + qid(id)).load(location.protocol + "//" + location.host + |
|
37 "/comments/single/" + id + "/", function() { |
|
38 ajaxifyForm(id); |
|
39 }); |
|
40 return false; |
|
41 } |
|
42 |
|
43 function loadAllComments() { |
|
44 $("a.commenttoggle").each(function() { |
|
45 var id = $(this).attr("pid"); |
|
46 if (id) { |
|
47 loadComments(id); |
|
48 } |
|
49 }); |
|
50 } |
|
51 |
|
52 |
|
53 //this part works don't change |
|
54 // $(document).ready(function() { |
|
55 // function loading(id) { |
|
56 // return " <span id=\"comments_" + id + "\" class=\"comment\">" + |
|
57 // "<span pid=\"" + id + "\" class=\"commenttoggle\">Loading..." + |
|
58 // "</span></span>"; |
|
59 // } |
|
60 // $("p") |
|
61 // .after("<p style='display: none;'><a onclick='return loadAllComments()'>" + |
|
62 // "Load all comments (<b>slow</b>)</a></p>") |
|
63 // .toggle(function() { $(this).nextAll().show("normal"); }, |
|
64 // function() { $(this).nextAll().hide("normal"); }) |
|
65 // .hover(function() { $(this).fadeTo("normal", 0.8); }, |
|
66 // function() { $(this).fadeTo("normal", 0.35); }); |
|
67 // $(".chapter p[@id]").each(function() { |
|
68 // $(this).append(loading($(this).attr("id"))); |
|
69 // }); }); |
|
70 // // $(".chapter table[@id].equation").each(function() { |
|
71 // // id = $(this).attr("id"); |
|
72 // // $("#" + id + " tr").after('<tr><td colspan="4">' + loading($(this).attr("id")) + '</td></tr>'); |
|
73 // // }); |
|
74 // // $(".chapter pre[@id]").each(function() { |
|
75 // // $(this).after(loading($(this).attr("id"))); |
|
76 // // }) |
|
77 |
|
78 $(document).ready(function() { |
|
79 function loading(id) { |
|
80 return " <span id=\"comments_" + id + "\" class=\"comment\">" + |
|
81 "<span pid=\"" + id + "\" class=\"commenttoggle\">bleeding..." + |
|
82 "</span></span>"; |
|
83 } |
|
84 $("p") |
|
85 .after("<p style='display: none;'><a onclick='return loadAllComments()'>" + |
|
86 "Load all comments (<b>slow</b>)</a></p>") |
|
87 .toggle(function() { $(this).nextAll().show("normal"); }, |
|
88 function() { $(this).nextAll().hide("normal"); }) |
|
89 .hover(function() { $(this).fadeTo("normal", 0.8); }, |
|
90 function() { $(this).fadeTo("normal", 0.35); }); |
|
91 |
|
92 // |
|
93 $("p").each(function() { |
|
94 $(this).append(loading($(this).attr("id"))); |
|
95 }); |
|
96 // // $(".chapter table[@id].equation").each(function() { |
|
97 // // id = $(this).attr("id"); |
|
98 // // $("#" + id + " tr").after('<tr><td colspan="4">' + loading($(this).attr("id")) + '</td></tr>'); |
|
99 // // }); |
|
100 // // $(".chapter pre[@id]").each(function() { |
|
101 // // $(this).after(loading($(this).attr("id"))); |
|
102 // // }); |
|
103 |
|
104 |
|
105 // // var chapid = $("div.preface, div.chapter, div.appendix, div.bibliography").attr("id"); |
|
106 // // $("#chapterfeed").attr("href", |
|
107 // // $("#chapterfeed").attr("href") + chapid + "/"); |
|
108 // // $.getJSON(location.protocol + "//" + location.host + "/comments/chapter/" + |
|
109 // // chapid + "/count/", function(data) { |
|
110 $("p").onclick(function() { |
|
111 // // // var s = item == 1 ? "" : "s"; |
|
112 // $(".chapter p[@id]").each(function() { |
|
113 $(this).replace( |
|
114 "<a class='commenttoggle'"+ "href='comments: show / hide'>" + " comment"+ "</a>"); |
|
115 // // // "pid='" + id + "' " + |
|
116 // // // "onclick='return loadComments(\"" + id + "\")' " + |
|
117 }); }); |
|
118 // // }); |
|
119 // // $("span.commenttoggle").each(function() { |
|
120 // // var id = $(this).attr("pid"); |
|
121 // // $(this).replaceWith("<a class='commenttoggle' id='toggle_" + id + "' " + |
|
122 // // "onclick='return loadComments(\"" + id + "\")' " + |
|
123 // // "href='comment: add'>No comments</a>"); |
|
124 // // }); |
|
125 // // }); |
|
126 // // }); |