comments: move Javascript into component.

This is a minor breaking changing for userscripts that may have tried to
hook into our comment Javascript.
This commit is contained in:
evazion
2021-01-21 20:08:14 -06:00
parent c718667d46
commit 2beac62fc3
3 changed files with 35 additions and 36 deletions

View File

@@ -0,0 +1,34 @@
class CommentComponent {
static initialize() {
if ($("#c-posts #a-show, #c-comments").length) {
$(document).on("click.danbooru.comment", ".edit_comment_link", CommentComponent.showEditForm);
$(document).on("click.danbooru.comment", ".expand-comment-response", CommentComponent.showNewCommentForm);
$(document).on("click.danbooru.comment", ".unhide-comment-link", CommentComponent.unhideComment);
}
}
static showNewCommentForm(e) {
$(e.target).hide();
var $form = $(e.target).closest("div.new-comment").find("form");
$form.show();
$form[0].scrollIntoView(false);
e.preventDefault();
}
static showEditForm(e) {
$(this).closest(".comment").find(".edit_comment").show();
e.preventDefault();
}
static unhideComment(e) {
let $comment = $(this).closest(".comment");
$comment.find(".unhide-comment-link").hide();
$comment.find(".body").show();
e.preventDefault();
}
}
$(document).ready(CommentComponent.initialize);
export default CommentComponent;