fix(widgets): remove announcement outer card
This commit is contained in:
@@ -155,14 +155,32 @@
|
||||
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) {
|
||||
options = options || {};
|
||||
var replace = options.replace !== false;
|
||||
if (!container) return;
|
||||
|
||||
var itemsHtml = payload.itemsHtml || payload.html || "";
|
||||
var itemHost = findItemHost(container);
|
||||
if (replace) {
|
||||
container.querySelectorAll(".ajax-item").forEach(function (n) {
|
||||
itemHost.querySelectorAll(".ajax-item").forEach(function (n) {
|
||||
n.remove();
|
||||
});
|
||||
// If container itself holds only items, clear non-loader children.
|
||||
@@ -180,19 +198,19 @@
|
||||
});
|
||||
}
|
||||
if (itemsHtml) {
|
||||
var pag = container.querySelector(".ajax-pag");
|
||||
var pag = itemHost.querySelector(".ajax-pag");
|
||||
if (pag) {
|
||||
pag.insertAdjacentHTML("beforebegin", itemsHtml);
|
||||
} else {
|
||||
container.insertAdjacentHTML("beforeend", itemsHtml);
|
||||
itemHost.insertAdjacentHTML("beforeend", itemsHtml);
|
||||
}
|
||||
}
|
||||
} else if (itemsHtml) {
|
||||
var pag2 = container.querySelector(".ajax-pag");
|
||||
var pag2 = itemHost.querySelector(".ajax-pag");
|
||||
if (pag2) {
|
||||
pag2.insertAdjacentHTML("beforebegin", itemsHtml);
|
||||
} else {
|
||||
container.insertAdjacentHTML("beforeend", itemsHtml);
|
||||
itemHost.insertAdjacentHTML("beforeend", itemsHtml);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user