Use typewatch for previewing comments

This commit is contained in:
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') }}") script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.bootstrap-3.3.7.min.js') }}")
| {% if current_user.is_authenticated() %}
| {% block footer_scripts_pre %}{% endblock %} script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.typewatch-3.0.0.min.js') }}")
| {% block footer_scripts %}{% endblock %}
script. script.
// When sending an AJAX request, always add the X-CSRFToken header to it. // When sending an AJAX request, always add the X-CSRFToken header to it.
var csrf_token = "{{ csrf_token() }}"; var csrf_token = "{{ csrf_token() }}";
@@ -97,6 +95,10 @@ html(lang="en")
} }
} }
}); });
| {% endif %}
| {% block footer_scripts_pre %}{% endblock %}
| {% block footer_scripts %}{% endblock %}
script. script.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (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 // Writing comment
var $commentField = $("#comment_field"); var $commentField = $("#comment_field");
var $commentContainer = $commentField.parent();
var $commentPreview = $commentField.parent().parent().find('.comment-reply-preview-md'); var $commentPreview = $commentField.parent().parent().find('.comment-reply-preview-md');
console.log('{{csrf_token}}');
function parseCommentContent(content) { function parseCommentContent(content) {
var csrf_token = '{{ csrf_token }}';
console.log(csrf_token);
$.ajax({ $.ajax({
url: "{{ url_for('nodes.preview_markdown')}}", url: "{{ url_for('nodes.preview_markdown')}}",
type: 'post', type: 'post',
@@ -149,7 +144,6 @@ script.
.fail(function (err) { .fail(function (err) {
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed'); toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
}); });
} }
var options = { var options = {
@@ -162,32 +156,24 @@ script.
$commentField.typeWatch(options); $commentField.typeWatch(options);
// Markdown convert as we type in the textarea $(document)
//- $(document) .off('keyup','body .comment-reply-field textarea')
//- .off('keyup','body .comment-reply-field textarea') .on( 'keyup','body .comment-reply-field textarea',function(e){
//- .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, // While we are at it, style if empty
//- // rather than relying on our JS-converted Markdown. if ($commentField.val()) {
//- $preview.html($textarea.val()); $commentContainer.addClass('filled');
} else {
$commentContainer.removeClass('filled');
}
//- // While we are at it, style if empty // Send on ctrl+enter
//- if ($textarea.val()) { if ($commentField.is(":focus")) {
//- $container.addClass('filled'); if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
//- } else { post_comment($commentContainer.find('.comment-action-submit'));
//- $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'));
//- }
//- }
//- });
// Autoresize the textarea as we type // Autoresize the textarea as we type
$('#comment_field').autoResize(); $('#comment_field').autoResize();