fix(widgets): remove announcement outer card

This commit is contained in:
kate522 committed 2026-08-16 15:49:12 +08:00
1 parent 054d057fc6
commit 22c0c9df9c
1 file changed
+23 -5
+23 -5
View File
@@ -155,14 +155,32 @@
if (next) old.replaceWith(next); if (next) old.replaceWith(next);
} }
// Some widgets keep the rendered post grid inside an outer ajaxpager that
// also owns pagination/loading controls. Preserve that grid when replacing
// or appending AJAX items instead of flattening cards into the outer panel.
function findItemHost(container) {
if (!container || !container.children) return container;
for (var i = 0; i < container.children.length; i++) {
var child = container.children[i];
if (
child.matches &&
child.matches(".posts-row.post-grid, .aksrt-home-widget__post-grid")
) {
return child;
}
}
return container;
}
function inject(container, payload, options) { function inject(container, payload, options) {
options = options || {}; options = options || {};
var replace = options.replace !== false; var replace = options.replace !== false;
if (!container) return; if (!container) return;
var itemsHtml = payload.itemsHtml || payload.html || ""; var itemsHtml = payload.itemsHtml || payload.html || "";
var itemHost = findItemHost(container);
if (replace) { if (replace) {
container.querySelectorAll(".ajax-item").forEach(function (n) { itemHost.querySelectorAll(".ajax-item").forEach(function (n) {
n.remove(); n.remove();
}); });
// If container itself holds only items, clear non-loader children. // If container itself holds only items, clear non-loader children.
@@ -180,19 +198,19 @@
}); });
} }
if (itemsHtml) { if (itemsHtml) {
var pag = container.querySelector(".ajax-pag"); var pag = itemHost.querySelector(".ajax-pag");
if (pag) { if (pag) {
pag.insertAdjacentHTML("beforebegin", itemsHtml); pag.insertAdjacentHTML("beforebegin", itemsHtml);
} else { } else {
container.insertAdjacentHTML("beforeend", itemsHtml); itemHost.insertAdjacentHTML("beforeend", itemsHtml);
} }
} }
} else if (itemsHtml) { } else if (itemsHtml) {
var pag2 = container.querySelector(".ajax-pag"); var pag2 = itemHost.querySelector(".ajax-pag");
if (pag2) { if (pag2) {
pag2.insertAdjacentHTML("beforebegin", itemsHtml); pag2.insertAdjacentHTML("beforebegin", itemsHtml);
} else { } else {
container.insertAdjacentHTML("beforeend", itemsHtml); itemHost.insertAdjacentHTML("beforeend", itemsHtml);
} }
} }