fix(comments): align image upload with Zibll
Unify comment image upload settings, REST permissions, preview, progress, and response handling while removing obsolete compatibility paths.
This commit is contained in:
1 parent
129432ae45
commit
44e165d34e
14 files changed
+513
-216
No files matched your search
@@ -15,6 +15,7 @@ export const commentSchema = {
|
||||
comment_edit_window: 10,
|
||||
comment_code: true,
|
||||
comment_img: true,
|
||||
comment_upload_img: false,
|
||||
comment_link: false,
|
||||
comment_like_s: true,
|
||||
comment_hot_threshold: 10,
|
||||
|
||||
@@ -213,12 +213,62 @@
|
||||
*
|
||||
* 评论区布局样式已硬切换为自有版权(见 layout.css / mobile-item.css),
|
||||
* vendor main.min.css 不再提供评论区规则。
|
||||
* 本文件只放 AKSRT 特有标记的补充规则(identity chip/medal)。
|
||||
* 本文件放 AKSRT 特有标记与评论图片上传的补充规则。
|
||||
* 共享基础样式仍由 bundle 中更早加载的 bootstrap 3 与
|
||||
* core/tokens.css 提供。
|
||||
* ============================================================ */
|
||||
|
||||
/* 身份徽章(AKSRT 渲染于 <name> 内,对应 legacy 的认证/等级徽章位) */
|
||||
#comments .comment-image-tabs .comment-image-upload {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload-label {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .preview {
|
||||
width: 100%;
|
||||
height: 96px;
|
||||
min-height: 96px;
|
||||
margin-bottom: 6px;
|
||||
overflow: hidden;
|
||||
border: 1px dashed var(--muted-border-color);
|
||||
border-radius: var(--main-radius);
|
||||
background: var(--main-shadow);
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .preview img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 96px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .input-expand-upload {
|
||||
min-width: 88px;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .progress {
|
||||
position: static;
|
||||
inset: auto;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
margin-top: 4px;
|
||||
overflow: hidden;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .progress-bar {
|
||||
position: static;
|
||||
inset: auto;
|
||||
display: block;
|
||||
height: 100%;
|
||||
width: 0;
|
||||
transition: width 0.2s ease;
|
||||
}
|
||||
#comments .comment-header .aksrt-identity-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
#comments .comment-box .comments-closed,#comments .action-text,#comments #cancel-comment-reply-link{display:none}#comments #postcomments .action-text,#comments #postcomments #cancel-comment-reply-link{display:inline-block}#comments .comt-title{width:90px}#comments .comt-title .comt-avatar .avatar{width:60px;height:60px}#comments #postcomments .comt-title{display:none}#respond:not(.mobile-fixed) #postcomments .comt-box{padding:5px 5px 4px;background:var(--main-bg-color);border-radius:4px;margin-top:12px}#comments #postcomments .comt-ctrl .but{margin-bottom:2px}#comments .list-inline{padding:15px}#comment{margin-bottom:5px}.comment-signarea{background:var(--main-shadow)}#respond+#postcomments .comment-filter,.comment-signarea+#postcomments .comment-filter{margin-top:20px}#postcomments .tab-nav-theme{margin-top:0}#postcomments .tab-nav-theme li{padding-bottom:1px}#postcomments .tab-nav-theme li:before{bottom:-2px}#postcomments .comment-footer{position:relative}#postcomments .avatar-img{--this-size: 45px;margin-right:20px}#postcomments .children .avatar-img{--this-size: 26px;vertical-align:2px;margin-right:6px}#postcomments .commentlist>.comment>.list-inline .author-box{align-items:start;margin-bottom:0;padding:0;background:none;border-radius:0;box-shadow:none}#postcomments .commentlist>.comment>.list-inline .comment-footer{margin-left:65px;margin-top:-25px}#postcomments .comment .list-inline>.comt-main{width:100%}#postcomments .commentlist .comment+.comment{border-top:1px solid var(--main-border-color)}#postcomments .comment .list-inline>li{padding:10px;vertical-align:top}#postcomments .comment-header{font-size:15px;position:relative}.comment-header .badge-status{margin-top:0;width:68px;z-index:0}#postcomments .action count{margin-left:4px}#postcomments .comt-meta>span:not(:empty){margin-right:10px;vertical-align:middle}#postcomments .comt-meta>span a{color:inherit}#postcomments .comt-meta>span .but{padding:.2em .8em}#postcomments .comment-approve-link.unapprove{color:#e87725}#postcomments .comment-approve-link.approve{color:#3695ff}#postcomments .comt-meta>span .comment-trash-link{color:#ff4b4b}#postcomments .children{list-style:none;padding-left:0;margin-left:86px;background:var(--main-shadow);border-radius:var(--main-radius);margin-bottom:6px}#postcomments .children .children{margin-left:23px}#postcomments .children .avatar-icontag{font-size:8px;height:14px;width:14px}.comment-content{word-wrap:break-word;white-space:pre-wrap}.comment-content .enlighter-default{margin-bottom:0;opacity:.9}#postcomments .comment-content img{max-width:260px;max-height:350px;display:block;width:auto;height:auto}#comments .virtual-input{display:none}.commentlist .no-more{margin:0;padding-bottom:10px}#comments .comment-header .aksrt-identity-chip{display:inline-flex;align-items:center;gap:3px;vertical-align:middle;max-width:9em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}#comments .comment-header .aksrt-identity-medal{display:inline-block;width:auto;height:1.1em;max-width:6em;object-fit:contain;vertical-align:-.15em}@media(max-width:767px){#comments .virtual-input{display:flex;height:36px;border-radius:120px;background:var(--main-shadow);color:var(--muted-2-color)}.virtual-input .but,.virtual-input img{width:28px;height:28px;border-radius:120px;margin:0 4px;flex-shrink:0}.virtual-input .but{width:auto;padding:3px 10px}.drop-fixed-sm .dropdown-menu,.mobile-fixed{position:fixed;transform:translateY(220%);transition:.6s;opacity:1;left:0;right:0;bottom:0;padding:22px 16px;background:var(--main-bg-color);z-index:1080;border-radius:10px 10px 0 0;margin:0}.drop-fixed-sm.open .dropdown-menu,.mobile-fixed.show{box-shadow:0 -50px 50px #0003;transition:.6s cubic-bezier(.28,.9,.34,.99);transform:unset}.mobile-fixed.show .fixed-body{visibility:unset;z-index:-1}#respond.mobile-fixed{z-index:1040}.drop-fixed-sm .dropdown-menu{z-index:1045;padding:10px;top:auto!important;right:0!important;left:0!important;max-height:50vh;overflow:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch}.drop-fixed-sm .dropdown-menu>li>a{font-size:16px!important;padding:10px 20px}.modal-open .drop-fixed-sm.open .dropdown-menu{opacity:0}.drop-fixed-sm .dropdown-menu:before{display:none}}@media(max-width:640px){#comments .comt-title{display:none}#comments .comt-box{width:100%;padding:0}#comments .list-inline{padding:15px 0;margin:0}.comment-signarea h3{font-size:13px}.comt-tips-left .but svg,.comt-tips-left .but .fa{margin:0}.btn-input-expand{width:31px;padding:0;height:31px;line-height:31px}#postcomments .comment-header{font-size:14px}#postcomments .comt-meta{font-size:12px}#postcomments .comment .list-inline>li{padding:0}#postcomments .comment .list-inline>li+li{padding-left:10px}#postcomments .avatar-img{--this-size: 36px;margin-right:10px}#postcomments .commentlist>.comment>.list-inline .comment-footer{margin-left:45px;margin-top:-15px}#postcomments .children{margin-left:0}#postcomments .children .children{margin-left:13px}#postcommLine truncated
|
||||
#comments .comment-box .comments-closed,#comments .action-text,#comments #cancel-comment-reply-link{display:none}#comments #postcomments .action-text,#comments #postcomments #cancel-comment-reply-link{display:inline-block}#comments .comt-title{width:90px}#comments .comt-title .comt-avatar .avatar{width:60px;height:60px}#comments #postcomments .comt-title{display:none}#respond:not(.mobile-fixed) #postcomments .comt-box{padding:5px 5px 4px;background:var(--main-bg-color);border-radius:4px;margin-top:12px}#comments #postcomments .comt-ctrl .but{margin-bottom:2px}#comments .list-inline{padding:15px}#comment{margin-bottom:5px}.comment-signarea{background:var(--main-shadow)}#respond+#postcomments .comment-filter,.comment-signarea+#postcomments .comment-filter{margin-top:20px}#postcomments .tab-nav-theme{margin-top:0}#postcomments .tab-nav-theme li{padding-bottom:1px}#postcomments .tab-nav-theme li:before{bottom:-2px}#postcomments .comment-footer{position:relative}#postcomments .avatar-img{--this-size: 45px;margin-right:20px}#postcomments .children .avatar-img{--this-size: 26px;vertical-align:2px;margin-right:6px}#postcomments .commentlist>.comment>.list-inline .author-box{align-items:start;margin-bottom:0;padding:0;background:none;border-radius:0;box-shadow:none}#postcomments .commentlist>.comment>.list-inline .comment-footer{margin-left:65px;margin-top:-25px}#postcomments .comment .list-inline>.comt-main{width:100%}#postcomments .commentlist .comment+.comment{border-top:1px solid var(--main-border-color)}#postcomments .comment .list-inline>li{padding:10px;vertical-align:top}#postcomments .comment-header{font-size:15px;position:relative}.comment-header .badge-status{margin-top:0;width:68px;z-index:0}#postcomments .action count{margin-left:4px}#postcomments .comt-meta>span:not(:empty){margin-right:10px;vertical-align:middle}#postcomments .comt-meta>span a{color:inherit}#postcomments .comt-meta>span .but{padding:.2em .8em}#postcomments .comment-approve-link.unapprove{color:#e87725}#postcomments .comment-approve-link.approve{color:#3695ff}#postcomments .comt-meta>span .comment-trash-link{color:#ff4b4b}#postcomments .children{list-style:none;padding-left:0;margin-left:86px;background:var(--main-shadow);border-radius:var(--main-radius);margin-bottom:6px}#postcomments .children .children{margin-left:23px}#postcomments .children .avatar-icontag{font-size:8px;height:14px;width:14px}.comment-content{word-wrap:break-word;white-space:pre-wrap}.comment-content .enlighter-default{margin-bottom:0;opacity:.9}#postcomments .comment-content img{max-width:260px;max-height:350px;display:block;width:auto;height:auto}#comments .virtual-input{display:none}.commentlist .no-more{margin:0;padding-bottom:10px}#comments .comment-image-tabs .comment-image-upload{margin:0}#comments .comment-image-upload-label{display:block;width:100%}#comments .comment-image-upload .preview{width:100%;height:96px;min-height:96px;margin-bottom:6px;overflow:hidden;border:1px dashed var(--muted-border-color);border-radius:var(--main-radius);background:var(--main-shadow)}#comments .comment-image-upload .preview img{display:block;width:100%;height:96px;object-fit:cover}#comments .comment-image-upload .input-expand-upload{min-width:88px}#comments .comment-image-upload .progress{position:static;inset:auto;display:block;width:100%;height:3px;margin-top:4px;overflow:hidden;border-radius:3px;background:#ffffff40}#comments .comment-image-upload .progress-bar{position:static;inset:auto;display:block;height:100%;width:0;transition:width .2s ease}#comments .comment-header .aksrt-identity-chip{display:inline-flex;align-items:center;gap:3px;vertical-align:middle;max-width:9em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px}#comments .comment-header .aksrt-identity-medal{display:inline-block;width:auto;height:1.1em;max-width:6em;object-fit:contain;vertical-align:-.15em}@media(max-width:767px){#comments .virtual-input{display:flex;height:36px;border-radius:120px;background:var(--main-shadow);color:var(--muted-2-color)}.virtual-input .but,.virtual-input img{width:28px;height:28px;border-radius:120px;margin:0 4px;flex-shrink:0}.virtual-input .but{width:auto;padding:3px 10px}.drop-fixed-sm .dropdown-menu,.mobile-fixed{position:fixed;transform:translateY(220%);transition:.6s;opacity:1;left:0;right:0;bottom:0;padding:22px 16px;background:var(--main-bg-color);z-index:1080;border-radius:10px 10px 0 0;margin:0}.drop-fixed-sm.open .dropdown-menu,.mobile-fixed.show{box-shadow:0 -50px 50px #0003;transition:.6s cubic-bezier(.28,.9,.34,.99);transform:unset}.mobile-fixed.show .fixed-body{visibility:unset;z-index:-1}#respond.mobile-fixed{z-index:1040}.drop-fixed-sm .dropdown-menu{z-index:1045;padding:10px;top:auto!important;right:0!important;left:0!important;max-height:50vh;overflow:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch}.drop-fixed-sm .dropdown-menu>li>a{font-size:16px!important;padding:10px 20px}.modal-open .drop-fixed-sm.open .dropdown-menu{opacLine truncated
|
||||
@@ -3,12 +3,62 @@
|
||||
*
|
||||
* 评论区布局样式已硬切换为自有版权(见 layout.css / mobile-item.css),
|
||||
* vendor main.min.css 不再提供评论区规则。
|
||||
* 本文件只放 AKSRT 特有标记的补充规则(identity chip/medal)。
|
||||
* 本文件放 AKSRT 特有标记与评论图片上传的补充规则。
|
||||
* 共享基础样式仍由 bundle 中更早加载的 bootstrap 3 与
|
||||
* core/tokens.css 提供。
|
||||
* ============================================================ */
|
||||
|
||||
/* 身份徽章(AKSRT 渲染于 <name> 内,对应 legacy 的认证/等级徽章位) */
|
||||
#comments .comment-image-tabs .comment-image-upload {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload-label {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .preview {
|
||||
width: 100%;
|
||||
height: 96px;
|
||||
min-height: 96px;
|
||||
margin-bottom: 6px;
|
||||
overflow: hidden;
|
||||
border: 1px dashed var(--muted-border-color);
|
||||
border-radius: var(--main-radius);
|
||||
background: var(--main-shadow);
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .preview img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 96px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .input-expand-upload {
|
||||
min-width: 88px;
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .progress {
|
||||
position: static;
|
||||
inset: auto;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
margin-top: 4px;
|
||||
overflow: hidden;
|
||||
border-radius: 3px;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
#comments .comment-image-upload .progress-bar {
|
||||
position: static;
|
||||
inset: auto;
|
||||
display: block;
|
||||
height: 100%;
|
||||
width: 0;
|
||||
transition: width 0.2s ease;
|
||||
}
|
||||
#comments .comment-header .aksrt-identity-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
+256
-79
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* Comment expand tools — legacy-style shortcode inserts ([code] [img=]).
|
||||
* Comment expand tools — shortcode inserts and comment image upload.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var uploadStates = new WeakMap();
|
||||
|
||||
function findTextarea(from) {
|
||||
var form = from && from.closest ? from.closest('form') : null;
|
||||
if (form) {
|
||||
@@ -24,107 +26,282 @@
|
||||
textarea.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
function restUpload(file) {
|
||||
var d = window.aksrtData || {};
|
||||
var url = d.commentUploadUrl || ((d.restUrl || '/wp-json/aksrt/v1').replace(/\/$/, '') + '/comment/upload-image');
|
||||
var fd = new FormData();
|
||||
fd.append('image', file);
|
||||
fd.append('file', file);
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'X-WP-Nonce': d.restNonce || d.nonce || '' },
|
||||
credentials: 'same-origin',
|
||||
body: fd
|
||||
}).then(function (r) { return r.json(); });
|
||||
function notify(message, type) {
|
||||
if (typeof window.notyf === 'function') {
|
||||
window.notyf(message, type);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
var linkBtn = e.target && e.target.closest ? e.target.closest('.input-link-submit') : null;
|
||||
if (linkBtn) {
|
||||
e.preventDefault();
|
||||
var lbox = linkBtn.closest('.dropdown-link');
|
||||
var lta = lbox ? lbox.querySelector('textarea.link-textarea') : null;
|
||||
var url = lta ? (lta.value || '').trim() : '';
|
||||
if (!/^https?:\/\/\S+$/i.test(url)) {
|
||||
notyf('请输入有效链接地址', 'warning');
|
||||
return;
|
||||
}
|
||||
var ltext = lbox ? (lbox.querySelector('.link-text') || {}).value || '' : '';
|
||||
insertAtCursor(findTextarea(linkBtn), '[link=' + url + ']' + (ltext.trim() || url) + '[/link]');
|
||||
if (lta) lta.value = '';
|
||||
var lt = lbox ? lbox.querySelector('.link-text') : null;
|
||||
if (lt) lt.value = '';
|
||||
var lw = linkBtn.closest('span.dropup');
|
||||
if (lw) lw.classList.remove('open');
|
||||
function showImageTab(trigger) {
|
||||
var selector = trigger.getAttribute('data-image-tab');
|
||||
var wrapper = trigger.closest('.comment-image-tabs');
|
||||
if (!selector || !wrapper) return null;
|
||||
var target = wrapper.querySelector(selector);
|
||||
if (!target) return null;
|
||||
|
||||
wrapper.querySelectorAll('.tab-pane').forEach(function (pane) {
|
||||
pane.classList.remove('in', 'active');
|
||||
});
|
||||
target.classList.add('in', 'active');
|
||||
return target;
|
||||
}
|
||||
|
||||
function getUploadState(form) {
|
||||
var state = uploadStates.get(form);
|
||||
if (state) return state;
|
||||
|
||||
var preview = form.querySelector('.preview');
|
||||
state = {
|
||||
file: null,
|
||||
uploading: false,
|
||||
previewHtml: preview ? preview.innerHTML : ''
|
||||
};
|
||||
uploadStates.set(form, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
function resetUpload(form) {
|
||||
var state = getUploadState(form);
|
||||
var input = form.querySelector('.comment-image-file');
|
||||
var preview = form.querySelector('.preview');
|
||||
|
||||
state.file = null;
|
||||
state.uploading = false;
|
||||
if (input) {
|
||||
input.disabled = false;
|
||||
input.value = '';
|
||||
}
|
||||
if (preview) preview.innerHTML = state.previewHtml;
|
||||
}
|
||||
|
||||
function restoreUploadButton(button, html) {
|
||||
button.disabled = false;
|
||||
button.innerHTML = html;
|
||||
}
|
||||
|
||||
function validateImage(input, file) {
|
||||
var accepts = (input.getAttribute('accept') || '')
|
||||
.split(',')
|
||||
.map(function (type) { return type.trim().toLowerCase(); })
|
||||
.filter(Boolean);
|
||||
var fileType = (file.type || '').toLowerCase();
|
||||
if (accepts.length && accepts.indexOf(fileType) === -1) {
|
||||
notify('图片格式错误:' + file.name, 'danger');
|
||||
return false;
|
||||
}
|
||||
|
||||
var maxSize = Number((window.aksrtData || {}).commentUploadMaxSize) || 0;
|
||||
if (maxSize > 0 && file.size > maxSize) {
|
||||
notify('图片大小不能超过 ' + Math.round(maxSize / 1024 / 1024) + 'MB', 'danger');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function previewImage(form, file) {
|
||||
var preview = form.querySelector('.preview');
|
||||
if (!preview) return;
|
||||
if (typeof FileReader === 'undefined') {
|
||||
notify('当前浏览器不支持图片预览', 'danger');
|
||||
return;
|
||||
}
|
||||
|
||||
var codeBtn = e.target && e.target.closest ? e.target.closest('.input-code-submit') : null;
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
if (getUploadState(form).file !== file) return;
|
||||
var image = document.createElement('img');
|
||||
image.className = 'fit-cover';
|
||||
image.alt = '';
|
||||
image.src = event.target.result;
|
||||
preview.innerHTML = '';
|
||||
preview.appendChild(image);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
function parseUploadResponse(xhr) {
|
||||
try {
|
||||
return JSON.parse(xhr.responseText || '{}');
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function uploadImage(button) {
|
||||
var form = button.closest('.comment-image-upload');
|
||||
if (!form) return;
|
||||
|
||||
var input = form.querySelector('.comment-image-file');
|
||||
var state = getUploadState(form);
|
||||
if (!input || !state.file) {
|
||||
notify('请先选择待上传的图片', 'danger');
|
||||
return;
|
||||
}
|
||||
if (state.uploading) return;
|
||||
|
||||
var data = window.aksrtData || {};
|
||||
var uploadUrl = data.commentUploadUrl || '';
|
||||
if (!uploadUrl) {
|
||||
notify('图片上传服务不可用', 'danger');
|
||||
return;
|
||||
}
|
||||
|
||||
var originalHtml = button.innerHTML;
|
||||
var formData = new FormData();
|
||||
formData.append('image', state.file, state.file.name);
|
||||
|
||||
state.uploading = true;
|
||||
button.disabled = true;
|
||||
input.disabled = true;
|
||||
button.innerHTML = '<span class="miniupload-ing"><i class="loading mr3 c-white"></i><span class="loading-text c-white">上传中<count class="px12 ml3"></count></span><span class="progress progress-striped active"><span class="progress-bar progress-bar-success" role="progressbar" style="width:0"></span></span></span>';
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', uploadUrl, true);
|
||||
if (data.restNonce) xhr.setRequestHeader('X-WP-Nonce', data.restNonce);
|
||||
|
||||
xhr.upload.onprogress = function (event) {
|
||||
if (!event.lengthComputable) return;
|
||||
var percent = Math.round((event.loaded / event.total) * 100);
|
||||
var count = button.querySelector('count');
|
||||
var progress = button.querySelector('.progress-bar');
|
||||
var loadingText = button.querySelector('.loading-text');
|
||||
if (count) count.textContent = percent + '%';
|
||||
if (progress) progress.style.width = percent + '%';
|
||||
if (percent >= 100 && loadingText) loadingText.firstChild.nodeValue = '处理中';
|
||||
};
|
||||
|
||||
xhr.onload = function () {
|
||||
var response = parseUploadResponse(xhr);
|
||||
var url = response && response.success === true && response.data
|
||||
? response.data.url
|
||||
: '';
|
||||
|
||||
if (xhr.status < 200 || xhr.status >= 300 || typeof url !== 'string' || url.length < 6) {
|
||||
var message = response && response.message ? response.message : '图片上传失败';
|
||||
notify(message, 'danger');
|
||||
restoreUploadButton(button, originalHtml);
|
||||
resetUpload(form);
|
||||
return;
|
||||
}
|
||||
|
||||
notify(response.message || '图片已上传', 'success');
|
||||
insertAtCursor(findTextarea(button), '[img=' + url + ']\n');
|
||||
restoreUploadButton(button, originalHtml);
|
||||
resetUpload(form);
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
notify('网络错误,图片上传失败', 'danger');
|
||||
restoreUploadButton(button, originalHtml);
|
||||
resetUpload(form);
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
document.addEventListener('change', function (event) {
|
||||
var input = event.target && event.target.closest
|
||||
? event.target.closest('.comment-image-file')
|
||||
: null;
|
||||
if (!input) return;
|
||||
|
||||
var form = input.closest('.comment-image-upload');
|
||||
var file = input.files && input.files[0];
|
||||
if (!form || !file) return;
|
||||
if (!validateImage(input, file)) {
|
||||
resetUpload(form);
|
||||
return;
|
||||
}
|
||||
|
||||
var state = getUploadState(form);
|
||||
state.file = file;
|
||||
previewImage(form, file);
|
||||
var button = form.querySelector('[data-comment-upload-submit]');
|
||||
if (button) uploadImage(button);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var linkBtn = event.target && event.target.closest ? event.target.closest('.input-link-submit') : null;
|
||||
if (linkBtn) {
|
||||
event.preventDefault();
|
||||
var linkBox = linkBtn.closest('.dropdown-link');
|
||||
var linkTextarea = linkBox ? linkBox.querySelector('textarea.link-textarea') : null;
|
||||
var linkUrl = linkTextarea ? (linkTextarea.value || '').trim() : '';
|
||||
if (!/^https?:\/\/\S+$/i.test(linkUrl)) {
|
||||
notify('请输入有效链接地址', 'warning');
|
||||
return;
|
||||
}
|
||||
var linkTextInput = linkBox ? linkBox.querySelector('.link-text') : null;
|
||||
var linkText = linkTextInput ? linkTextInput.value || '' : '';
|
||||
insertAtCursor(findTextarea(linkBtn), '[link=' + linkUrl + ']' + (linkText.trim() || linkUrl) + '[/link]');
|
||||
if (linkTextarea) linkTextarea.value = '';
|
||||
if (linkTextInput) linkTextInput.value = '';
|
||||
var linkWrapper = linkBtn.closest('span.dropup');
|
||||
if (linkWrapper) linkWrapper.classList.remove('open');
|
||||
return;
|
||||
}
|
||||
|
||||
var codeBtn = event.target && event.target.closest ? event.target.closest('.input-code-submit') : null;
|
||||
if (codeBtn) {
|
||||
e.preventDefault();
|
||||
var box = codeBtn.closest('.dropdown-code, .input-expand-code');
|
||||
var ta = box ? box.querySelector('textarea') : null;
|
||||
var code = ta ? ta.value : '';
|
||||
event.preventDefault();
|
||||
var codeBox = codeBtn.closest('.dropdown-code, .input-expand-code');
|
||||
var codeTextarea = codeBox ? codeBox.querySelector('textarea') : null;
|
||||
var code = codeTextarea ? codeTextarea.value : '';
|
||||
if (!code || code.length < 2) {
|
||||
notyf('请输入代码', 'warning');
|
||||
notify('请输入代码', 'warning');
|
||||
return;
|
||||
}
|
||||
insertAtCursor(findTextarea(codeBtn), '[code]\n' + code + '\n[/code]\n');
|
||||
if (ta) ta.value = '';
|
||||
var w = codeBtn.closest('span.dropup');
|
||||
if (w) w.classList.remove('open');
|
||||
if (codeTextarea) codeTextarea.value = '';
|
||||
var codeWrapper = codeBtn.closest('span.dropup');
|
||||
if (codeWrapper) codeWrapper.classList.remove('open');
|
||||
return;
|
||||
}
|
||||
|
||||
var imgBtn = e.target && e.target.closest ? e.target.closest('.input-image-submit') : null;
|
||||
if (imgBtn) {
|
||||
e.preventDefault();
|
||||
var ibox = imgBtn.closest('.dropdown-image, .input-expand-image');
|
||||
var input = ibox ? ibox.querySelector('.input-image-url') : null;
|
||||
var url = input ? (input.value || '').trim() : '';
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
notyf('请输入有效图片地址', 'warning');
|
||||
var imageSubmit = event.target && event.target.closest ? event.target.closest('.input-image-submit') : null;
|
||||
if (imageSubmit) {
|
||||
event.preventDefault();
|
||||
var imageBox = imageSubmit.closest('.dropdown-image');
|
||||
var imageInput = imageBox ? imageBox.querySelector('.input-image-url') : null;
|
||||
var imageUrl = imageInput ? (imageInput.value || '').trim() : '';
|
||||
if (imageUrl.length < 6) {
|
||||
notify('请输入有效图片地址', 'warning');
|
||||
return;
|
||||
}
|
||||
insertAtCursor(findTextarea(imgBtn), '[img=' + url + ']');
|
||||
if (input) input.value = '';
|
||||
var iw = imgBtn.closest('span.dropup');
|
||||
if (iw) iw.classList.remove('open');
|
||||
insertAtCursor(findTextarea(imageSubmit), '[img=' + imageUrl + ']\n');
|
||||
return;
|
||||
}
|
||||
|
||||
var upBtn = e.target && e.target.closest ? e.target.closest('.input-image-upload') : null;
|
||||
if (upBtn) {
|
||||
e.preventDefault();
|
||||
var fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
fileInput.accept = 'image/jpeg,image/png,image/gif,image/webp';
|
||||
fileInput.addEventListener('change', function () {
|
||||
var file = fileInput.files && fileInput.files[0];
|
||||
if (!file) return;
|
||||
restUpload(file)
|
||||
.then(function (json) {
|
||||
var u = (json && (json.url || json.source_url || (json.data && (json.data.url || json.data.source_url)))) || '';
|
||||
if (!u) {
|
||||
notyf((json && json.message) || '上传失败', 'danger');
|
||||
return;
|
||||
}
|
||||
insertAtCursor(findTextarea(upBtn), '[img=' + u + ']');
|
||||
})
|
||||
.catch(function () { notyf('上传失败', 'danger'); });
|
||||
});
|
||||
fileInput.click();
|
||||
var uploadTab = event.target && event.target.closest ? event.target.closest('.input-image-upload-tab') : null;
|
||||
if (uploadTab) {
|
||||
event.preventDefault();
|
||||
var uploadPane = showImageTab(uploadTab);
|
||||
var uploadInput = uploadPane ? uploadPane.querySelector('.comment-image-file') : null;
|
||||
if (uploadInput) uploadInput.click();
|
||||
return;
|
||||
}
|
||||
|
||||
var addressTab = event.target && event.target.closest ? event.target.closest('.input-image-address-tab') : null;
|
||||
if (addressTab) {
|
||||
event.preventDefault();
|
||||
showImageTab(addressTab);
|
||||
return;
|
||||
}
|
||||
|
||||
var uploadButton = event.target && event.target.closest ? event.target.closest('[data-comment-upload-submit]') : null;
|
||||
if (uploadButton) {
|
||||
event.preventDefault();
|
||||
uploadImage(uploadButton);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (!(e.ctrlKey || e.metaKey) || e.key !== 'Enter') return;
|
||||
var ta = e.target;
|
||||
if (!ta || ta.id !== 'comment') return;
|
||||
var form = ta.closest('#commentform');
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (!(event.ctrlKey || event.metaKey) || event.key !== 'Enter') return;
|
||||
var textarea = event.target;
|
||||
if (!textarea || textarea.id !== 'comment') return;
|
||||
var form = textarea.closest('#commentform');
|
||||
if (!form) return;
|
||||
e.preventDefault();
|
||||
event.preventDefault();
|
||||
var submit = form.querySelector('#submit, [type="submit"]');
|
||||
if (submit) submit.click();
|
||||
});
|
||||
|
||||
@@ -59,19 +59,6 @@
|
||||
return formData;
|
||||
}
|
||||
|
||||
// 从 wp_die() HTML 中提取错误信息
|
||||
function extractErrorMessage(html) {
|
||||
// WordPress wp_die() 输出格式: <p>错误信息</p>
|
||||
var match = html.match(/<p[^>]*>([^<]+)<\/p>/i);
|
||||
return match ? match[1].trim() : '未知错误';
|
||||
}
|
||||
|
||||
// 从错误消息中提取等待时间(秒)
|
||||
function extractWaitTime(msg) {
|
||||
var match = msg.match(/(\d+)\s*秒/);
|
||||
return match ? parseInt(match[1]) : 0;
|
||||
}
|
||||
|
||||
// 启动倒计时(用于频率限制)
|
||||
function startCountdown(seconds) {
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
@@ -106,93 +93,6 @@
|
||||
var nextCount = Math.max(0, parseInt(match[1], 10) + delta);
|
||||
countEl.textContent = text.replace(match[1], String(nextCount));
|
||||
}
|
||||
function handleResponse(responseText, statusCode) {
|
||||
try {
|
||||
// 情况1: 成功提交 - 包含评论ID或成功标记
|
||||
if (statusCode === 200 || statusCode === 201) {
|
||||
if (responseText.includes('comment-submitted') ||
|
||||
responseText.indexOf('id="comment-') !== -1 ||
|
||||
responseText.indexOf('awaiting-moderation') !== -1) {
|
||||
|
||||
// 区分是否需要审核
|
||||
if (responseText.indexOf('审核') !== -1 ||
|
||||
responseText.indexOf('moderation') !== -1 ||
|
||||
responseText.includes('awaiting-moderation')) {
|
||||
notyf('评论已提交,等待管理员审核', 'info');
|
||||
} else {
|
||||
notyf('评论发布成功', 'success');
|
||||
}
|
||||
|
||||
// 清空文本框
|
||||
var textarea = form.querySelector('#comment');
|
||||
if (textarea) textarea.value = '';
|
||||
|
||||
// 重置回复状态
|
||||
var replyInfo = document.getElementById('comment-reply-info');
|
||||
if (replyInfo) replyInfo.style.display = 'none';
|
||||
|
||||
// 刷新评论列表(延迟执行,确保后端处理完成)
|
||||
setTimeout(function () {
|
||||
reloadCommentList();
|
||||
}, 500);
|
||||
setLoading(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 情况2: HTTP 429 频率限制
|
||||
if (statusCode === 429) {
|
||||
var errorMsg = extractErrorMessage(responseText);
|
||||
var waitSeconds = extractWaitTime(errorMsg);
|
||||
|
||||
notyf(errorMsg, 'warning');
|
||||
|
||||
if (waitSeconds > 0) {
|
||||
startCountdown(waitSeconds);
|
||||
} else {
|
||||
setLoading(false); // 无具体等待时间时恢复按钮
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 情况3: HTTP 403 权限不足(地区/IP/关键词等)
|
||||
if (statusCode === 403) {
|
||||
var forbiddenMsg = extractErrorMessage(responseText);
|
||||
notyf(forbiddenMsg, 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 情况4: 包含WordPress错误信息
|
||||
var errorMatch = responseText.match(/<p[^>]*>([^<]*(?:错误|失败|error|Error)[^<]*)<\/p>/i);
|
||||
if (errorMatch) {
|
||||
notyf(errorMatch[1].trim(), 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
// 默认情况:可能是成功或其他
|
||||
notyf('评论已提交', 'success');
|
||||
var textarea2 = form.querySelector('#comment');
|
||||
if (textarea2) textarea2.value = '';
|
||||
|
||||
// 局部刷新评论列表(不再整页 reload)
|
||||
setTimeout(function () {
|
||||
reloadCommentList();
|
||||
}, 500);
|
||||
setLoading(false);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (e) {
|
||||
console.error('[AKSRT Comment] 解析响应失败:', e);
|
||||
notyf('响应解析异常,请重试', 'danger');
|
||||
setLoading(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 执行实际的 REST 请求 — local insert instead of full-page re-fetch
|
||||
function performSubmit(captchaPayload) {
|
||||
setLoading(true);
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
(function($,window2,document2){"use strict";function closeNotyf($element){$element.addClass("notyn-out"),window2.setTimeout(function(){$element.remove()},1e3)}function notyf2(message,type,time,id){var $body=jQuery(document2.body);jQuery(".notyn").length||$body.append('<div class="notyn"></div>'),type=type||"success",type==="error"&&(type="danger"),time=time||5e3,time=time<100?time*1e3:time;var idAttribute=id?' id="'+id+'"':"",$notification=jQuery('<div class="noty1"'+idAttribute+'><div class="notyf '+type+'">'+message+"</div></div>"),shouldClose=!id;id&&jQuery("#"+id).length?(jQuery("#"+id).find(".notyf").removeClass().addClass("notyf "+type).html(message),$notification=jQuery("#"+id),shouldClose=!0):jQuery(".notyn").append($notification),shouldClose&&window2.setTimeout(function(){closeNotyf($notification)},time)}jQuery(document2.body).on("click",".noty1",function(){closeNotyf(jQuery(this))}),window2.notyf=notyf2})(jQuery,window,document),(function(window2){"use strict";var allowedKinds={identity:!0,badges:!0,orders:!0,vip:!0},allowedEvents={click:!0,shell:!0,"first-content":!0,ready:!0,"action-start":!0,"action-end":!0,unauthorized:!0,error:!0},sessions=Object.create(null),sequence=0,maxSessions=100;function normalize(value,fallback){var normalized=String(value||fallback||"").toLowerCase().replace(/[^a-z0-9-]/g,"");return normalized||fallback}function now(){return window2.performance&&typeof window2.performance.now=="function"?window2.performance.now():0}function markName(session,event){return"aksrt-modal-"+session.kind+"-"+session.id+"-"+event}function emit(session,event){if(!(!window2.performance||typeof window2.performance.mark!="function")){var name=markName(session,event);if(window2.performance.mark(name),session.marks[event]=name,typeof window2.performance.measure=="function"&&session.marks.click&&event!=="click")try{window2.performance.measure("aksrt-modal-"+session.kind+"-"+session.id+"-click-to-"+event,session.marks.click,name)}catch{}}}function start(kind){var safeKind=normalize(kind,"unknown");allowedKinds[safeKind]||(safeKind="unknown"),sequence+=1;var id=String(sequence),session={id,kind:safeKind,startedAt:now(),marks:Object.create(null)};sessions[id]=session,emit(session,"click");for(var ids=Object.keys(sessions);ids.length>maxSessions;)delete sessions[ids.shift()];return id}function mark(id,event){var session=sessions[String(id||"")],safeEvent=normalize(event,"error");!session||!allowedEvents[safeEvent]||emit(session,safeEvent)}function finish(id){mark(id,"ready")}function fail(id){mark(id,"error")}window2.AksrtModalTelemetry={start,mark,finish,error:fail}})(window),(function(window2){"use strict";function data(){return window2.aksrtData||window2.aksrt||{}}function createIdempotencyKey(){if(window2.crypto&&typeof window2.crypto.randomUUID=="function")return window2.crypto.randomUUID();if(!window2.crypto||typeof window2.crypto.getRandomValues!="function")throw new Error("当前浏览器无法生成安全的操作标识");var bytes=new Uint8Array(16);window2.crypto.getRandomValues(bytes),bytes[6]=bytes[6]&15|64,bytes[8]=bytes[8]&63|128;var hex=Array.prototype.map.call(bytes,function(value){return value.toString(16).padStart(2,"0")}).join("");return hex.slice(0,8)+"-"+hex.slice(8,12)+"-"+hex.slice(12,16)+"-"+hex.slice(16,20)+"-"+hex.slice(20)}function restBase(){var config=data(),raw=config.restUrl||config.apiUrl||config.rest_url||"",siteUrl=config.siteUrl||config.homeUrl||window2.location.origin+"/";return window2.location.protocol==="https:"&&siteUrl.substring(0,5)==="http:"&&(siteUrl="https:"+siteUrl.substring(5)),raw?String(raw).replace(/\/$/,""):String(siteUrl).replace(/\/$/,"")+"/index.php?rest_route=/aksrt/v1"}function appendQuery(url2,query){if(!query)return url2;var parts=[];return typeof query=="string"?parts=query.replace(/^\?/,"").split("&").filter(Boolean):typeof query=="object"&&Object.keys(query).forEach(function(key){query[key]===void 0||query[key]===null||parts.push(encodeURIComponent(key)+"="+encodeURIComponent(String(query[key])))}),parts.length?url2+(url2.indexOf("?")>=0?"&":"?")+parts.join("&"):url2}function url(path,query){path=String(path||"");var inlineQuery="",queryIndex=path.indexOf("?");if(queryIndex>=0&&(inlineQuery=path.slice(queryIndex+1),path=path.slice(0,queryIndex)),/^https?:\/\//i.test(path))return appendQuery(path,query||inlineQuery);path.charAt(0)!=="/"&&(path="/"+path);var base=restBase(),result=(base.indexOf("rest_route=")>=0,base+path);return appendQuery(result,query||inlineQuery)}function headers(options){var config=data(),source=options&&options.headers||{},result={},nonce=config.restNonce||config.nonce||"";return Object.keys(source).forEach(function(key){result[key]=source[key]}),result.Accept||(result.Accept="application/json, text/html;q=0.9, */*;q=0.8"),nonce&&!result["X-WP-Nonce"]&&(result["X-WP-Nonce"]=nonce),options&&options.body!==void 0&&options.body!==null&&!(window2.FormData&&options.body instanceof window2.FormData)&&!result["Content-Type"]&Line truncated
|
||||
(function($,window2,document2){"use strict";function closeNotyf($element){$element.addClass("notyn-out"),window2.setTimeout(function(){$element.remove()},1e3)}function notyf2(message,type,time,id){var $body=jQuery(document2.body);jQuery(".notyn").length||$body.append('<div class="notyn"></div>'),type=type||"success",type==="error"&&(type="danger"),time=time||5e3,time=time<100?time*1e3:time;var idAttribute=id?' id="'+id+'"':"",$notification=jQuery('<div class="noty1"'+idAttribute+'><div class="notyf '+type+'">'+message+"</div></div>"),shouldClose=!id;id&&jQuery("#"+id).length?(jQuery("#"+id).find(".notyf").removeClass().addClass("notyf "+type).html(message),$notification=jQuery("#"+id),shouldClose=!0):jQuery(".notyn").append($notification),shouldClose&&window2.setTimeout(function(){closeNotyf($notification)},time)}jQuery(document2.body).on("click",".noty1",function(){closeNotyf(jQuery(this))}),window2.notyf=notyf2})(jQuery,window,document),(function(window2){"use strict";var allowedKinds={identity:!0,badges:!0,orders:!0,vip:!0},allowedEvents={click:!0,shell:!0,"first-content":!0,ready:!0,"action-start":!0,"action-end":!0,unauthorized:!0,error:!0},sessions=Object.create(null),sequence=0,maxSessions=100;function normalize(value,fallback){var normalized=String(value||fallback||"").toLowerCase().replace(/[^a-z0-9-]/g,"");return normalized||fallback}function now(){return window2.performance&&typeof window2.performance.now=="function"?window2.performance.now():0}function markName(session,event){return"aksrt-modal-"+session.kind+"-"+session.id+"-"+event}function emit(session,event){if(!(!window2.performance||typeof window2.performance.mark!="function")){var name=markName(session,event);if(window2.performance.mark(name),session.marks[event]=name,typeof window2.performance.measure=="function"&&session.marks.click&&event!=="click")try{window2.performance.measure("aksrt-modal-"+session.kind+"-"+session.id+"-click-to-"+event,session.marks.click,name)}catch{}}}function start(kind){var safeKind=normalize(kind,"unknown");allowedKinds[safeKind]||(safeKind="unknown"),sequence+=1;var id=String(sequence),session={id,kind:safeKind,startedAt:now(),marks:Object.create(null)};sessions[id]=session,emit(session,"click");for(var ids=Object.keys(sessions);ids.length>maxSessions;)delete sessions[ids.shift()];return id}function mark(id,event){var session=sessions[String(id||"")],safeEvent=normalize(event,"error");!session||!allowedEvents[safeEvent]||emit(session,safeEvent)}function finish(id){mark(id,"ready")}function fail(id){mark(id,"error")}window2.AksrtModalTelemetry={start,mark,finish,error:fail}})(window),(function(window2){"use strict";function data(){return window2.aksrtData||window2.aksrt||{}}function createIdempotencyKey(){if(window2.crypto&&typeof window2.crypto.randomUUID=="function")return window2.crypto.randomUUID();if(!window2.crypto||typeof window2.crypto.getRandomValues!="function")throw new Error("当前浏览器无法生成安全的操作标识");var bytes=new Uint8Array(16);window2.crypto.getRandomValues(bytes),bytes[6]=bytes[6]&15|64,bytes[8]=bytes[8]&63|128;var hex=Array.prototype.map.call(bytes,function(value){return value.toString(16).padStart(2,"0")}).join("");return hex.slice(0,8)+"-"+hex.slice(8,12)+"-"+hex.slice(12,16)+"-"+hex.slice(16,20)+"-"+hex.slice(20)}function restBase(){var config=data(),raw=config.restUrl||config.apiUrl||config.rest_url||"",siteUrl=config.siteUrl||config.homeUrl||window2.location.origin+"/";return window2.location.protocol==="https:"&&siteUrl.substring(0,5)==="http:"&&(siteUrl="https:"+siteUrl.substring(5)),raw?String(raw).replace(/\/$/,""):String(siteUrl).replace(/\/$/,"")+"/index.php?rest_route=/aksrt/v1"}function appendQuery(url2,query){if(!query)return url2;var parts=[];return typeof query=="string"?parts=query.replace(/^\?/,"").split("&").filter(Boolean):typeof query=="object"&&Object.keys(query).forEach(function(key){query[key]===void 0||query[key]===null||parts.push(encodeURIComponent(key)+"="+encodeURIComponent(String(query[key])))}),parts.length?url2+(url2.indexOf("?")>=0?"&":"?")+parts.join("&"):url2}function url(path,query){path=String(path||"");var inlineQuery="",queryIndex=path.indexOf("?");if(queryIndex>=0&&(inlineQuery=path.slice(queryIndex+1),path=path.slice(0,queryIndex)),/^https?:\/\//i.test(path))return appendQuery(path,query||inlineQuery);path.charAt(0)!=="/"&&(path="/"+path);var base=restBase(),result=(base.indexOf("rest_route=")>=0,base+path);return appendQuery(result,query||inlineQuery)}function headers(options){var config=data(),source=options&&options.headers||{},result={},nonce=config.restNonce||config.nonce||"";return Object.keys(source).forEach(function(key){result[key]=source[key]}),result.Accept||(result.Accept="application/json, text/html;q=0.9, */*;q=0.8"),nonce&&!result["X-WP-Nonce"]&&(result["X-WP-Nonce"]=nonce),options&&options.body!==void 0&&options.body!==null&&!(window2.FormData&&options.body instanceof window2.FormData)&&!result["Content-Type"]&Line truncated
|
||||
Reference in new issue
Block a user