- 删除 AksrtFrontend registry/rehydrate 双路架构及 build/public.js 拼包入口,
前台唯一初始路径为 PHP 本地栈(jQuery 1.9.1 → Bootstrap 3.4.1)
→ loader_js(_win/aksrtData 唯一注入)→ tbquire(['main']) → runtime/main.min.js
- window.auto_fun = debounce(z_auto_fun, 100) 为唯一重扫入口;所有模块改为
执行一次 + off/on('auto_fun.aksrt-*') 命名空间重扫,data/class 标记幂等
- 局部更新协议统一:HTML 注入 → post_ajax.ed → auto_fun();
远程 modal → loaded.bs.modal → auto_fun();JSON 成功 → zib_ajax.success
- 灯箱恢复 Miniimgbox/imgbox 唯一 owner(imgbox-container、a[data-imgbox]、
imgbox_data),删除 AksrtLightbox/data-aksrt-lightbox 第二实现及 CSS/overlay,
_win.imgbox* 重新接上 post-display 设置
- 死代码清理:runtime 下 11 组被自有实现替代的旧模块副本、无消费 vendored 库、
顶层 grade.min.js、revenue.js、无调用方的 aksrt_get_win_runtime_config(),
以及 loader 中 16 条死 mapping
- PHP 入队改为本地栈 + loader_js,routed/widget/submit 依赖统一换绑;
用户卡片发布按钮恢复 nav_user_newposts_btn 设置门控
- 测试对齐:新增 frontend-lifecycle-contract,重写 navigation/lazyload/toast/
auth-source/comment/page-display/post-visual 等断言为目标架构契约
验证:node --test widget-system+navigation 223 通过 0 失败;
构建脚本重建 main/imgbox min 与 CSS bundles;改动 PHP php -l、JS node --check
全部通过;git diff --check 干净;credits 重入 harness 通过。
128 lines
4.5 KiB
JavaScript
128 lines
4.5 KiB
JavaScript
/**
|
|
* On-site wallet tipping modal.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
;(function () {
|
|
'use strict';
|
|
|
|
var cfg = window.aksrtData || {};
|
|
|
|
function initReward() {
|
|
var activeTrigger = null;
|
|
|
|
function operationKey(modal) {
|
|
if (!modal.dataset.aksrtOperationKey) {
|
|
modal.dataset.aksrtOperationKey = window.AksrtRequest.createIdempotencyKey();
|
|
}
|
|
return modal.dataset.aksrtOperationKey;
|
|
}
|
|
|
|
function closeAll() {
|
|
document.querySelectorAll('.reward-modal.is-open').forEach(function (modal) {
|
|
modal.classList.remove('is-open');
|
|
modal.setAttribute('aria-hidden', 'true');
|
|
});
|
|
document.body.style.overflow = '';
|
|
if (activeTrigger) activeTrigger.focus();
|
|
activeTrigger = null;
|
|
}
|
|
|
|
function open(trigger) {
|
|
var userId = trigger.getAttribute('data-user-id') || '';
|
|
var modal = document.getElementById('reward-modal-' + userId);
|
|
if (!modal) return;
|
|
closeAll();
|
|
activeTrigger = trigger;
|
|
modal.dataset.postId = trigger.getAttribute('data-post-id') || modal.dataset.postId || '0';
|
|
modal.classList.add('is-open');
|
|
modal.setAttribute('aria-hidden', 'false');
|
|
document.body.style.overflow = 'hidden';
|
|
var first = modal.querySelector('[data-reward-amount], [data-aksrt-reward-custom]');
|
|
if (first) first.focus();
|
|
}
|
|
|
|
document.addEventListener('click', function (event) {
|
|
var opener = event.target.closest('[data-aksrt-reward-open]');
|
|
if (opener) {
|
|
event.preventDefault();
|
|
open(opener);
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest('[data-aksrt-reward-close]')) {
|
|
event.preventDefault();
|
|
closeAll();
|
|
return;
|
|
}
|
|
|
|
var amountButton = event.target.closest('[data-reward-amount]');
|
|
if (amountButton) {
|
|
var modal = amountButton.closest('.reward-modal');
|
|
delete modal.dataset.aksrtOperationKey;
|
|
modal.querySelectorAll('[data-reward-amount]').forEach(function (button) {
|
|
button.classList.toggle('is-active', button === amountButton);
|
|
});
|
|
var custom = modal.querySelector('[data-aksrt-reward-custom]');
|
|
if (custom) custom.value = '';
|
|
return;
|
|
}
|
|
|
|
var submit = event.target.closest('[data-aksrt-reward-submit]');
|
|
if (!submit || submit.disabled) return;
|
|
var tipModal = submit.closest('.reward-modal');
|
|
var message = tipModal.querySelector('[data-aksrt-reward-message]');
|
|
var customInput = tipModal.querySelector('[data-aksrt-reward-custom]');
|
|
var selected = tipModal.querySelector('[data-reward-amount].is-active');
|
|
var amount = customInput && customInput.value ? customInput.value : (selected ? selected.dataset.rewardAmount : '');
|
|
if (customInput && customInput.dataset.aksrtIdempotencyBound !== '1') {
|
|
customInput.dataset.aksrtIdempotencyBound = '1';
|
|
customInput.addEventListener('input', function () { delete tipModal.dataset.aksrtOperationKey; });
|
|
}
|
|
|
|
submit.disabled = true;
|
|
submit.textContent = '赞赏中…';
|
|
if (message) message.textContent = '';
|
|
|
|
var body = new URLSearchParams();
|
|
body.set('action', 'aksrt_submit_tip');
|
|
body.set('nonce', cfg.nonce || '');
|
|
body.set('recipient_id', tipModal.dataset.userId || '');
|
|
body.set('post_id', tipModal.dataset.postId || '0');
|
|
body.set('amount', amount);
|
|
|
|
fetch(cfg.ajaxUrl || '/wp-admin/admin-ajax.php', {
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
'Idempotency-Key': operationKey(tipModal)
|
|
},
|
|
body: body.toString()
|
|
}).then(function (response) {
|
|
return response.json();
|
|
}).then(function (response) {
|
|
var text = response && response.data && response.data.message ? response.data.message : '赞赏失败';
|
|
if (response && response.success) {
|
|
delete tipModal.dataset.aksrtOperationKey;
|
|
if (message) message.textContent = text;
|
|
setTimeout(closeAll, 900);
|
|
} else if (message) {
|
|
message.textContent = text;
|
|
}
|
|
}).catch(function () {
|
|
if (message) message.textContent = '网络错误,请稍后重试';
|
|
}).finally(function () {
|
|
submit.disabled = false;
|
|
submit.textContent = '余额赞赏';
|
|
});
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape') closeAll();
|
|
});
|
|
}
|
|
|
|
jQuery(document).off('auto_fun.aksrt-reward').on('auto_fun.aksrt-reward', initReward);
|
|
})();
|