Files
wordpress-theme-aksrt/assets/js/core/comment-move-form.js
T
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

233 lines
7.7 KiB
JavaScript

/**
* Comment moveForm for reply/edit (legacy parity) — REST-backed edit fetch.
*/
(function () {
'use strict';
var respondId = 'respond';
var tempId = 'jio-wp-temp-form-div';
var editingId = 0;
function getRespond() {
return document.getElementById(respondId);
}
function restRoot() {
var d = window.jioData || {};
return (d.restUrl || d.rest_url || '/wp-json/jio/v1').replace(/\/$/, '');
}
function nonce() {
var d = window.jioData || {};
return d.restNonce || d.nonce || '';
}
function setActionText(text) {
var el = document.querySelector('#' + respondId + ' .action-text');
if (!el) return;
if (text) {
el.style.display = '';
el.textContent = text;
} else {
el.style.display = 'none';
el.textContent = '';
}
}
function ensureParentField(respond) {
var form = respond.querySelector('#commentform') || respond;
var parent = form.querySelector('[name="comment_parent"]');
if (!parent) {
parent = document.createElement('input');
parent.type = 'hidden';
parent.name = 'comment_parent';
parent.id = 'comment_parent';
parent.value = '0';
form.appendChild(parent);
}
return parent;
}
function ensureEditField(respond, commentId) {
var form = respond.querySelector('#commentform') || respond;
var existing = form.querySelector('[name="edit_comment_ID"]');
if (commentId) {
if (!existing) {
existing = document.createElement('input');
existing.type = 'hidden';
existing.name = 'edit_comment_ID';
existing.id = 'edit_comment_ID';
form.appendChild(existing);
}
existing.value = String(commentId);
// Hide parent while editing.
var parent = form.querySelector('[name="comment_parent"]');
if (parent) parent.name = 'comment_parent_bak';
} else if (existing) {
existing.remove();
var bak = form.querySelector('[name="comment_parent_bak"]');
if (bak) bak.name = 'comment_parent';
}
}
function moveForm(commId, parentId, isEdit) {
var respond = getRespond();
if (!respond) return false;
var comm = document.getElementById(commId);
var parent = ensureParentField(respond);
var cancel = document.getElementById('cancel-comment-reply-link');
var submit = respond.querySelector('#submit');
var textarea = respond.querySelector('#comment');
if (!document.getElementById(tempId)) {
var temp = document.createElement('div');
temp.id = tempId;
temp.style.display = 'none';
respond.parentNode.insertBefore(temp, respond);
}
if (comm && comm.parentNode) {
comm.parentNode.insertBefore(respond, comm.nextSibling);
}
parent.value = isEdit ? '0' : String(parentId || '0');
editingId = isEdit ? parseInt(parentId, 10) || 0 : 0;
if (cancel) {
cancel.style.display = '';
cancel.onclick = function () {
var t = document.getElementById(tempId);
var r = getRespond();
if (t && r && t.parentNode) {
t.parentNode.insertBefore(r, t);
t.parentNode.removeChild(t);
}
ensureEditField(r, 0);
if (parent) parent.value = '0';
setActionText('');
if (textarea) textarea.value = '';
editingId = 0;
cancel.style.display = 'none';
if (window.JioFixedInput) window.JioFixedInput(r, 'hide');
else if (r) r.classList.remove('show');
return false;
};
}
if (isEdit && editingId) {
setActionText('编辑评论');
ensureEditField(respond, editingId);
if (textarea) {
textarea.disabled = true;
textarea.value = '加载中…';
}
if (submit) submit.disabled = true;
fetch(restRoot() + '/comment/get?comment_id=' + encodeURIComponent(String(editingId)), {
headers: { 'X-WP-Nonce': nonce() },
credentials: 'same-origin',
})
.then(function (r) { return r.json(); })
.then(function (json) {
var content = (json && (json.content || (json.data && json.data.content))) || '';
if (textarea) {
textarea.disabled = false;
textarea.value = content;
textarea.dispatchEvent(new Event('input'));
}
if (submit) submit.disabled = false;
})
.catch(function () {
notyf('加载评论失败', 'danger');
if (textarea) {
textarea.disabled = false;
textarea.value = '';
}
if (submit) submit.disabled = false;
});
} else {
var nameEl = comm ? comm.querySelector('.comment-header name') : null;
var author = nameEl ? (nameEl.textContent || '').trim() : '';
setActionText(author ? ('回复 @' + author) : '回复评论');
ensureEditField(respond, 0);
if (textarea) {
textarea.focus();
}
}
if (window.JioFixedInput) {
window.JioFixedInput(respond, 'show');
} else {
respond.classList.add('show');
}
if (comm && comm.scrollIntoView) {
comm.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
return false;
}
document.addEventListener('click', function (e) {
var reply = e.target && e.target.closest ? e.target.closest('.comment-reply-link') : null;
var edit = e.target && e.target.closest ? e.target.closest('.comment-edit-link, [data-comment-action="edit"]') : null;
if (reply) {
e.preventDefault();
var cid = reply.getAttribute('data-commentid') || reply.getAttribute('data-comment-id') || '';
var postid = reply.getAttribute('data-postid') || '';
if (!cid) {
var li = reply.closest('[data-comment-id], #comment-' + (cid || ''));
if (li && li.getAttribute('data-comment-id')) cid = li.getAttribute('data-comment-id');
}
if (!cid) {
var m = (reply.closest('li[id^="comment-"]') || {}).id || '';
var mm = /comment-(\d+)/.exec(m);
if (mm) cid = mm[1];
}
moveForm('div-comment-' + cid, cid, false);
return;
}
if (edit) {
e.preventDefault();
var eid = edit.getAttribute('data-commentid') || edit.getAttribute('data-comment-id') || '';
if (!eid) {
var row = edit.closest('[data-comment-id]');
if (row) eid = row.getAttribute('data-comment-id');
}
if (!eid) return;
moveForm('div-comment-' + eid, eid, true);
}
});
// Dropup / dropdown toggles (guest info, expand toolbar, action menu).
document.addEventListener('click', function (e) {
var t = e.target && e.target.closest ? e.target.closest('[data-toggle-class="open"], span.dropup > a.but, [data-toggle="dropdown"]') : null;
if (!t) return;
var wrap = t.closest('span.dropup, span.dropdown');
if (!wrap) return;
// 点击已在打开的下拉内部(表情/快捷项等)不切换
if (wrap.classList.contains('open') && t.parentElement !== wrap) return;
e.preventDefault();
wrap.classList.toggle('open');
});
// Close dropups on outside click.
document.addEventListener('click', function (e) {
if (e.target.closest && e.target.closest('span.dropup.open, span.dropdown.open')) return;
document.querySelectorAll('span.dropup.open, span.dropdown.open').forEach(function (n) {
n.classList.remove('open');
});
});
// Scroll helper for @parent.
document.addEventListener('click', function (e) {
var a = e.target && e.target.closest ? e.target.closest('[data-scroll-to]') : null;
if (!a) return;
e.preventDefault();
var sel = a.getAttribute('data-scroll-to');
var el = sel ? document.querySelector(sel) : null;
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' });
});
window.jioCommentMoveForm = moveForm;
window.jioGetEditingCommentId = function () { return editingId; };
})();