From d10bdea6c5e48ce9242327a7b288805ad3cc7978 Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Wed, 28 Mar 2018 23:35:59 +0200 Subject: [PATCH] Use typewatch for previewing comments --- src/templates/layout.pug | 10 ++-- .../nodes/custom/comment/list_embed_base.pug | 48 +++++++------------ 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/templates/layout.pug b/src/templates/layout.pug index b1f5f6f9..6c91ef9c 100644 --- a/src/templates/layout.pug +++ b/src/templates/layout.pug @@ -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(){ diff --git a/src/templates/nodes/custom/comment/list_embed_base.pug b/src/templates/nodes/custom/comment/list_embed_base.pug index ce96fb45..1e42e7c8 100644 --- a/src/templates/nodes/custom/comment/list_embed_base.pug +++ b/src/templates/nodes/custom/comment/list_embed_base.pug @@ -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();