Comments: Fix multiple posting when using a hotkey
On every new item loaded with comments, we would bind the click without unbinding first, leading to multiple posting when triggering the comment submission.
This commit is contained in:
parent
dbde681aff
commit
38e960eb3f
@ -76,6 +76,8 @@
|
|||||||
|
|
||||||
| {% block comment_scripts %}
|
| {% block comment_scripts %}
|
||||||
script.
|
script.
|
||||||
|
|
||||||
|
// If there's a comment link in the URL, scroll there
|
||||||
function scrollToLinkedComment() {
|
function scrollToLinkedComment() {
|
||||||
var scrollToId = location.hash;
|
var scrollToId = location.hash;
|
||||||
if (scrollToId.length <= 1) return;
|
if (scrollToId.length <= 1) return;
|
||||||
@ -86,13 +88,16 @@ script.
|
|||||||
}
|
}
|
||||||
$(scrollToLinkedComment);
|
$(scrollToLinkedComment);
|
||||||
|
|
||||||
// Markdown initialization
|
// Initialize Markdown to later convert comment as we type
|
||||||
var convert = new Markdown.getSanitizingConverter();
|
var convert = new Markdown.getSanitizingConverter();
|
||||||
Markdown.Extra.init(convert);
|
Markdown.Extra.init(convert);
|
||||||
convert = convert.makeHtml;
|
convert = convert.makeHtml;
|
||||||
|
|
||||||
/* Submit new comment */
|
|
||||||
$(document).on('click', 'body .comment-action-submit', function(e){
|
// Submit new comment
|
||||||
|
$(document)
|
||||||
|
.off('click','body .comment-action-submit')
|
||||||
|
.on( 'click','body .comment-action-submit', function(e){
|
||||||
post_comment($(this));
|
post_comment($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -106,10 +111,12 @@ script.
|
|||||||
});
|
});
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
/* Edit comment */
|
|
||||||
|
|
||||||
|
// Writing comment
|
||||||
// Markdown convert as we type in the textarea
|
// Markdown convert as we type in the textarea
|
||||||
$(document).on('keyup','body .comment-reply-field textarea',function(e){
|
$(document)
|
||||||
|
.off('keyup','body .comment-reply-field textarea')
|
||||||
|
.on( 'keyup','body .comment-reply-field textarea',function(e){
|
||||||
var $textarea = $(this);
|
var $textarea = $(this);
|
||||||
var $container = $(this).parent();
|
var $container = $(this).parent();
|
||||||
var $preview = $textarea.next().next();
|
var $preview = $textarea.next().next();
|
||||||
@ -134,8 +141,12 @@ script.
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Enter edit mode */
|
// Edit comment
|
||||||
$(document).on('click','body .comment-action-edit span.edit_mode',function(){
|
// Enter edit mode
|
||||||
|
$(document)
|
||||||
|
.off('click','body .comment-action-edit span.edit_mode')
|
||||||
|
.on( 'click','body .comment-action-edit span.edit_mode',function(){
|
||||||
|
|
||||||
comment_mode(this, 'edit');
|
comment_mode(this, 'edit');
|
||||||
|
|
||||||
var parent_div = $(this).closest('.comment-container');
|
var parent_div = $(this).closest('.comment-container');
|
||||||
@ -162,12 +173,17 @@ script.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click','body .comment-action-edit span.edit_cancel',function(e){
|
// Abort, abort
|
||||||
|
$(document)
|
||||||
|
.off('click','body .comment-action-edit span.edit_cancel')
|
||||||
|
.on( 'click','body .comment-action-edit span.edit_cancel',function(e){
|
||||||
commentEditCancel(this, true);
|
commentEditCancel(this, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Save edited comment */
|
// Save edited comment
|
||||||
$(document).on('click','body .comment-action-edit span.edit_save',function(e){
|
$(document)
|
||||||
|
.off('click','body .comment-action-edit span.edit_save')
|
||||||
|
.on( 'click','body .comment-action-edit span.edit_save',function(e){
|
||||||
var $button = $(this);
|
var $button = $(this);
|
||||||
var $container = $button.closest('.comment-container');
|
var $container = $button.closest('.comment-container');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user