From c9417ff0928852330c5b6c865648d085cfacde9b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Thu, 23 Jan 2025 23:47:01 +0000 Subject: [PATCH] PEP Theme: Support multiple closeable admonitions --- .../pep_theme/static/sticky_banner.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pep_sphinx_extensions/pep_theme/static/sticky_banner.js b/pep_sphinx_extensions/pep_theme/static/sticky_banner.js index e20f62d2d33..4e3722053fc 100644 --- a/pep_sphinx_extensions/pep_theme/static/sticky_banner.js +++ b/pep_sphinx_extensions/pep_theme/static/sticky_banner.js @@ -17,18 +17,16 @@ document.addEventListener("DOMContentLoaded", () => { function adjustBannerMargin() { const text = document.createTextNode( - ":target { scroll-margin-top: " + stickyBanner.offsetHeight + "px; }" + `:target { scroll-margin-top: ${stickyBanner.offsetHeight}px; }`, ); node.replaceChildren(text); } - const closeButton = document.querySelector('.close-button'); - if (closeButton) { - closeButton.addEventListener('click', () => { - const stickyBanner = document.querySelector('.sticky-banner'); - if (stickyBanner) { - stickyBanner.style.display = 'none'; - } + for (const closeButton of document.getElementsByClassName("close-button")) { + closeButton.addEventListener("click", () => { + // search the button's ancestors for a ``sticky-banner`` element. + const stickyBanner = closeButton.closest(".sticky-banner"); + if (stickyBanner) stickyBanner.remove(); }); }