Advertisement
petrogradphilosopher

curi.us reply/quote js proposal

Feb 12th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // initializeComment blanks out the comment title and the comment author, sets the comment
  2. // body to the given text, focuses the comment body, resizes the comment height to show
  3. // all of the given text, and puts the cursor at the end of the comment body.
  4. function initializeComment(text) {
  5.   document.getElementById("comment_jebra").value = ""; // Title.
  6.   document.getElementById("comment_comment_writer").value = ""; // Author.
  7.   commentBody = document.getElementById("comment_argle"); // Body.
  8.   window.location.href = "#post-comment"
  9.   commentBody.focus();
  10.   commentBody.value = text;
  11.   autogrow()
  12. }
  13.  
  14. function reply(commentNum) {
  15.   initializeComment("#" + commentNum + " ");
  16. }
  17.  
  18. function quote(commentNum) {
  19.   reply("")
  20.   var body = "";
  21.   // Find the outer element for the comment to be quoted and get its child of class
  22.   // "comment-body".  (There should be only one.) The innerText of this is what we want to
  23.   // quote.
  24.   var comment = document.getElementById(commentNum);
  25.   for (var i = 0; i < comment.childNodes.length; i++) {
  26.     if (comment.childNodes[i].className == "comment-body") {
  27.       text = comment.childNodes[i].innerText.replace(/^(?=.)/mg, "> ");
  28.       // Append a final pair of newlines if necessary.
  29.       if (text.slice(-2) != "\n\n") {
  30.         text = text + "\n\n";
  31.       }
  32.       initializeComment(text);
  33.       break;
  34.     }
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement