fix(ajax): show the reference skeleton on every load-more surface
Clicking 加载更多 in the 多栏目文章 widget showed no skeleton at all — the
list simply stayed still until the response arrived, then the new cards
appeared. The homepage stream, archives and comments already had a working
skeleton; the widget's AJAX load goes through a different client and never
found its loader.
Root cause was DOM placement, not visibility: ContentRenderer emitted
.post_ajax_loader as a *sibling* of .widget-ajaxpager, while the widget REST
client resolves it with container.querySelector('.post_ajax_loader'). The
node existed but could never match, so .is-loading was never added and the
skeleton stayed display:none. Inactive tab panes had the same shape, and the
direct-load branch of ajaxpager() emitted no loader at all.
Changes, all following the reference theme's post_ajax() contract in
zibll/js/main.js (beforeSend anchors the loader to the end of the list;
success only hides it, never removes it):
- ContentRenderer: nest the loader inside .widget-ajaxpager for both the
direct-load and inactive-tab branches, and drop the sibling append.
- widgets/frontend.js: anchorLoader() moves the loader to the end of the
list before .ajax-pag on every request; appended cards are inserted before
it; a replace preserves the node instead of wiping it with innerHTML; a
fallback loader is created when the DOM has none; loadItems() now returns
its promise; drop the unreachable is-loading auto-load branch.
- Message centre, user-home panels and the search page switch from spinner /
opacity feedback to the same .posts-item-shaped skeleton, so all AJAX
surfaces share one loading contract.
- Remove the second, never-wired skeleton system (.aksrt-skeleton-* in
core-ui.css) and the dead spinner stylesheets/rules (skeleton.css,
ajax-spinner.css, .load-more__*, --skeleton-base/--skeleton-shine) plus the
unregistered assets/js/waterfall.js.
- Extend the widget, message-centre, user-home and asset-ledger contract
tests to pin the loader inside the container, the class-only visibility
switch, and the absence of the deleted dead code.
Verified: 470 node tests, 136 PHP widget assertions, admin-contract and
widget-system audits all green; rebuilt public assets after the CSS/JS
removals.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
271e7f0518
commit
cf4554e7c8
25 files changed
+330
-981
No files matched your search
@@ -109,16 +109,27 @@
|
||||
}
|
||||
|
||||
function loaderOf(container) {
|
||||
if (!container) return null;
|
||||
return container.querySelector('.post_ajax_loader');
|
||||
}
|
||||
|
||||
function fallbackLoader() {
|
||||
var text = (window.aksrtData && aksrtData.ajaxLoading) || '加载中...';
|
||||
var node = document.createElement('div');
|
||||
node.className = 'post_ajax_loader';
|
||||
node.setAttribute('role', 'status');
|
||||
node.innerHTML = '<div class="mb20"><div class="text-center muted-2-color mt20"><i class="loading mr10"></i>' + text + '</div></div>';
|
||||
return node;
|
||||
}
|
||||
|
||||
function setBusy(container, busy) {
|
||||
if (!container) return;
|
||||
if (busy) {
|
||||
container.dataset.loading = '1';
|
||||
container.setAttribute('aria-busy', 'true');
|
||||
var loader = loaderOf(container);
|
||||
// 骨架开关走 .is-loading 类(modal-runtime.css),不写 inline display。
|
||||
if (loader) loader.classList.add('is-loading');
|
||||
var loader = loaderOf(container) || container.appendChild(fallbackLoader());
|
||||
loader.classList.add('is-loading');
|
||||
} else {
|
||||
delete container.dataset.loading;
|
||||
container.setAttribute('aria-busy', 'false');
|
||||
@@ -127,6 +138,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 参考主题 post_ajax 的 beforeSend 语义:骨架每次请求都挪到列表末尾
|
||||
// (最后一个条目之后、分页控件之前),请求成功后只隐藏而不删除,
|
||||
// 下一轮翻页复用同一个节点。
|
||||
function anchorLoader(container) {
|
||||
var pag = container.querySelector(':scope > .ajax-pag');
|
||||
var loader = loaderOf(container);
|
||||
if (!loader) return null;
|
||||
if (pag) {
|
||||
pag.parentNode.insertBefore(loader, pag);
|
||||
} else {
|
||||
container.appendChild(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
function loadItems(container, page, append) {
|
||||
var owner = container.closest('[data-widget]') || container;
|
||||
var widget = owner.dataset.widget || container.dataset.widget;
|
||||
@@ -134,28 +160,49 @@
|
||||
var segment = container.dataset.segment || owner.dataset.segment || '';
|
||||
if (!widget || !instance || !config.restUrl || container.dataset.loading === '1') return;
|
||||
setBusy(container, true);
|
||||
fetch(itemsUrl(widget, instance, page, segment), { credentials: 'same-origin', headers: { Accept: 'application/json' } })
|
||||
anchorLoader(container);
|
||||
return fetch(itemsUrl(widget, instance, page, segment), { credentials: 'same-origin', headers: { Accept: 'application/json' } })
|
||||
.then(function (response) { if (!response.ok) throw new Error('items'); return response.json(); })
|
||||
.then(function (data) {
|
||||
var fragment = document.createElement('div');
|
||||
fragment.innerHTML = String(data.html || '');
|
||||
Array.prototype.slice.call(container.querySelectorAll(':scope > .ajax-pag')).forEach(function (node) { node.remove(); });
|
||||
if (append) {
|
||||
Array.prototype.slice.call(fragment.children).forEach(function (node) { container.appendChild(node); });
|
||||
// 追加方向为底部:新条目插到骨架之前,骨架始终贴住最后一张卡片。
|
||||
var anchor = loaderOf(container) || container.querySelector(':scope > .ajax-pag');
|
||||
Array.prototype.slice.call(fragment.children).forEach(function (node) {
|
||||
if (anchor && anchor.parentNode === container) {
|
||||
container.insertBefore(node, anchor);
|
||||
} else {
|
||||
container.appendChild(node);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
container.innerHTML = fragment.innerHTML;
|
||||
// 替换时保留骨架节点本身(参考主题 success 后只 hide() 不删除)。
|
||||
var loader = loaderOf(container);
|
||||
Array.prototype.slice.call(container.children).forEach(function (child) {
|
||||
if (child !== loader && !child.classList.contains('ajax-pag')) child.remove();
|
||||
});
|
||||
Array.prototype.slice.call(fragment.children).forEach(function (node) { container.appendChild(node); });
|
||||
}
|
||||
Array.prototype.slice.call(container.querySelectorAll(':scope > .ajax-pag')).forEach(function (node) { node.remove(); });
|
||||
if (data.paginate_html) container.insertAdjacentHTML('beforeend', data.paginate_html);
|
||||
container.dataset.page = String(data.page || page);
|
||||
anchorLoader(container);
|
||||
scan(container);
|
||||
})
|
||||
.catch(function () { container.innerHTML = errorMarkup(); })
|
||||
.catch(function () {
|
||||
var loader = loaderOf(container);
|
||||
if (loader && loader.parentNode === container) {
|
||||
loader.insertAdjacentHTML('beforebegin', errorMarkup());
|
||||
} else {
|
||||
container.insertAdjacentHTML('afterbegin', errorMarkup());
|
||||
}
|
||||
})
|
||||
.finally(function () { setBusy(container, false); });
|
||||
}
|
||||
|
||||
function initItems(container) {
|
||||
if (!once(container, 'Items')) return;
|
||||
if (container.classList.contains('is-loading')) loadItems(container, 1, false);
|
||||
container.addEventListener('click', function (event) {
|
||||
var retry = event.target.closest('[data-widget-retry]');
|
||||
var trigger = event.target.closest('[data-next-page]');
|
||||
|
||||
Reference in new issue
Block a user