Skip to content

Commit fde7330

Browse files
feat(pjax): preserve footer while replacing tail content during navigation
Signed-off-by: wangsimiao1 <wangsimiao1@xiaomi.com>
1 parent 9634fa6 commit fde7330

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

_javascript/modules/layouts/pjax.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ async function navigate(url, pushState = true) {
130130
panel.innerHTML = newPanel.innerHTML;
131131
}
132132

133+
// Replace tail content (comments etc.) but preserve footer
134+
const tail = container.querySelector('#tail-wrapper');
135+
const newTail = newContainer.querySelector('#tail-wrapper');
136+
if (tail && newTail) {
137+
const footer = tail.querySelector('footer');
138+
const newChildren = [...newTail.childNodes].filter(
139+
(n) => n.nodeName !== 'FOOTER'
140+
);
141+
[...tail.childNodes]
142+
.filter((n) => n.nodeName !== 'FOOTER')
143+
.forEach((n) => n.remove());
144+
if (footer) {
145+
newChildren.forEach((n) => tail.insertBefore(n.cloneNode(true), footer));
146+
}
147+
}
148+
133149
// Update title
134150
document.title = doc.title;
135151

0 commit comments

Comments
 (0)