Skip to content
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

docs: Don't hide the version selector when scrolling down #5114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/extra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
document$.subscribe(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I tried this out and it seems to not work when I reload the page and keep the same scroll location. The header doesn't disappear until I scroll up and scroll down again.

However, removing the document$.subscribe and calling the function immediately seems to resolve the issue. My guess is that if the page is already scrolled down, then we never observe a mutation in the header for whatever reason. It looks like extra.js is embedded in the page after the target header element, so there should be a guarantee that the element can be addressed and we can install the mutation observer safely?

nit: Should this function also be an arrow function instead, like the other ones in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, I’ll try without subscribe then

// 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 });
});
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading