WIP on using the new nodes.preview_markdown for comments
This commit is contained in:
@@ -116,11 +116,6 @@ script.
|
||||
|
||||
// If we can actually comment, load the tools to do it
|
||||
|
||||
// Initialize Markdown to later convert comment as we type
|
||||
var convert = new Markdown.getSanitizingConverter();
|
||||
Markdown.Extra.init(convert);
|
||||
convert = convert.makeHtml;
|
||||
|
||||
// Submit new comment
|
||||
$(document)
|
||||
.off('click','body .comment-action-submit')
|
||||
@@ -129,32 +124,70 @@ script.
|
||||
});
|
||||
|
||||
// Writing comment
|
||||
var $commentField = $("#comment_field");
|
||||
var $commentPreview = $commentField.parent().parent().find('.comment-reply-preview-md');
|
||||
|
||||
console.log('{{csrf_token}}');
|
||||
|
||||
function parseCommentContent(content) {
|
||||
|
||||
var csrf_token = '{{ csrf_token }}';
|
||||
|
||||
console.log(csrf_token);
|
||||
|
||||
$.ajax({
|
||||
url: "{{ url_for('nodes.preview_markdown')}}",
|
||||
type: 'post',
|
||||
data: {content: content},
|
||||
headers: {"X-CSRFToken": csrf_token},
|
||||
headers: {},
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(function (data) {
|
||||
$commentPreview.html(data.content);
|
||||
})
|
||||
.fail(function (err) {
|
||||
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var options = {
|
||||
callback: parseCommentContent,
|
||||
wait: 750,
|
||||
highlight: false,
|
||||
allowSubmit: false,
|
||||
captureLength: 2
|
||||
}
|
||||
|
||||
$commentField.typeWatch(options);
|
||||
|
||||
// Markdown convert as we type in the textarea
|
||||
$(document)
|
||||
.off('keyup','body .comment-reply-field textarea')
|
||||
.on( 'keyup','body .comment-reply-field textarea',function(e){
|
||||
var $textarea = $(this);
|
||||
var $container = $(this).parent();
|
||||
var $preview = $container.parent().find('.comment-reply-preview-md');
|
||||
//- $(document)
|
||||
//- .off('keyup','body .comment-reply-field textarea')
|
||||
//- .on( 'keyup','body .comment-reply-field textarea',function(e){
|
||||
//- var $textarea = $(this);
|
||||
//- var $container = $(this).parent();
|
||||
//- var $preview = $container.parent().find('.comment-reply-preview-md');
|
||||
|
||||
// TODO: communicate with back-end to do the conversion,
|
||||
// rather than relying on our JS-converted Markdown.
|
||||
$preview.html(convert($textarea.val()));
|
||||
//- // TODO: communicate with back-end to do the conversion,
|
||||
//- // rather than relying on our JS-converted Markdown.
|
||||
//- $preview.html($textarea.val());
|
||||
|
||||
// While we are at it, style if empty
|
||||
if ($textarea.val()) {
|
||||
$container.addClass('filled');
|
||||
} else {
|
||||
$container.removeClass('filled');
|
||||
}
|
||||
//- // While we are at it, style if empty
|
||||
//- if ($textarea.val()) {
|
||||
//- $container.addClass('filled');
|
||||
//- } else {
|
||||
//- $container.removeClass('filled');
|
||||
//- }
|
||||
|
||||
// Send on ctrl+enter
|
||||
if ($textarea.is(":focus")) {
|
||||
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
|
||||
post_comment($container.find('.comment-action-submit'));
|
||||
}
|
||||
}
|
||||
});
|
||||
//- // Send on ctrl+enter
|
||||
//- if ($textarea.is(":focus")) {
|
||||
//- if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
|
||||
//- post_comment($container.find('.comment-action-submit'));
|
||||
//- }
|
||||
//- }
|
||||
//- });
|
||||
|
||||
// Autoresize the textarea as we type
|
||||
$('#comment_field').autoResize();
|
||||
|
Reference in New Issue
Block a user