bos@574: function qid(id) {
bos@574: return id.replace(/([.:])/g, "\\$1");
bos@574: }
bos@574:
bos@574: function beforeComment(formData, jqForm, options) {
bos@574: var form = jqForm[0];
bos@574: if (!form.comment.value) {
bos@574: $(options.target + " span.comment_error").empty().append(
bos@574: "Your comment is empty");
bos@574: return false;
bos@574: }
bos@574: if (!form.name.value) {
bos@574: $(options.target + " span.comment_error").empty().append(
bos@574: "Please provide a name");
bos@574: return false;
bos@574: }
bos@574: $(options.target + " span.comment_error").empty().after(
bos@574: "");
bos@574: $(options.target + " input[@name=submit]").attr("disabled", true);
bos@574: }
bos@574:
bos@574: function ajaxifyForm(id) {
bos@574: var q = qid(id);
bos@574:
bos@574: $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment,
bos@574: success: function() { ajaxifyForm(id); },
bos@574: target: "#comments_" + q });
bos@574: }
bos@574:
bos@574: function toggleComment(id) {
bos@574: $("#toggle_" + qid(id)).nextAll().toggle();
bos@574: return false;
bos@574: }
bos@574:
bos@574: function loadComments(id) {
bos@574: $("#comments_" + qid(id)).load(location.protocol + "//" + location.host +
bos@574: "/comments/single/" + id + "/", function() {
bos@574: ajaxifyForm(id);
bos@574: });
bos@574: return false;
bos@574: }
bos@574:
bos@574: function loadAllComments() {
bos@574: $("a.commenttoggle").each(function() {
bos@574: var id = $(this).attr("pid");
bos@574: if (id) {
bos@574: loadComments(id);
bos@574: }
bos@574: });
bos@574: }
bos@574:
bos@574: $(document).ready(function() {
bos@574: function loading(id) {
bos@574: return " " +
bos@574: "Loading..." +
bos@574: "";
bos@574: }
bos@574: $("div.toc>p")
bos@574: .after("