From 5c5f03ac56fba84db4137920145d2e8861177017 Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 16 Dec 2024 23:45:52 +0100 Subject: [PATCH] docs: Don't hide the version selector when scrolling down --- docs/extra.js | 22 ++++++++++++++++++++++ mkdocs.yml | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 docs/extra.js diff --git a/docs/extra.js b/docs/extra.js new file mode 100644 index 000000000..9fa715a04 --- /dev/null +++ b/docs/extra.js @@ -0,0 +1,22 @@ +document$.subscribe(function () { + // Stop mkdocs-material from hiding the version selector when scrolling down; + // this is done by removing the --active class when mkdocs-material adds it. + // (--active = scrolled down) + + const title = document.querySelector('*[data-md-component="header-title"]'); + + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.attributeName === "class") { + const classList = title.className.split(" "); + classList.forEach((className) => { + if (className.endsWith("--active")) { + title.classList.remove(className); + } + }); + } + }); + }); + + observer.observe(title, { attributes: true }); +}); diff --git a/mkdocs.yml b/mkdocs.yml index 2e85e10fa..7d3c70886 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -84,6 +84,9 @@ markdown_extensions: emoji_index: !!python/name:material.extensions.emoji.twemoji emoji_generator: !!python/name:material.extensions.emoji.to_svg +extra_javascript: + - extra.js + # This lists all the files that become part of the documentation nav: - 'Home': 'index.md'