- assets/vendor 全量迁移: fontawesome5→assets/fontawesome5, css→assets/css, js→assets/js/runtime(避开 14 个同名自有文件), img 合并去重→assets/img, fonts→assets/fonts; 删除 assets/vendor - libs 五个与 widgets/third-party 字节相同的库不重复入库, loader paths 改指向 - 运行时切换: _win.uri=assets 根, loader baseUrl=/js/runtime, enlighter 注入 路径同步; PHP 7 个引用文件切换并改名 $zibll_*→$runtime_* - 去品牌: Qinver 头注释/品牌 console.log/演示链接清除, 默认文案中性化 - 功能标识符改名: zib__→aksrt__, zib_ajax→aksrt_ajax, window.zib→ window.aksrtLegacy, zibllblock/*→aksrtblock/*, .zib-widget→.aksrt-panel, .zib-slider→.aksrt-slider, zib_menu_options meta 键等 - 自有 CSS 改名: legacy-utilities/compat-vars/footer shell - admin SPA 重建; 契约测试同步(路径/断言/文件更名) - 例外保留: tests/visual 对照环境与 fixtures 前缀(外部 Zibll 产品引用) 验证: php -l 133 个改动文件通过; runtime 86 个 JS node --check 通过; 契约测试 68/70(2 个失败经 stash 对照确认为存量问题)
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
/**
|
|
* Server-rendered user medal actions.
|
|
*
|
|
* Mirrors the legacy admin-ajax lifecycle: mutate, close the dialog, then
|
|
* reload the page so every server-rendered medal surface is in sync.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
(function (window, document) {
|
|
'use strict';
|
|
|
|
var actions = {
|
|
wear: 'aksrt_user_medal_wear',
|
|
grant: 'aksrt_user_medal_manually_add',
|
|
revoke: 'aksrt_user_medal_manually_remove'
|
|
};
|
|
|
|
function notice(message, type) {
|
|
if (typeof window.notyf === 'function') window.notyf(message, type);
|
|
}
|
|
|
|
document.addEventListener('click', function (event) {
|
|
var button = event.target.closest('[data-aksrt-badge-action]');
|
|
if (!button || button.classList.contains('is-loading')) return;
|
|
|
|
var type = button.getAttribute('data-aksrt-badge-action') || '';
|
|
var action = actions[type];
|
|
var slug = button.getAttribute('data-slug') || '';
|
|
var nonce = (window.aksrtData && window.aksrtData.nonce) || '';
|
|
if (!action || !slug || !nonce) return;
|
|
|
|
event.preventDefault();
|
|
button.classList.add('is-loading');
|
|
button.setAttribute('aria-busy', 'true');
|
|
|
|
var form = new URLSearchParams();
|
|
form.set('action', action);
|
|
form.set('nonce', nonce);
|
|
form.set('slug', slug);
|
|
if (type !== 'wear') form.set('id', button.getAttribute('data-user-id') || '0');
|
|
|
|
window.fetch((window.aksrtData && window.aksrtData.ajaxUrl) || '/wp-admin/admin-ajax.php', {
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
|
body: form.toString()
|
|
}).then(function (response) {
|
|
return response.json();
|
|
}).then(function (json) {
|
|
if (!json || !json.success) throw new Error((json && json.data && json.data.message) || '操作失败');
|
|
notice((json.data && json.data.message) || '操作成功', 'success');
|
|
window.AksrtModalRuntime.close('badge-action');
|
|
window.setTimeout(function () { window.location.reload(); }, 120);
|
|
}).catch(function (error) {
|
|
button.classList.remove('is-loading');
|
|
button.removeAttribute('aria-busy');
|
|
notice(error.message || '网络错误', 'danger');
|
|
});
|
|
});
|
|
})(window, document);
|