feat(runtime): 全站前端脚本统一接入 AksrtFrontend 全局 DOM 生命周期
- rehydrate.js 新增 boot()/aksrt:ready 事件,支持 boot 后晚注册立即以 init 触发 - aksrt-runtime.js 初始加载改走 AksrtFrontend.boot,tooltip/倒计时注册为组件 - 约 30 个前端脚本(首页、评论、支付、路由、页面叶子、widgets) 从直接 DOMContentLoaded 迁移为 AksrtFrontend.register,并加幂等标记 - section-navs 依赖改为 aksrt-runtime,保证注册时序 - 清理死代码:删除孤儿 loader.js/main.js 及 runtime/page-navs 遗留副本 - loader.js 移除已迁移模块的 tbquire 路径映射,main.js 相应瘦身 - build-public-assets.mjs 增加 runtime/main.min.js 自动压缩步骤 - 新增 4 个契约测试(homepage-dom/rehydrate-runtime/global-dom-init/ public-bundle-parity),3 个既有 harness 适配注册表初始化方式
This commit is contained in:
1 parent
5984d4e42d
commit
1f4a39d8f8
60 files changed
+1810
-1742
No files matched your search
+19
-67
@@ -269,64 +269,7 @@
|
||||
});
|
||||
}, true);
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// §10.10a — 拦截 vendor 评论脚本 & 解绑 vendor ajax 委托
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// vendor 链路:loader.js(tbquire,改造版 RequireJS)→ main.min.js 检测到
|
||||
// #commentform/#postcomments 即 tbquire(["comment"]) 懒加载 comment.min.js;
|
||||
// 检测到 .dropdown-code/.dropdown-image 即 tbquire(["input-expand"])。
|
||||
// AKSRT 自有评论脚本(comments/comment-tools/comment-fixed-input/
|
||||
// comment-move-form/comment-ajax)已承担全部行为,vendor comment.min.js 的
|
||||
// 7 条 body 委托会双路触发(提交 legacy action=submit_comment 无处理器,
|
||||
// 即控制台「ajax请求错误」400 "0" 的来源;回复/排序/分页同理);
|
||||
// vendor input-expand.min.js(表情/快捷回复旧链路,源文件已删除)同理不再下载。
|
||||
//
|
||||
// 双层防御:
|
||||
// 1) tbfine 预注册空 'comment'/'input-expand' 模块 → tbquire 不再下载;
|
||||
// 2) 若模块抢在注册前加载,退化为对 7 条委托做幂等 .off。
|
||||
function stubVendorCommentModule() {
|
||||
if (!(window.tbfine && window.tbquire && window.tbquire.defined)) return false;
|
||||
try {
|
||||
['comment', 'input-expand'].forEach(function (name) {
|
||||
if (!window.tbquire.defined(name)) {
|
||||
window.tbfine(name, [], function () { return {}; });
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// main.min.js 的 body 级 legacy 委托同理摘除(vendor 只保留 UI 行为)。
|
||||
function unbindVendorAjaxDelegates() {
|
||||
stubVendorCommentModule();
|
||||
if (!window.jQuery) return;
|
||||
try {
|
||||
var $body = jQuery('body');
|
||||
$body.off('click', '[data-action]');
|
||||
$body.off('click', '[ajax-action]');
|
||||
$body.off('click', '.wp-ajax-submit,[zibajax="submit"]');
|
||||
$body.off('click', '.initiate-checkin');
|
||||
$body.off('click', '.oauth-untying');
|
||||
// comment.min.js 的 7 条委托(legacy/js/comment.js 原始选择器)
|
||||
$body.off('click', '[fixed-input]');
|
||||
$body.off('click', '.commentlist .pagenav a,.comment-orderby');
|
||||
$body.off('click', '.comment-edit-link,.comment-reply-link');
|
||||
$body.off('keydown', '#comment');
|
||||
$body.off('click', '.comment-trash-link');
|
||||
$body.off('click', '.comment-approve-link');
|
||||
$body.off('click', '#commentform #submit');
|
||||
} catch (e) { /* vendor 运行时未就绪时忽略 */ }
|
||||
}
|
||||
var unbindVendorAjaxLoop = function () {
|
||||
unbindVendorAjaxDelegates();
|
||||
if (++unbindVendorAjaxLoop.tries >= 50) return; // ~10s @200ms 覆盖异步加载窗口
|
||||
setTimeout(unbindVendorAjaxLoop, 200);
|
||||
};
|
||||
unbindVendorAjaxLoop.tries = 0;
|
||||
unbindVendorAjaxLoop();
|
||||
|
||||
// Vendor modules are no longer dynamically loaded by the canonical frontend path.
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// §10.11 — [data-action] / [ajax-action] universal buttons
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
@@ -533,13 +476,7 @@
|
||||
// §10.11 — auto_fun: extended rehydration coverage
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
|
||||
aksrt.autoFun = function (root) {
|
||||
root = root || document;
|
||||
if (window.AksrtFrontend) {
|
||||
AksrtFrontend.rehydrate(root, 'ajax');
|
||||
}
|
||||
|
||||
// Tooltips
|
||||
function initTooltips(root) {
|
||||
root.querySelectorAll('[data-tooltip]').forEach(function (el) {
|
||||
if (el.dataset.tooltipBound) return;
|
||||
el.dataset.tooltipBound = '1';
|
||||
@@ -557,8 +494,9 @@
|
||||
if (el._aksrtTooltip) { el._aksrtTooltip.remove(); el._aksrtTooltip = null; }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Countdowns
|
||||
function initCountdowns(root) {
|
||||
root.querySelectorAll('[data-countdown]').forEach(function (el) {
|
||||
if (el.dataset.countdownBound) return;
|
||||
el.dataset.countdownBound = '1';
|
||||
@@ -572,6 +510,20 @@
|
||||
el.textContent = (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s;
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
AksrtFrontend.register('aksrt-tooltips', initTooltips);
|
||||
AksrtFrontend.register('aksrt-countdowns', initCountdowns);
|
||||
|
||||
aksrt.autoFun = function (root, reason) {
|
||||
root = root || document;
|
||||
reason = reason || 'ajax';
|
||||
if (!window.AksrtFrontend) return;
|
||||
if (reason === 'init' && typeof AksrtFrontend.boot === 'function') {
|
||||
AksrtFrontend.boot(root);
|
||||
} else {
|
||||
AksrtFrontend.rehydrate(root, reason);
|
||||
}
|
||||
};
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
@@ -590,7 +542,7 @@
|
||||
// ── DOMContentLoaded ──
|
||||
|
||||
function initRuntime() {
|
||||
aksrt.autoFun(document);
|
||||
aksrt.autoFun(document, 'init');
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
|
||||
Reference in new issue
Block a user