From 5ab60299619557307cf38aa14824c8576f23f21c Mon Sep 17 00:00:00 2001 From: Emily O'Leary Date: Sun, 24 Mar 2013 21:42:42 -0400 Subject: [PATCH] Added comment preview functionality to user pages. It works by passing the comment's value as a JSON string to a new handler that lives at /ajax/comment/preview. The query string is decoded, unquoted, and has its leading and trailing quotes removed to match the input that cleaned_markdown_conversion expects. It does this in real time with a 500ms lag by using a timer. Initially I tried the onChange handler but you need to lose focus for that to process. The javascript timer is only invoked if the add comment button is pressed. A request is only sent if the comment box is not empty and the current value is not the same as the last value. --- mediagoblin/static/js/comment_show.js | 12 ++++++++++++ .../mediagoblin/user_pages/media.html | 2 ++ mediagoblin/user_pages/forms.py | 2 +- mediagoblin/user_pages/routing.py | 4 ++++ mediagoblin/user_pages/views.py | 18 +++++++++++++++++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mediagoblin/static/js/comment_show.js b/mediagoblin/static/js/comment_show.js index c5ccee66..cb69fccd 100644 --- a/mediagoblin/static/js/comment_show.js +++ b/mediagoblin/static/js/comment_show.js @@ -15,12 +15,24 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +var content=""; +function previewComment(){ + if ($('#comment_content').val() && (content != $('#comment_content').val())) { + content = $('#comment_content').val(); + $.getJSON($('#previewURL').val(),JSON.stringify($('#comment_content').val()), + function(data){ + $('#comment_preview').replaceWith("

Comment Preview


" + decodeURIComponent(data) + + "
"); + }); + } +} $(document).ready(function(){ $('#form_comment').hide(); $('#button_addcomment').click(function(){ $(this).fadeOut('fast'); $('#form_comment').slideDown(function(){ + setInterval("previewComment()",500); $('#comment_content').focus(); }); }); diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index c16e4c78..39a5eec5 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -107,7 +107,9 @@ {{ csrf_token }} + +
{% endif %}