diff --git a/src/scripts/tutti/2_comments.js b/src/scripts/tutti/2_comments.js
index 067d9cd1..f5c24550 100644
--- a/src/scripts/tutti/2_comments.js
+++ b/src/scripts/tutti/2_comments.js
@@ -303,3 +303,33 @@ function save_comment(is_new_comment, $commentContainer)
return promise;
}
+
+/* Used when clicking the .comment-action-submit button or by a shortcut */
+function post_comment($submit_button){
+
+ save_comment(true)
+ .progress(function() {
+ $submit_button
+ .addClass('submitting')
+ .html(' Posting...');
+ })
+ .fail(function(xhr){
+ if (typeof xhr === 'string') {
+ show_comment_button_error(xhr);
+ } else {
+ // If it's not a string, we assume it's a jQuery XHR object.
+ if (console) console.log('Error saving comment:', xhr.responseText);
+ show_comment_button_error("Houston! Try again?");
+ }
+ toastr.error(xhr.responseText, 'Error saving comment');
+ })
+ .done(function(comment_node_id) {
+ $submit_button
+ .removeClass('submitting')
+ .html('Post Comment');
+ $('#comment_field').val('');
+ $('body').trigger('pillar:comment-posted', [comment_node_id]);
+
+ toastr.success('Comment posted!');
+ });
+}
diff --git a/src/templates/nodes/custom/comment/list_embed.pug b/src/templates/nodes/custom/comment/list_embed.pug
index b9a59f64..29f1b466 100644
--- a/src/templates/nodes/custom/comment/list_embed.pug
+++ b/src/templates/nodes/custom/comment/list_embed.pug
@@ -92,32 +92,8 @@ script.
convert = convert.makeHtml;
/* Submit new comment */
- $('.comment-action-submit').click(function(e){
- var $button = $(this);
-
- save_comment(true)
- .progress(function() {
- $button
- .addClass('submitting')
- .html(' Posting...');
- })
- .fail(function(xhr){
- if (typeof xhr === 'string') {
- show_comment_button_error(xhr);
- } else {
- // If it's not a string, we assume it's a jQuery XHR object.
- if (console) console.log('Error saving comment:', xhr.responseText);
- show_comment_button_error("Houston! Try again?");
- }
- toastr.error(xhr.responseText, 'Error saving comment');
- })
- .done(function(comment_node_id) {
- $button
- .removeClass('submitting')
- .html('Post Comment');
- $('#comment_field').val('');
- $('body').trigger('pillar:comment-posted', [comment_node_id]);
- });
+ $(document).on('click', 'body .comment-action-submit', function(e){
+ post_comment($(this));
});
{% if show_comments %}
@@ -152,7 +128,7 @@ script.
// Send on ctrl+enter
if ($textarea.is(":focus")) {
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
- $( ".comment-action-submit" ).trigger( "click" );
+ post_comment($container.find('.comment-action-submit'));
}
}
});