dukebody avatar dukebody committed 92f13a5

Stage an unexplicably unstaged javascript file.

Comments (0)

Files changed (1)

web/support/javascript/hsbook.js

+function qid(id) {
+  return id.replace(/([.:])/g, "\\$1");
+}
+
+function beforeComment(formData, jqForm, options) {
+  var form = jqForm[0];
+  if (!form.comment.value) {
+    $(options.target + " span.comment_error").empty().append(
+      "<span class=\"comment_error\">Your comment is empty</span>");
+    return false;
+  }
+  if (!form.name.value) {
+    $(options.target + " span.comment_error").empty().append(
+      "<span class=\"comment_error\">Please provide a name</span>");
+    return false;
+  }
+  $(options.target + " span.comment_error").empty().after(
+    "<img src=\"figs/throbber.gif\" style=\"vertical-align: middle\"/>");
+  $(options.target + " input[@name=submit]").attr("disabled", true);
+}
+
+function ajaxifyForm(id) {
+  var q = qid(id);
+  
+  $("#form_" + q).ajaxForm({ beforeSubmit: beforeComment,
+			     success: function() { ajaxifyForm(id); },
+			     target: "#comments_" + q });
+}
+
+function toggleComment(id) {
+  $("#toggle_" + qid(id)).nextAll().toggle();
+  return false;
+}
+
+function loadComments(id) {
+  $("#comments_" + qid(id)).load(location.protocol + "//" + location.host +
+				 "/comments/single/" + id + "/", function() {
+    ajaxifyForm(id);
+  });
+  return false;
+}
+
+function loadAllComments() {
+  $("a.commenttoggle").each(function() {
+    var id = $(this).attr("pid");
+    if (id) {
+      loadComments(id);
+    }
+  });
+}
+
+$(document).ready(function() {
+  function loading(id) {
+    return " <span id=\"comments_" + id + "\" class=\"comment\">" +
+      "<span pid=\"" + id + "\" class=\"commenttoggle\">Loading..." +
+      "</span></span>";
+  }
+  $("div.toc>p")
+    .after("<p style='display: none;'><a onclick='return loadAllComments()'>" +
+	   "Load all comments (<b>slow</b>)</a></p>")
+    .toggle(function() { $(this).nextAll().show("normal"); },
+	    function() { $(this).nextAll().hide("normal"); })
+    .hover(function() { $(this).fadeTo("normal", 0.8); },
+	   function() { $(this).fadeTo("normal", 0.35); });
+  $("p[@id]").each(function() {
+    $(this).append(loading($(this).attr("id")));
+  });
+  $("table[@id].equation").each(function() {
+    $(this).after(loading_equation($(this).attr("id")));
+  });
+  $("pre[@id]").each(function() {
+    $(this).after(loading($(this).attr("id")));
+  });
+  var chapid = $("div.preface, div.chapter, div.appendix, div.bibliography").attr("id");
+  $("#chapterfeed").attr("href",
+			 $("#chapterfeed").attr("href") + chapid + "/");
+  $.getJSON(location.protocol + "//" + location.host + "/comments/chapter/" +
+	    chapid + "/count/", function(data) {
+    $.each(data, function(id, item) {
+      var s = item == 1 ? "" : "s";
+      $("#comments_" + qid(id) + " span.commenttoggle").replaceWith(
+        "<a class='commenttoggle' id='toggle_" + id + "' " +
+	"pid='" + id + "' " +
+	"onclick='return loadComments(\"" + id + "\")' " +
+	"href='comments: show / hide'>" + item + " comment" + s + "</a>");
+    });
+    $("span.commenttoggle").each(function() {
+      var id = $(this).attr("pid");
+      $(this).replaceWith("<a class='commenttoggle' id='toggle_" + id + "' " +
+			  "onclick='return loadComments(\"" + id + "\")' " +
+			  "href='comment: add'>No comments</a>");
+    });
+  });
+});
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.