feat(comments): full 1:1 zibll comment kernel for posts, forum, shop

Extract shared comment helpers (content/item/form/geo/actions), port GIF
[g=] smilies + FixedInput/moveForm UX, wire close_comments/city/quick
settings, REST comment get, and align product review chrome with zibll.
This commit is contained in:
kate522 committed 2026-07-18 15:51:47 +08:00
1 parent 9edd39c33d
commit 276a2891ba
116 files changed
+2658 -1848

No files matched your search

+9 -75
View File
@@ -1,23 +1,15 @@
/**
* AKSRT Comment Actions client
*
* Single client for per-comment actions via REST aksrt/v1:
* like / edit / delete / moderate (approve|hold|spam) / pin
* REST aksrt/v1: like / delete / moderate / pin.
* Edit uses moveForm (#respond) via comment-move-form.js — not inline textarea.
* Submit owned by assets/js/core/comments.js (single submit contract).
*
* Comment SUBMISSION is owned by main.js initCommentSystem() (the native
* wp-comments-post.php flow, which runs captcha verification, rate limiting and
* the moderation pipeline, then re-renders the list through the canonical
* server callback). This file deliberately does NOT bind the submit form, so
* there is exactly one comment-submit contract.
*
* Markup contract (rendered by aksrt_comment_callback, identical on first
* paint, load-more and post-submit reload):
* Markup (aksrt_comment_callback):
* li.aksrt-comment[data-comment-id]
* .aksrt-comment__text (content)
* .aksrt-comment__actions
* [data-comment-action="like|edit|delete|approve|hold|spam|pin"]
*
* Depends on: aksrtData.restNonce (wp_rest) + aksrtData.siteUrl.
* .comment-header .aksrt-comment__like[data-comment-action=like]
* .comment-content#comment-content-{id}
* .comt-meta [data-comment-action=pin|approve|hold|spam|delete]
*
* @package AKSRT
*/
@@ -66,11 +58,10 @@
var commentId = getCommentId(commentEl);
if (!commentId) return;
// edit is handled by comment-move-form.js (moveForm into #respond).
switch (action) {
case 'like': handleLike(actionBtn, commentId); break;
case 'edit': handleEdit(commentEl); break;
case 'save-edit': saveEdit(commentEl, commentId, actionBtn); break;
case 'cancel-edit': cancelEdit(commentEl); break;
case 'edit': break;
case 'delete': handleDelete(commentEl, commentId); break;
case 'pin': handlePin(commentEl, actionBtn, commentId); break;
case 'approve':
@@ -104,63 +95,6 @@
.finally(function () { btn.dataset.busy = ''; });
}
function handleEdit(commentEl) {
var contentEl = commentEl.querySelector(CONTENT_SELECTOR);
if (!contentEl || commentEl.querySelector('.aksrt-comment-edit-form')) return;
var temp = document.createElement('div');
temp.innerHTML = contentEl.innerHTML;
var originalText = (temp.textContent || temp.innerText || '').trim();
var editForm = document.createElement('div');
editForm.className = 'aksrt-comment-edit-form';
editForm.innerHTML =
'<textarea class="aksrt-comment-edit-textarea"></textarea>' +
'<div class="aksrt-comment-actions">' +
'<button type="button" data-comment-action="save-edit" class="aksrt-comment-action-btn aksrt-comment-action-btn--success">保存</button>' +
'<button type="button" data-comment-action="cancel-edit" class="aksrt-comment-action-btn">取消</button>' +
'</div>';
editForm.querySelector('textarea').value = originalText;
contentEl.style.display = 'none';
contentEl.parentNode.insertBefore(editForm, contentEl.nextSibling);
editForm.querySelector('textarea').focus();
}
function cancelEdit(commentEl) {
var editForm = commentEl.querySelector('.aksrt-comment-edit-form');
if (!editForm) return;
var contentEl = commentEl.querySelector(CONTENT_SELECTOR);
if (contentEl) contentEl.style.display = '';
editForm.remove();
}
function saveEdit(commentEl, commentId, saveBtn) {
var editForm = commentEl.querySelector('.aksrt-comment-edit-form');
if (!editForm) return;
var textarea = editForm.querySelector('.aksrt-comment-edit-textarea');
var newContent = textarea ? textarea.value.trim() : '';
if (!newContent) return;
if (saveBtn) { saveBtn.disabled = true; saveBtn.textContent = '保存中...'; }
restPost('/comment/edit', { comment_id: commentId, content: newContent })
.then(function (result) {
if (result.success) {
var contentEl = commentEl.querySelector(CONTENT_SELECTOR);
if (contentEl) { contentEl.innerHTML = result.data.content; contentEl.style.display = ''; }
editForm.remove();
} else {
notify((result.data && result.data.message) || result.message || '编辑失败', 'error');
if (saveBtn) { saveBtn.disabled = false; saveBtn.textContent = '保存'; }
}
})
.catch(function () {
notify('网络错误', 'error');
if (saveBtn) { saveBtn.disabled = false; saveBtn.textContent = '保存'; }
});
}
function handleDelete(commentEl, commentId) {
var msg = (window.aksrt && aksrt.__) ? aksrt.__('comment_confirm_delete', '确定要删除这条评论吗?') : '确定要删除这条评论吗?';
var doDelete = function () {