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("<div id=comment_preview><h3>{% trans -%}Comment Preview{%- endtrans %}</h3><br />" + decodeURIComponent(data) +
- "<hr style='border: 1px solid #333;' /></div>");
- });
- }
+ if ($('#comment_content').val() && (content != $('#comment_content').val())) {
+ content = $('#comment_content').val();
+ $.post($('#previewURL').val(),$('#form_comment').serialize(),
+ function(data){
+ preview = JSON.parse(data)
+ $('#comment_preview').replaceWith("<div id=comment_preview><h3>" + $('#previewText').val() +"</h3><br />" + preview.content +
+ "<hr style='border: 1px solid #333;' /></div>");
+ });
+ }
}
$(document).ready(function(){
$('#form_comment').hide();
$('#button_addcomment').click(function(){
$(this).fadeOut('fast');
$('#form_comment').slideDown(function(){
- setInterval("previewComment()",500);
+ setInterval("previewComment()",500);
$('#comment_content').focus();
});
});
import logging
import datetime
import json
-import urllib
from mediagoblin import messages, mg_globals
from mediagoblin.db.models import (MediaEntry, MediaTag, Collection,
def media_preview_comment(request):
+ """Runs a comment through markdown so it can be previewed."""
+ comment = unicode(request.form['comment_content'])
+ cleancomment = { "content":cleaned_markdown_conversion(comment)}
- comment = unicode(urllib.unquote(request.query_string).decode('string_escape'))
- if comment.startswith('"') and comment.endswith('"'):
- comment = comment[1:-1]
- print comment
- #decoderRing = json.JSONDecoder()
- #comment = decoderRing.decode(request.query_string)
-
- return Response(json.dumps(cleaned_markdown_conversion(comment)))
+ return Response(json.dumps(cleancomment))
@get_media_entry_by_id
@require_active_login