Skip to content

Commit 9b8e3f9

Browse files
authored
PEP Theme: Support multiple closeable admonitions (#4225)
1 parent 41a1c11 commit 9b8e3f9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pep_sphinx_extensions/pep_theme/static/sticky_banner.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ document.addEventListener("DOMContentLoaded", () => {
1717

1818
function adjustBannerMargin() {
1919
const text = document.createTextNode(
20-
":target { scroll-margin-top: " + stickyBanner.offsetHeight + "px; }"
20+
`:target { scroll-margin-top: ${stickyBanner.offsetHeight}px; }`,
2121
);
2222
node.replaceChildren(text);
2323
}
2424

25-
const closeButton = document.querySelector('.close-button');
26-
if (closeButton) {
27-
closeButton.addEventListener('click', () => {
28-
const stickyBanner = document.querySelector('.sticky-banner');
29-
if (stickyBanner) {
30-
stickyBanner.style.display = 'none';
31-
}
25+
for (const closeButton of document.getElementsByClassName("close-button")) {
26+
closeButton.addEventListener("click", () => {
27+
// search the button's ancestors for a ``sticky-banner`` element.
28+
const stickyBanner = closeButton.closest(".sticky-banner");
29+
if (stickyBanner) stickyBanner.remove();
3230
});
3331
}
3432

0 commit comments

Comments
 (0)