Use typewatch for previewing comments

This commit is contained in:
Pablo Vazquez 2018-03-28 23:35:59 +02:00
parent 5b061af3a5
commit d10bdea6c5
2 changed files with 23 additions and 35 deletions

View File

@ -83,10 +83,8 @@ html(lang="en")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.bootstrap-3.3.7.min.js') }}")
| {% block footer_scripts_pre %}{% endblock %}
| {% block footer_scripts %}{% endblock %}
| {% if current_user.is_authenticated() %}
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.typewatch-3.0.0.min.js') }}")
script.
// When sending an AJAX request, always add the X-CSRFToken header to it.
var csrf_token = "{{ csrf_token() }}";
@ -97,6 +95,10 @@ html(lang="en")
}
}
});
| {% endif %}
| {% block footer_scripts_pre %}{% endblock %}
| {% block footer_scripts %}{% endblock %}
script.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@ -125,16 +125,11 @@ script.
// Writing comment
var $commentField = $("#comment_field");
var $commentContainer = $commentField.parent();
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',
@ -149,7 +144,6 @@ script.
.fail(function (err) {
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
});
}
var options = {
@ -162,32 +156,24 @@ script.
$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){
//- // 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 ($commentField.val()) {
$commentContainer.addClass('filled');
} else {
$commentContainer.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 ($commentField.is(":focus")) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
post_comment($commentContainer.find('.comment-action-submit'));
}
}
});
// Autoresize the textarea as we type
$('#comment_field').autoResize();