# HG changeset patch # User neko259 # Date 2015-04-09 15:43:47 # Node ID 86aa132a2349c0c433e206602119f88dbb3286ab # Parent ad1beed448de4b5d9ca3d3d2e48931ae365c4289 JS formatting panel refactoring diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js --- a/boards/static/js/thread.js +++ b/boards/static/js/thread.js @@ -46,15 +46,20 @@ function resetFormPosition() { } function addQuickReply(postId) { + var postLinkRaw = '[post]' + postId + '[/post]' + var textToAdd = ''; var blockToInsert = null; + var textAreaJq = $('textarea'); + if (postId != null) { var post = $('#' + postId); - // If this is not OP, add reflink to the post - if (!post.is(':first-child')) { - textToAdd += '[post]' + postId + '[/post]\n'; + // If this is not OP, add reflink to the post. If there already is + // the same reflink, don't add it again. + if (!post.is(':first-child') && !textAreaJq.val().contains(postLinkRaw)) { + textToAdd += postLinkRaw + '\n'; } blockToInsert = post; @@ -67,15 +72,14 @@ function addQuickReply(postId) { textToAdd += '[quote]' + selection + '[/quote]\n'; } - var textAreaId = 'textarea'; - $(textAreaId).val($(textAreaId).val()+ textToAdd); + textAreaJq.val(textAreaJq.val()+ textToAdd); var form = getForm(); form.insertAfter(blockToInsert); form.show(); + textAreaJq.focus(); var textarea = document.getElementsByTagName('textarea')[0]; - $(textAreaId).focus(); moveCaretToEnd(textarea); }