diff options
Diffstat (limited to 'js/comments.js')
-rw-r--r-- | js/comments.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/js/comments.js b/js/comments.js index 43e6fe96e..30baf53f4 100644 --- a/js/comments.js +++ b/js/comments.js @@ -6,6 +6,69 @@ * defined by the Mozilla Public License, v. 2.0. */ +/* Adds the reply text to the 'comment' textarea */ +function replyToComment(id, real_id, replyto_header, text) { + var replytext = ""; + if (replyCommentConfig.quote_replies == 'quoted_reply') { + /* pre id="comment_name_N" */ + if (text == null) { + var text_elem = document.getElementById('comment_text_'+id); + text = getText(text_elem); + } + replytext = replyto_header + "\n" + wrapReplyText(text); + } else if (replyCommentConfig.quote_replies == 'simple_reply') { + replytext = replyto_header + "\n"; + } + + if (replyCommentConfig.is_insider) { + if (document.getElementById('isprivate_' + real_id).checked) { + document.getElementById('newcommentprivacy').checked = 'checked'; + updateCommentTagControl(document.getElementById('newcommentprivacy'), 'comment'); + } + } + + /* <textarea id="comment"> */ + var textarea = document.getElementById('comment'); + if (textarea.value != replytext) { + textarea.value += replytext; + } + + textarea.focus(); +} + +function replyToMarkdownComment(id, real_id, replyto_header) { + var textarea = document.getElementById('comment'); + var comment = textarea.value; + textarea.value += replyCommentConfig.markdown_fetching_comment; + YAHOO.util.Connect.setDefaultPostHeader('application/json', true); + YAHOO.util.Connect.asyncRequest('POST', 'jsonrpc.cgi', + { + success: function(res) { + var data = YAHOO.lang.JSON.parse(res.responseText); + if (!data.error) { + textarea.value = comment; + var text = data.result.comments[real_id].text; + replyToComment(id, real_id, replyto_header, text); + } else { + replyToComment(id, real_id, replyto_header); + } + }, + failure: function(res) { + /* On failure, quote the comment as plain-text */ + replyToComment(id, real_id, replyto_header); + } + }, + YAHOO.lang.JSON.stringify({ + version: "1.1", + method: "Bug.comments", + params: { + Bugzilla_api_token: BUGZILLA.api_token, + comment_ids: [real_id], + } + }) + ); +} + function updateCommentPrivacy(checkbox, id) { var comment_elem = document.getElementById('comment_text_'+id).parentNode; if (checkbox.checked) { |