Files
wordpress-theme-aksrt/assets/js/page-template.js
T
kate522 5fd7c212ed fix(runtime): 按参考主题硬切换为 loader/main/auto_fun 单一 DOM 生命周期
- 删除 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 通过。
2026-09-03 12:44:31 +08:00

96 lines
3.2 KiB
JavaScript

/**
* AKSRT Page Template
*
* Handles template-scoped content interactions: expandable article bodies
* and one-shot query cleanup banners.
*
* @package AKSRT
*/
(function () {
'use strict';
function initContentExpand() {
// legacy-style: inject .read-more inside .limit-height and expand on click.
document.querySelectorAll('.wp-posts-content.limit-height, .limit-height[data-nav]').forEach(function (content) {
if (content.dataset.aksrtExpandBound === '1') return;
content.dataset.aksrtExpandBound = '1';
var customMax = parseInt(content.getAttribute('data-maxheight') || content.dataset.maxheight || '0', 10);
// data-maxheight may be maxheight-80 (legacy) or absolute maxheight; prefer style max-height.
var styleMax = 0;
if (content.style && content.style.maxHeight) {
styleMax = parseInt(content.style.maxHeight, 10) || 0;
}
var limit = styleMax > 0 ? styleMax : (customMax > 0 ? customMax + 80 : 0);
if (!(limit > 0) && customMax > 0) {
limit = customMax;
}
if (!(limit > 0)) {
content.classList.remove('limit-height');
return;
}
if (content.scrollHeight <= limit + 40) {
content.classList.remove('limit-height');
content.style.maxHeight = '';
return;
}
content.classList.add('limit-height');
content.style.maxHeight = limit + 'px';
if (content.querySelector('.read-more')) return;
var wrap = document.createElement('div');
wrap.className = 'read-more';
var link = document.createElement('a');
link.href = 'javascript:;';
link.className = 'read-more-open';
link.innerHTML = '展开阅读全文<i class="fa ml10 fa-angle-down" aria-hidden="true"></i>';
wrap.appendChild(link);
content.appendChild(wrap);
link.addEventListener('click', function (event) {
event.preventDefault();
content.classList.remove('limit-height');
content.style.maxHeight = '';
wrap.remove();
});
});
// Compatibility: old external expand buttons.
document.addEventListener('click', function (event) {
var open = event.target.closest && event.target.closest('.read-more-open');
if (!open) return;
var limitBox = open.closest('.limit-height');
if (!limitBox) return;
event.preventDefault();
limitBox.classList.remove('limit-height');
limitBox.style.maxHeight = '';
var more = open.closest('.read-more');
if (more) more.remove();
});
}
function initFlashQueryCleanup() {
document.querySelectorAll('[data-aksrt-flash-query]').forEach(function (node) {
var queryKey = node.getAttribute('data-aksrt-flash-query');
if (!queryKey || !window.history || typeof window.history.replaceState !== 'function') return;
var url = new URL(window.location.href);
if (!url.searchParams.has(queryKey)) return;
url.searchParams.delete(queryKey);
window.history.replaceState({}, '', url.toString());
});
}
function init() {
initContentExpand();
initFlashQueryCleanup();
}
jQuery(document).off('auto_fun.aksrt-page-template').on('auto_fun.aksrt-page-template', function () { init(document); });
})();