# HG changeset patch # User neko259 # Date 2017-12-17 12:33:49 # Node ID 8f0c2e52991f048ffcc34c7196050a7eef353e33 # Parent c2c571fab3992531b2bcc0b55bf3625a3b947ad7 Hide quote button when its click. Cache its selector 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 @@ -27,6 +27,7 @@ var REPLY_TO_MSG = '.reply-to-message'; var REPLY_TO_MSG_ID = '#reply-to-message-id'; var $html = $("html, body"); +var $quoteButton = $("#quote-button"); function moveCaretToEnd(el) { var newPos = el.val().length; @@ -78,8 +79,7 @@ function addQuickReply(postId) { function addQuickQuote() { var textAreaJq = getPostTextarea(); - var quoteButton = $("#quote-button"); - var postId = quoteButton.attr('data-post-id'); + var postId = $quoteButton.attr('data-post-id'); if (postId != null) { addQuickReply(postId); } @@ -87,7 +87,7 @@ function addQuickQuote() { var textToAdd = ''; var selection = window.getSelection().toString(); if (selection.length == 0) { - selection = quoteButton.attr('data-text'); + selection = $quoteButton.attr('data-text'); } if (selection.length > 0) { textToAdd += '[quote]' + selection + '[/quote]\n'; @@ -98,6 +98,8 @@ function addQuickQuote() { textAreaJq.focus(); moveCaretToEnd(textAreaJq); + + $quoteButton.hide(); } function scrollToBottom() { @@ -106,14 +108,13 @@ function scrollToBottom() { function showQuoteButton() { var selection = window.getSelection().getRangeAt(0).getBoundingClientRect(); - var quoteButton = $("#quote-button"); if (selection.width > 0) { // quoteButton.offset({ top: selection.top - selection.height, left: selection.left }); - quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left}); - quoteButton.show(); + $quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left}); + $quoteButton.show(); var text = window.getSelection().toString(); - quoteButton.attr('data-text', text); + $quoteButton.attr('data-text', text); var rect = window.getSelection().getRangeAt(0).getBoundingClientRect(); var element = $(document.elementFromPoint(rect.x, rect.y)); @@ -126,9 +127,9 @@ function showQuoteButton() { postId = postParent.attr('id'); } } - quoteButton.attr('data-post-id', postId); + $quoteButton.attr('data-post-id', postId); } else { - quoteButton.hide(); + $quoteButton.hide(); } }