- 删除 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 通过。
174 lines
5.0 KiB
JavaScript
174 lines
5.0 KiB
JavaScript
/**
|
|
* AKSRT Waterfall — 瀑布流/异步列表
|
|
*
|
|
* 提供纯 CSS column-based 瀑布流布局和无限滚动加载能力。
|
|
* 无外部依赖。
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
/**
|
|
* Initialize waterfall layout on a container.
|
|
*
|
|
* @param {HTMLElement} container - The container element
|
|
* @param {Object} options
|
|
* @param {number} options.columns - Number of columns (default: auto from CSS)
|
|
* @param {string} options.itemSelector - Child item selector (default: '.waterfall-item')
|
|
* @param {number} options.gap - Gap between items in px (default: 16)
|
|
*/
|
|
function Waterfall(container, options) {
|
|
if (!container) return;
|
|
|
|
this.container = container;
|
|
this.options = Object.assign({
|
|
columns: 0,
|
|
itemSelector: '.waterfall-item',
|
|
gap: 16,
|
|
}, options || {});
|
|
|
|
this._resizeHandler = this.layout.bind(this);
|
|
window.addEventListener('resize', this._resizeHandler);
|
|
this.layout();
|
|
}
|
|
|
|
Waterfall.prototype.layout = function () {
|
|
var items = this.container.querySelectorAll(this.options.itemSelector);
|
|
if (items.length === 0) return;
|
|
|
|
var cols = this.options.columns;
|
|
if (cols <= 0) {
|
|
var containerWidth = this.container.offsetWidth;
|
|
cols = Math.max(1, Math.floor(containerWidth / 280));
|
|
}
|
|
|
|
var gap = this.options.gap;
|
|
var colWidth = (this.container.offsetWidth - gap * (cols - 1)) / cols;
|
|
var colHeights = new Array(cols).fill(0);
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
var item = items[i];
|
|
item.style.width = colWidth + 'px';
|
|
item.style.position = 'absolute';
|
|
|
|
// Find shortest column
|
|
var minHeight = Infinity;
|
|
var minCol = 0;
|
|
for (var c = 0; c < cols; c++) {
|
|
if (colHeights[c] < minHeight) {
|
|
minHeight = colHeights[c];
|
|
minCol = c;
|
|
}
|
|
}
|
|
|
|
item.style.left = (minCol * (colWidth + gap)) + 'px';
|
|
item.style.top = colHeights[minCol] + 'px';
|
|
|
|
colHeights[minCol] += item.offsetHeight + gap;
|
|
}
|
|
|
|
// Set container height to tallest column
|
|
var maxHeight = Math.max.apply(null, colHeights);
|
|
this.container.style.height = maxHeight + 'px';
|
|
this.container.style.position = 'relative';
|
|
};
|
|
|
|
Waterfall.prototype.relayout = function () {
|
|
this.layout();
|
|
};
|
|
|
|
Waterfall.prototype.destroy = function () {
|
|
window.removeEventListener('resize', this._resizeHandler);
|
|
};
|
|
|
|
/**
|
|
* Infinite scroll loader.
|
|
*
|
|
* @param {Object} options
|
|
* @param {string} options.containerSelector - List container selector
|
|
* @param {string} options.loadMoreSelector - Load-more button selector
|
|
* @param {Function} options.loadMore - Async function that loads more items
|
|
* @param {number} options.threshold - Distance from bottom to trigger (default: 200)
|
|
*/
|
|
function InfiniteScroll(options) {
|
|
this.options = Object.assign({
|
|
containerSelector: '.aksrt-infinite-list',
|
|
loadMoreSelector: '.aksrt-load-more',
|
|
loadMore: null,
|
|
threshold: 200,
|
|
}, options || {});
|
|
|
|
this.loading = false;
|
|
this.hasMore = true;
|
|
this._scrollHandler = this._check.bind(this);
|
|
|
|
window.addEventListener('scroll', this._scrollHandler);
|
|
this._check();
|
|
}
|
|
|
|
InfiniteScroll.prototype._check = function () {
|
|
if (this.loading || !this.hasMore) return;
|
|
|
|
var loadMoreBtn = document.querySelector(this.options.loadMoreSelector);
|
|
if (!loadMoreBtn) {
|
|
this.hasMore = false;
|
|
return;
|
|
}
|
|
|
|
var rect = loadMoreBtn.getBoundingClientRect();
|
|
if (rect.top < window.innerHeight + this.options.threshold) {
|
|
this._load();
|
|
}
|
|
};
|
|
|
|
InfiniteScroll.prototype._load = function () {
|
|
if (!this.options.loadMore) return;
|
|
|
|
this.loading = true;
|
|
var self = this;
|
|
|
|
this.options.loadMore().then(function (hasMore) {
|
|
self.hasMore = hasMore !== false;
|
|
self.loading = false;
|
|
if (self.hasMore) {
|
|
self._check();
|
|
}
|
|
}).catch(function () {
|
|
self.loading = false;
|
|
});
|
|
};
|
|
|
|
InfiniteScroll.prototype.destroy = function () {
|
|
window.removeEventListener('scroll', this._scrollHandler);
|
|
};
|
|
|
|
// Auto-init
|
|
var waterfallInstances = [];
|
|
|
|
function relayoutAll() {
|
|
waterfallInstances.forEach(function (instance) {
|
|
if (instance && typeof instance.relayout === 'function') {
|
|
instance.relayout();
|
|
}
|
|
});
|
|
}
|
|
|
|
function autoInit() {
|
|
document.querySelectorAll('[data-aksrt-waterfall]:not([data-aksrt-waterfall-bound])').forEach(function (el) {
|
|
el.dataset.aksrtWaterfallBound = '1';
|
|
var cols = parseInt(el.dataset.aksrtWaterfallColumns) || 0;
|
|
var gap = parseInt(el.dataset.aksrtWaterfallGap) || 16;
|
|
waterfallInstances.push(new Waterfall(el, { columns: cols, gap: gap }));
|
|
});
|
|
relayoutAll();
|
|
}
|
|
|
|
jQuery(document).off('auto_fun.aksrt-waterfall').on('auto_fun.aksrt-waterfall', autoInit);
|
|
jQuery(document).off('lazyloaded.aksrt-waterfall').on('lazyloaded.aksrt-waterfall', relayoutAll);
|
|
|
|
// Export to global
|
|
window.AksrtWaterfall = Waterfall;
|
|
window.AksrtInfiniteScroll = InfiniteScroll;
|
|
})();
|