- 删除 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 通过。
127 lines
4.2 KiB
JavaScript
127 lines
4.2 KiB
JavaScript
/**
|
|
* AKSRT Input Expand
|
|
*
|
|
* Lightweight input field enhancements:
|
|
* - Textarea auto-resize on input
|
|
* - Character counter with limit display
|
|
* - Validation feedback (min/max length, required)
|
|
*
|
|
* No external dependencies — pure vanilla JS.
|
|
*
|
|
* Usage:
|
|
* <textarea data-aksrt-autoresize></textarea>
|
|
* <input data-aksrt-counter data-aksrt-maxlength="200">
|
|
* <input data-aksrt-validate data-aksrt-minlength="3" required>
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
(function () {
|
|
'use strict';
|
|
|
|
var STYLE_ID = 'aksrt-input-expand-style';
|
|
|
|
function injectStyle() {
|
|
if (document.getElementById(STYLE_ID)) return;
|
|
var style = document.createElement('style');
|
|
style.id = STYLE_ID;
|
|
style.textContent =
|
|
'.aksrt-counter{display:block;text-align:right;font-size:12px;color:#8a909c;margin-top:4px;transition:color 0.2s;}' +
|
|
'.aksrt-counter.is-over{color:#e74c3c;}' +
|
|
'.aksrt-counter.is-warn{color:#f39c12;}' +
|
|
'.aksrt-validate-msg{display:block;font-size:12px;margin-top:4px;color:#e74c3c;opacity:0;max-height:0;overflow:hidden;transition:all 0.2s;}' +
|
|
'.aksrt-validate-msg.is-visible{opacity:1;max-height:30px;}' +
|
|
'textarea[data-aksrt-autoresize]{overflow:hidden;resize:none;}';
|
|
document.head.appendChild(style);
|
|
}
|
|
|
|
// ── Auto-resize Textarea ──
|
|
|
|
function initAutoResize() {
|
|
var textareas = document.querySelectorAll('textarea[data-aksrt-autoresize]');
|
|
textareas.forEach(function (ta) {
|
|
function resize() {
|
|
ta.style.height = 'auto';
|
|
ta.style.height = ta.scrollHeight + 'px';
|
|
}
|
|
ta.addEventListener('input', resize);
|
|
// Initial resize
|
|
resize();
|
|
});
|
|
}
|
|
|
|
// ── Character Counter ──
|
|
|
|
function initCounters() {
|
|
var fields = document.querySelectorAll('[data-aksrt-counter]');
|
|
fields.forEach(function (field) {
|
|
var max = parseInt(field.getAttribute('data-aksrt-maxlength') || field.getAttribute('maxlength') || '0', 10);
|
|
var counter = document.createElement('span');
|
|
counter.className = 'aksrt-counter';
|
|
field.parentNode.insertBefore(counter, field.nextSibling);
|
|
|
|
function update() {
|
|
var len = (field.value || '').length;
|
|
if (max > 0) {
|
|
counter.textContent = len + ' / ' + max;
|
|
counter.classList.toggle('is-over', len > max);
|
|
counter.classList.toggle('is-warn', len > max * 0.9 && len <= max);
|
|
} else {
|
|
counter.textContent = len + ' 字';
|
|
counter.classList.remove('is-over', 'is-warn');
|
|
}
|
|
}
|
|
|
|
field.addEventListener('input', update);
|
|
update();
|
|
});
|
|
}
|
|
|
|
// ── Validation Feedback ──
|
|
|
|
function initValidation() {
|
|
var fields = document.querySelectorAll('[data-aksrt-validate]');
|
|
fields.forEach(function (field) {
|
|
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');
|
|
|
|
var msg = document.createElement('span');
|
|
msg.className = 'aksrt-validate-msg';
|
|
field.parentNode.insertBefore(msg, field.nextSibling);
|
|
|
|
function validate() {
|
|
var val = (field.value || '').trim();
|
|
var error = '';
|
|
|
|
if (required && val === '') {
|
|
error = '此项为必填';
|
|
} else if (minLen > 0 && val.length > 0 && val.length < minLen) {
|
|
error = '至少需要 ' + minLen + ' 个字符';
|
|
} else if (maxLen > 0 && val.length > maxLen) {
|
|
error = '不能超过 ' + maxLen + ' 个字符';
|
|
}
|
|
|
|
msg.textContent = error;
|
|
msg.classList.toggle('is-visible', error !== '');
|
|
field.classList.toggle('is-invalid', error !== '');
|
|
field.classList.toggle('is-valid', error === '' && val !== '');
|
|
}
|
|
|
|
field.addEventListener('input', validate);
|
|
field.addEventListener('blur', validate);
|
|
});
|
|
}
|
|
|
|
// ── Main Init ──
|
|
|
|
function init() {
|
|
injectStyle();
|
|
initAutoResize();
|
|
initCounters();
|
|
initValidation();
|
|
}
|
|
|
|
jQuery(document).off('auto_fun.aksrt-input-expand').on('auto_fun.aksrt-input-expand', function () { init(document); });
|
|
})();
|