8000 Implement support for sticky banners and utilize them by pradyunsg · Pull Request #2992 · python/peps · GitHub
[go: up one dir, main page]

Skip to content

Implement support for sticky banners and utilize them #2992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 20, 2023
Merged
Prev Previous commit
Next Next commit
fixup! Implement support for sticky banners
  • Loading branch information
pradyunsg committed Mar 11, 2023
commit 6041230ea9cad42b26f6b9fa16b82625dd23d13f
29 changes: 20 additions & 9 deletions pep_sphinx_extensions/pep_theme/static/sticky_banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
// when clicking on a link to an element with an id attribute. The offset is
// equal to the height of the sticky banner.
document.addEventListener("DOMContentLoaded", () => {
let stickyBanners = document.getElementsByClassName("sticky-banner");
if (!stickyBanners) {
return;
}
let stickyBanner = stickyBanners[0];
let node = document.createElement("style");
let text = document.createTextNode(":target { scroll-margin-top: " + stickyBanner.offsetHeight + "px; }")
node.appendChild(text);
document.head.appendChild(node);
const stickyBanners = document.getElementsByClassName("sticky-banner");
if (!stickyBanners) {
return;
}

const stickyBanner = stickyBanners[0];
const node = document.createElement("style");
node.id = "sticky-banner-style";
document.head.appendChild(node);

function adjustBannerMargin() {
const text = document.createTextNode(
":target { scroll-margin-top: " + stickyBanner.offsetHeight + "px; }"
);
node.replaceChildren(text);
}

adjustBannerMargin();
document.addEventListener("resize", adjustBannerMargin);
document.addEventListener("load", adjustBannerMargin);
});
0