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

" + dukebody@906: "Load all comments (slow)

") dukebody@906: .toggle(function() { $(this).nextAll().show("normal"); }, dukebody@906: function() { $(this).nextAll().hide("normal"); }) dukebody@906: .hover(function() { $(this).fadeTo("normal", 0.8); }, dukebody@906: function() { $(this).fadeTo("normal", 0.35); }); dukebody@913: $(".chapter p[@id]").each(function() { dukebody@906: $(this).append(loading($(this).attr("id"))); dukebody@906: }); dukebody@913: $(".chapter table[@id].equation").each(function() { dukebody@908: id = $(this).attr("id"); dukebody@908: $("#" + id + " tr").after('' + loading($(this).attr("id")) + ''); dukebody@906: }); dukebody@913: $(".chapter pre[@id]").each(function() { dukebody@906: $(this).after(loading($(this).attr("id"))); dukebody@906: }); dukebody@906: var chapid = $("div.preface, div.chapter, div.appendix, div.bibliography").attr("id"); dukebody@906: $("#chapterfeed").attr("href", dukebody@906: $("#chapterfeed").attr("href") + chapid + "/"); dukebody@906: $.getJSON(location.protocol + "//" + location.host + "/comments/chapter/" + dukebody@906: chapid + "/count/", function(data) { dukebody@906: $.each(data, function(id, item) { dukebody@906: var s = item == 1 ? "" : "s"; dukebody@906: $("#comments_" + qid(id) + " span.commenttoggle").replaceWith( dukebody@906: "" + item + " comment" + s + ""); dukebody@906: }); dukebody@906: $("span.commenttoggle").each(function() { dukebody@906: var id = $(this).attr("pid"); dukebody@906: $(this).replaceWith("No comments"); dukebody@906: }); dukebody@906: }); dukebody@906: });