Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initializeComment blanks out the comment title and the comment author, sets the comment
- // body to the given text, focuses the comment body, resizes the comment height to show
- // all of the given text, and puts the cursor at the end of the comment body.
- function initializeComment(text) {
- document.getElementById("comment_jebra").value = ""; // Title.
- document.getElementById("comment_comment_writer").value = ""; // Author.
- commentBody = document.getElementById("comment_argle"); // Body.
- window.location.href = "#post-comment"
- commentBody.focus();
- commentBody.value = text;
- autogrow()
- }
- function reply(commentNum) {
- initializeComment("#" + commentNum + " ");
- }
- function quote(commentNum) {
- reply("")
- var body = "";
- // Find the outer element for the comment to be quoted and get its child of class
- // "comment-body". (There should be only one.) The innerText of this is what we want to
- // quote.
- var comment = document.getElementById(commentNum);
- for (var i = 0; i < comment.childNodes.length; i++) {
- if (comment.childNodes[i].className == "comment-body") {
- text = innerTextWithMarkdownLinks(comment.childNodes[i]).replace(/^(?=.)/mg, "> ");
- // Append a final pair of newlines if necessary.
- if (text.slice(-2) != "\n\n") {
- text = text + "\n\n";
- }
- initializeComment(text);
- break;
- }
- }
- }
- // innerTextWithMarkdownLinks returns a version of the innerText of elem
- // in which all links ("a" tags) – except for links of one of the types
- // below – have been replaced with markdown-style links. The types of
- // links which are are left as plain text are:
- // - auto-links to comment numbers (i.e., links whose innerText conists
- // of "#" followed by one or more digits)
- // - raw http/https links (i.e., links whose innerText matches the
- // regexp "^https?://"
- function innerTextWithMarkdownLinks(elem) {
- var orig = elem.innerHTML;
- var links = elem.getElementsByTagName("a");
- for (var i = 0; i < links.length; i++) {
- // Skip #XXXXX links.
- if (links[i].innerText.match(/^#[0-9]+$/)) {
- continue;
- }
- // Skip raw http/https links.
- if (links[i].innerText.match(/^https?:[/][/]/)) {
- continue;
- }
- // Temporarily change link to markdown-style link.
- links[i].innerHTML = "[" + links[i].innerText + "](" + links[i].href + ")"
- }
- text = elem.innerText;
- elem.innerHTML = orig; // Restore the original innerHTML.
- return text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement