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