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
+21
-21
@@ -166,7 +166,7 @@
|
||||
}
|
||||
if (data.paginate_html) container.insertAdjacentHTML('beforeend', data.paginate_html);
|
||||
container.dataset.page = String(data.page || page);
|
||||
scan(container);
|
||||
window.AksrtFrontend.rehydrate(container, 'ajax');
|
||||
})
|
||||
.catch(function () { container.innerHTML = errorMarkup(); })
|
||||
.finally(function () {
|
||||
@@ -262,28 +262,28 @@
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
|
||||
function elementsIn(root, selector) {
|
||||
var scope = root || document;
|
||||
var elements = [];
|
||||
if (scope.matches && scope.matches(selector)) elements.push(scope);
|
||||
if (scope.querySelectorAll) {
|
||||
scope.querySelectorAll(selector).forEach(function (element) { elements.push(element); });
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
function scan(root) {
|
||||
var scope = root || document;
|
||||
scope.querySelectorAll('.aksrt-widget-video[data-video-url]').forEach(initVideo);
|
||||
scope.querySelectorAll('.aksrt-widget-toc').forEach(initToc);
|
||||
scope.querySelectorAll('.aksrt-widget-quote').forEach(initQuote);
|
||||
scope.querySelectorAll('[data-widget-items]').forEach(initItems);
|
||||
scope.querySelectorAll('.aksrt-widget-tabs, .widget-tab-post').forEach(initTabs);
|
||||
scope.querySelectorAll('.aksrt-faq').forEach(initFaq);
|
||||
scope.querySelectorAll('.aksrt-feature-intro').forEach(initFeatures);
|
||||
scope.querySelectorAll('[data-count-up]').forEach(initCount);
|
||||
if (typeof window.VanillaTilt !== 'undefined') scope.querySelectorAll('[data-aksrt-tilt]').forEach(function (el) { if (once(el, 'Tilt')) window.VanillaTilt.init(el); });
|
||||
elementsIn(scope, '.aksrt-widget-video[data-video-url]').forEach(initVideo);
|
||||
elementsIn(scope, '.aksrt-widget-toc').forEach(initToc);
|
||||
elementsIn(scope, '.aksrt-widget-quote').forEach(initQuote);
|
||||
elementsIn(scope, '[data-widget-items]').forEach(initItems);
|
||||
elementsIn(scope, '.aksrt-widget-tabs, .widget-tab-post').forEach(initTabs);
|
||||
elementsIn(scope, '.aksrt-faq').forEach(initFaq);
|
||||
elementsIn(scope, '.aksrt-feature-intro').forEach(initFeatures);
|
||||
elementsIn(scope, '[data-count-up]').forEach(initCount);
|
||||
if (typeof window.VanillaTilt !== 'undefined') elementsIn(scope, '[data-aksrt-tilt]').forEach(function (el) { if (once(el, 'Tilt')) window.VanillaTilt.init(el); });
|
||||
}
|
||||
|
||||
function ready() {
|
||||
scan(document);
|
||||
if ('MutationObserver' in window) {
|
||||
new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (node) { if (node.nodeType === 1) scan(node); }); });
|
||||
}).observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', ready);
|
||||
else ready();
|
||||
window.AksrtFrontend.register('aksrt-widgets', scan);
|
||||
})();
|
||||
Reference in new issue
Block a user