hgbook
annotate web/support/javascript/hsbook.js @ 1114:527b86d55d4a
inotify: update installation information
inotify is shipped in Mercurial since 1.0, which greatly simplifies the installation process
inotify is shipped in Mercurial since 1.0, which greatly simplifies the installation process
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Sun Dec 13 16:35:56 2009 +0900 (2009-12-13) |
parents | f9b08e149131 |
children |
rev | line source |
---|---|
dukebody@906 | 1 function qid(id) { |
dukebody@906 | 2 return id.replace(/([.:])/g, "\\$1"); |
dukebody@906 | 3 } |
dukebody@906 | 4 |
dukebody@906 | 5 function beforeComment(formData, jqForm, options) { |
dukebody@906 | 6 var form = jqForm[0]; |
dukebody@906 | 7 if (!form.comment.value) { |
dukebody@906 | 8 $(options.target + " span.comment_error").empty().append( |
dukebody@906 | 9 "<span class=\"comment_error\">Your comment is empty</span>"); |
dukebody@906 | 10 return false; |
dukebody@906 | 11 } |
dukebody@906 | 12 if (!form.name.value) { |
dukebody@906 | 13 $(options.target + " span.comment_error").empty().append( |
dukebody@906 | 14 "<span class=\"comment_error\">Please provide a name</span>"); |
dukebody@906 | 15 return false; |
dukebody@906 | 16 } |
dukebody@906 | 17 $(options.target + " span.comment_error").empty().after( |
dukebody@916 | 18 "<img src=\"/support/icons/throbber.gif\" style=\"vertical-align: middle\"/>"); |
dukebody@906 | 19 $(options.target + " input[@name=submit]").attr("disabled", true); |
dukebody@906 | 20 } |
dukebody@906 | 21 |
dukebody@906 | 22 function ajaxifyForm(id) { |
dukebody@906 | 23 var q = qid(id); |
dukebody@906 | 24 |
dukebody@906 | 25 $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment, |
dukebody@906 | 26 success: function() { ajaxifyForm(id); }, |
dukebody@906 | 27 target: "#comments_" + q }); |
dukebody@906 | 28 } |
dukebody@906 | 29 |
dukebody@906 | 30 function toggleComment(id) { |
dukebody@906 | 31 $("#toggle_" + qid(id)).nextAll().toggle(); |
dukebody@906 | 32 return false; |
dukebody@906 | 33 } |
dukebody@906 | 34 |
dukebody@906 | 35 function loadComments(id) { |
dukebody@906 | 36 $("#comments_" + qid(id)).load(location.protocol + "//" + location.host + |
dukebody@906 | 37 "/comments/single/" + id + "/", function() { |
dukebody@906 | 38 ajaxifyForm(id); |
dukebody@906 | 39 }); |
dukebody@906 | 40 return false; |
dukebody@906 | 41 } |
dukebody@906 | 42 |
dukebody@906 | 43 function loadAllComments() { |
dukebody@906 | 44 $("a.commenttoggle").each(function() { |
dukebody@906 | 45 var id = $(this).attr("pid"); |
dukebody@906 | 46 if (id) { |
dukebody@906 | 47 loadComments(id); |
dukebody@906 | 48 } |
dukebody@906 | 49 }); |
dukebody@906 | 50 } |
dukebody@906 | 51 |
dukebody@906 | 52 $(document).ready(function() { |
dukebody@906 | 53 function loading(id) { |
dukebody@906 | 54 return " <span id=\"comments_" + id + "\" class=\"comment\">" + |
dukebody@906 | 55 "<span pid=\"" + id + "\" class=\"commenttoggle\">Loading..." + |
dukebody@906 | 56 "</span></span>"; |
dukebody@906 | 57 } |
dukebody@906 | 58 $("div.toc>p") |
dukebody@906 | 59 .after("<p style='display: none;'><a onclick='return loadAllComments()'>" + |
dukebody@906 | 60 "Load all comments (<b>slow</b>)</a></p>") |
dukebody@906 | 61 .toggle(function() { $(this).nextAll().show("normal"); }, |
dukebody@906 | 62 function() { $(this).nextAll().hide("normal"); }) |
dukebody@906 | 63 .hover(function() { $(this).fadeTo("normal", 0.8); }, |
dukebody@906 | 64 function() { $(this).fadeTo("normal", 0.35); }); |
dukebody@913 | 65 $(".chapter p[@id]").each(function() { |
dukebody@906 | 66 $(this).append(loading($(this).attr("id"))); |
dukebody@906 | 67 }); |
dukebody@913 | 68 $(".chapter table[@id].equation").each(function() { |
dukebody@908 | 69 id = $(this).attr("id"); |
dukebody@908 | 70 $("#" + id + " tr").after('<tr><td colspan="4">' + loading($(this).attr("id")) + '</td></tr>'); |
dukebody@906 | 71 }); |
dukebody@913 | 72 $(".chapter pre[@id]").each(function() { |
dukebody@906 | 73 $(this).after(loading($(this).attr("id"))); |
dukebody@906 | 74 }); |
dukebody@906 | 75 var chapid = $("div.preface, div.chapter, div.appendix, div.bibliography").attr("id"); |
dukebody@906 | 76 $("#chapterfeed").attr("href", |
dukebody@906 | 77 $("#chapterfeed").attr("href") + chapid + "/"); |
dukebody@906 | 78 $.getJSON(location.protocol + "//" + location.host + "/comments/chapter/" + |
dukebody@906 | 79 chapid + "/count/", function(data) { |
dukebody@906 | 80 $.each(data, function(id, item) { |
dukebody@906 | 81 var s = item == 1 ? "" : "s"; |
dukebody@906 | 82 $("#comments_" + qid(id) + " span.commenttoggle").replaceWith( |
dukebody@906 | 83 "<a class='commenttoggle' id='toggle_" + id + "' " + |
dukebody@906 | 84 "pid='" + id + "' " + |
dukebody@906 | 85 "onclick='return loadComments(\"" + id + "\")' " + |
dukebody@906 | 86 "href='comments: show / hide'>" + item + " comment" + s + "</a>"); |
dukebody@906 | 87 }); |
dukebody@906 | 88 $("span.commenttoggle").each(function() { |
dukebody@906 | 89 var id = $(this).attr("pid"); |
dukebody@906 | 90 $(this).replaceWith("<a class='commenttoggle' id='toggle_" + id + "' " + |
dukebody@906 | 91 "onclick='return loadComments(\"" + id + "\")' " + |
dukebody@906 | 92 "href='comment: add'>No comments</a>"); |
dukebody@906 | 93 }); |
dukebody@906 | 94 }); |
dukebody@906 | 95 }); |