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
+24
-15
@@ -37,9 +37,17 @@
|
||||
|
||||
// ── Auto-resize Textarea ──
|
||||
|
||||
function initAutoResize() {
|
||||
var textareas = document.querySelectorAll('textarea[data-aksrt-autoresize]');
|
||||
function queryAll(root, selector) {
|
||||
var nodes = Array.prototype.slice.call(root.querySelectorAll(selector));
|
||||
if (root.nodeType === 1 && root.matches(selector)) nodes.unshift(root);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function initAutoResize(root) {
|
||||
var textareas = queryAll(root, 'textarea[data-aksrt-autoresize]');
|
||||
textareas.forEach(function (ta) {
|
||||
if (ta.dataset.aksrtAutoresizeBound === '1') return;
|
||||
ta.dataset.aksrtAutoresizeBound = '1';
|
||||
function resize() {
|
||||
ta.style.height = 'auto';
|
||||
ta.style.height = ta.scrollHeight + 'px';
|
||||
@@ -52,9 +60,11 @@
|
||||
|
||||
// ── Character Counter ──
|
||||
|
||||
function initCounters() {
|
||||
var fields = document.querySelectorAll('[data-aksrt-counter]');
|
||||
function initCounters(root) {
|
||||
var fields = queryAll(root, '[data-aksrt-counter]');
|
||||
fields.forEach(function (field) {
|
||||
if (field.dataset.aksrtCounterBound === '1') return;
|
||||
field.dataset.aksrtCounterBound = '1';
|
||||
var max = parseInt(field.getAttribute('data-aksrt-maxlength') || field.getAttribute('maxlength') || '0', 10);
|
||||
var counter = document.createElement('span');
|
||||
counter.className = 'aksrt-counter';
|
||||
@@ -79,9 +89,11 @@
|
||||
|
||||
// ── Validation Feedback ──
|
||||
|
||||
function initValidation() {
|
||||
var fields = document.querySelectorAll('[data-aksrt-validate]');
|
||||
function initValidation(root) {
|
||||
var fields = queryAll(root, '[data-aksrt-validate]');
|
||||
fields.forEach(function (field) {
|
||||
if (field.dataset.aksrtValidateBound === '1') return;
|
||||
field.dataset.aksrtValidateBound = '1';
|
||||
var minLen = parseInt(field.getAttribute('data-aksrt-minlength') || field.getAttribute('minlength') || '0', 10);
|
||||
var maxLen = parseInt(field.getAttribute('data-aksrt-maxlength') || field.getAttribute('maxlength') || '0', 10);
|
||||
var required = field.hasAttribute('required');
|
||||
@@ -115,16 +127,13 @@
|
||||
|
||||
// ── Main Init ──
|
||||
|
||||
function init() {
|
||||
function init(root) {
|
||||
root = root || document;
|
||||
injectStyle();
|
||||
initAutoResize();
|
||||
initCounters();
|
||||
initValidation();
|
||||
initAutoResize(root);
|
||||
initCounters(root);
|
||||
initValidation(root);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
window.AksrtFrontend.register('aksrt-input-expand', init);
|
||||
})();
|
||||
Reference in new issue
Block a user