comments.js: use event delegation to bind click handlers.
Use event delegation to bind click handlers so that they don't have to be rebound when comments are dynamically loaded with "Show all comments".
This commit is contained in:
@@ -5,13 +5,10 @@ let Comment = {};
|
|||||||
|
|
||||||
Comment.initialize_all = function() {
|
Comment.initialize_all = function() {
|
||||||
if ($("#c-posts").length || $("#c-comments").length) {
|
if ($("#c-posts").length || $("#c-comments").length) {
|
||||||
this.initialize_response_link();
|
$(document).on("click", ".reply-link", Comment.quote);
|
||||||
this.initialize_reply_links();
|
$(document).on("click", ".edit_comment_link", Comment.show_edit_form);
|
||||||
|
$(document).on("click", ".expand-comment-response", Comment.show_new_comment_form);
|
||||||
this.initialize_expand_links();
|
this.initialize_expand_links();
|
||||||
|
|
||||||
if (!$("#a-edit").length) {
|
|
||||||
this.initialize_edit_links();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($("#c-posts").length && $("#a-show").length) {
|
if ($("#c-posts").length && $("#a-show").length) {
|
||||||
@@ -24,8 +21,6 @@ Comment.initialize_all = function() {
|
|||||||
} else {
|
} else {
|
||||||
Comment.highlight_threshold_comments(post_id);
|
Comment.highlight_threshold_comments(post_id);
|
||||||
}
|
}
|
||||||
Comment.initialize_reply_links(current_comment_section);
|
|
||||||
Comment.initialize_edit_links(current_comment_section);
|
|
||||||
Dtext.initialize_expandables(current_comment_section);
|
Dtext.initialize_expandables(current_comment_section);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -49,11 +44,6 @@ Comment.quote = function(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment.initialize_reply_links = function($parent) {
|
|
||||||
$parent = $parent || $(document);
|
|
||||||
$parent.find(".reply-link").click(Comment.quote);
|
|
||||||
}
|
|
||||||
|
|
||||||
Comment.initialize_expand_links = function() {
|
Comment.initialize_expand_links = function() {
|
||||||
$(".comment-section form").hide();
|
$(".comment-section form").hide();
|
||||||
$(".comment-section input.expand-comment-response").click(function(e) {
|
$(".comment-section input.expand-comment-response").click(function(e) {
|
||||||
@@ -64,24 +54,17 @@ Comment.initialize_expand_links = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment.initialize_response_link = function() {
|
Comment.show_new_comment_form = function(e) {
|
||||||
$("a.expand-comment-response").click(function(e) {
|
$(e.target).hide();
|
||||||
$(e.target).hide();
|
var $form = $(e.target).closest("div.new-comment").find("form");
|
||||||
var $form = $(e.target).closest("div.new-comment").find("form");
|
$form.show();
|
||||||
$form.show();
|
Utility.scroll_to($form);
|
||||||
Utility.scroll_to($form);
|
e.preventDefault();
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment.initialize_edit_links = function($parent) {
|
Comment.show_edit_form = function(e) {
|
||||||
$parent = $parent || $(document);
|
$(this).closest(".comment").find(".edit_comment").show();
|
||||||
$parent.find(".edit_comment_link").click(function(e) {
|
e.preventDefault();
|
||||||
var link_id = $(this).attr("id");
|
|
||||||
var comment_id = link_id.match(/^edit_comment_link_(\d+)$/)[1];
|
|
||||||
$("#edit_comment_" + comment_id).fadeToggle("fast");
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment.highlight_threshold_comments = function(post_id) {
|
Comment.highlight_threshold_comments = function(post_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user