fix: 点回复显示「回复 @某人」,可取消回复
This commit is contained in:
+21
-1
@@ -27,7 +27,7 @@ if (post_password_required()) return;
|
||||
</div>
|
||||
<div class="comment-item__text"><?php echo esc_html($c->comment_content); ?></div>
|
||||
<div class="comment-item__reply">
|
||||
<span class="reply-link" data-comment-id="<?php echo $c->comment_ID; ?>" tabindex="0">回复</span>
|
||||
<span class="reply-link" data-comment-id="<?php echo $c->comment_ID; ?>" data-comment-author="<?php echo esc_attr($c->comment_author); ?>" tabindex="0">回复</span>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
@@ -36,6 +36,10 @@ if (post_password_required()) return;
|
||||
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<div id="respond" class="comment-respond">
|
||||
<div id="reply-hint" class="reply-hint" style="display:none">
|
||||
<span id="reply-hint-text"></span>
|
||||
<a href="javascript:void(0)" class="cancel-reply-link" onclick="cancelReply()">取消回复</a>
|
||||
</div>
|
||||
<form id="commentform" class="comment-form" method="post" action="<?php echo site_url('/wp-comments-post.php'); ?>">
|
||||
<textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>
|
||||
<input type="hidden" name="comment_post_ID" value="<?php echo get_the_ID(); ?>">
|
||||
@@ -48,6 +52,10 @@ if (post_password_required()) return;
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div id="respond" class="comment-respond">
|
||||
<div id="reply-hint-guest" class="reply-hint" style="display:none">
|
||||
<span id="reply-hint-text-guest"></span>
|
||||
<a href="javascript:void(0)" class="cancel-reply-link" onclick="cancelReply()">取消回复</a>
|
||||
</div>
|
||||
<form id="commentform-guest" class="comment-form" novalidate>
|
||||
<textarea id="comment" name="comment" rows="3" placeholder="登录后写点什么..." required></textarea>
|
||||
<input type="hidden" id="comment_parent" name="comment_parent" value="0">
|
||||
@@ -83,12 +91,24 @@ if (post_password_required()) return;
|
||||
document.querySelectorAll('.reply-link').forEach(function(el) {
|
||||
el.addEventListener('click', function() {
|
||||
var cid = this.getAttribute('data-comment-id');
|
||||
var author = this.getAttribute('data-comment-author');
|
||||
document.getElementById('comment_parent').value = cid;
|
||||
var hint = document.getElementById('reply-hint');
|
||||
var hintText = document.getElementById('reply-hint-text');
|
||||
if (hint && hintText) {
|
||||
hintText.textContent = '回复 @' + author;
|
||||
hint.style.display = 'flex';
|
||||
}
|
||||
var textarea = document.getElementById('comment');
|
||||
if (textarea) textarea.focus();
|
||||
});
|
||||
el.style.cursor = 'pointer';
|
||||
});
|
||||
function cancelReply() {
|
||||
document.getElementById('comment_parent').value = '0';
|
||||
var hint = document.getElementById('reply-hint');
|
||||
if (hint) hint.style.display = 'none';
|
||||
}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user