-
Notifications
You must be signed in to change notification settings - Fork 13
80 focus lost in navbar #96
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
7c6f1b2
61da9d3
17d0016
cbf4e9a
331d0d3
42c9aed
9e1672e
8d5d822
d49dccc
5c8a2eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # ===================================================================================== | ||
| # C O P Y R I G H T | ||
| # ------------------------------------------------------------------------------------- | ||
| # Copyright (c) 2023 by Robert Bosch GmbH. All rights reserved. | ||
| # | ||
| # Author(s): | ||
| # - Aniket Salve, Robert Bosch GmbH | ||
| # ===================================================================================== | ||
|
|
||
| """Doxysphinx themes extension. | ||
|
|
||
| This extensions add custom javascript files depending on theme. | ||
| Currently only supporting Book and RTD theme. | ||
| """ | ||
|
|
||
| import pathlib | ||
|
|
||
| from sphinx.application import Sphinx | ||
| from sphinx.config import Config | ||
|
|
||
|
|
||
| def setup(app: Sphinx): | ||
| """Setups up the replacer extension.""" | ||
| app.connect("config-inited", doxysphinx_theme_extension) | ||
| return {"parallel_read_safe": True, "parallel_write_safe": True, "version": "0.1.0"} | ||
|
|
||
|
|
||
| def doxysphinx_theme_extension(app: Sphinx, config: Config): | ||
| """Add custom javascript files specific to theme and set theme options. | ||
|
|
||
| :param app: Sphinx app | ||
| :param config: Sphinx config | ||
| """ | ||
| current_file_path = pathlib.Path(__file__).parent.resolve() | ||
|
|
||
| config.html_static_path.append(str(current_file_path) + "/_static/") | ||
|
|
||
| if config.html_theme == "sphinx_book_theme": | ||
| app.add_js_file("js/customize-navbar-book.js") | ||
|
|
||
| elif config.html_theme == "sphinx_rtd_theme": | ||
| app.add_js_file("js/customize-navbar-rtd.js") | ||
| config.html_theme_options["collapse_navigation"] = False | ||
|
aniketsalve22 marked this conversation as resolved.
Comment on lines
+38
to
+
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for being nosey here, but could there be some kind of explicit option to get these files? For ROCm documentation our theme is a slightly modified version of the Sphinx Book Theme (custom headers and footers), and I'm certain the js file for that theme would work for us as well, so it would be nice if we could enable this fix somehow.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are planning to provide these files as part of an extension which will be part of Doxysphinx. So hopefully you won't need to add anything manually.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant is the current logic wouldn't work for us because
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Maetveis So you have an own version of the sphinx book theme with a different name, e.g. "sphinx-book-theme-custom" right? In that case as you said his extension won't do anything for you. But you could still use the jsfile as it's in the doxysphinx-theme package directory. #<conf.py>
from pathlib import Path
from importlib.resources import files
# ...
patch_js_path = Path(files("doxysphinx_theme")) / "_static/js/customize-navbar-book.js"
html_theme_options = {
'extra_scripts': [str(patch_js_path)]
}But this might be only working in python 3.11+.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that's exactly what we have. I think I'll be able to make something like that work, the only slight issue with it is that I need to "know" implementation details of doxysphinx, I guess that is a price for having "forked" a theme. I'll try this out and maybe do a PR if I come up with a way to have less coupling. Thank you for the help. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
|
|
||
| /** | ||
| ===================================================================================== | ||
| C O P Y R I G H T | ||
| ------------------------------------------------------------------------------------- | ||
| Copyright (c) 2023 by Robert Bosch GmbH. All rights reserved. | ||
|
|
||
| Author(s): | ||
| - Aniket Salve, Robert Bosch Gmbh | ||
| ===================================================================================== | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * This function stores and updates the session store with active href | ||
| * If href is not present in nav bar then last state for session storage | ||
| * is shown as active state in navbar | ||
| * | ||
| * The classes are customized for sphinx-book-theme | ||
| */ | ||
| function findCurrentRoute() { | ||
|
|
||
| if (window.sessionStorage.getItem("href") == null) { | ||
| window.sessionStorage.setItem("href", window.location.href); | ||
| } | ||
|
|
||
| if (document.querySelector("li.active")) { | ||
| window.sessionStorage.setItem("href", window.location.href); | ||
| return; | ||
| } else { | ||
| var lastActiveNav = window.sessionStorage.getItem("href"); | ||
| var allTags = document.querySelectorAll("li"); | ||
| for (let i = 0; i < allTags.length; i++) { | ||
| if (allTags[i].getElementsByTagName("a")[0].href == lastActiveNav) { | ||
| allTags[i].getElementsByTagName("a")[0].classList.add("current"); | ||
| allTags[i].classList.add("current"); | ||
| allTags[i].classList.add("active"); | ||
| recursiveParentClassAppend(allTags[i].parentNode, false); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This function recursively parses the parent nodes | ||
| * Adds current class to UL tags | ||
| * Adds current and active classes to LI tags | ||
| * | ||
| * For all 2nd level and about parent UL nodes, the corresponding | ||
| * input tag is checked so that the navbar is expanded. This is achieved using flag | ||
| * | ||
| * @param {ParentNode | null} element Parent node of last active LI tag | ||
| * @param {Boolean} flag flag to check if input should be checked or not | ||
| */ | ||
| function recursiveParentClassAppend(element, flag) { | ||
| if (element.nodeName == "UL") { | ||
| if (flag && element.getElementsByTagName("input")) { | ||
| element.getElementsByTagName("input")[0].setAttribute("checked", ""); | ||
| } | ||
| element.classList.add("current") | ||
| if (element.parentNode.nodeName == "LI") { | ||
| element.parentNode.classList.add("current"); | ||
| element.parentNode.classList.add("active"); | ||
| recursiveParentClassAppend(element.parentNode.parentNode, true); | ||
| } | ||
| else { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $(document).ready(function () { | ||
| findCurrentRoute(); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
|
|
||
| /** | ||
| ===================================================================================== | ||
| C O P Y R I G H T | ||
| ------------------------------------------------------------------------------------- | ||
| Copyright (c) 2023 by Robert Bosch GmbH. All rights reserved. | ||
|
|
||
| Author(s): | ||
| - Aniket Salve, Robert Bosch Gmbh | ||
| ===================================================================================== | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * This function stores and updates the session store with active href | ||
| * If href is not present in nav bar then last state for session storage | ||
| * is shown as active state in navbar | ||
| * | ||
| * The classes are customized for sphinx-rtd-theme | ||
| */ | ||
| function findCurrentRoute() { | ||
|
|
||
| if (window.sessionStorage.getItem("href") == null) { | ||
| window.sessionStorage.setItem("href", window.location.href); | ||
| } | ||
|
|
||
| if (document.querySelector("li.current")) { | ||
| window.sessionStorage.setItem("href", window.location.href); | ||
| return; | ||
| } else { | ||
| var lastActiveNav = window.sessionStorage.getItem("href"); | ||
| var allTags = document.querySelectorAll("li"); | ||
| for (let i = 0; i < allTags.length; i++) { | ||
| console.log(allTags[i].getElementsByTagName("a")[0].href); | ||
| if (allTags[i].getElementsByTagName("a")[0].href == lastActiveNav) { | ||
| allTags[i].getElementsByTagName("a")[0].classList.add("current"); | ||
| allTags[i].getElementsByTagName("a")[0].setAttribute("aria-expanded", "true") | ||
| allTags[i].classList.add("current"); | ||
| allTags[i].setAttribute("aria-expanded", "true") | ||
| recursiveParentClassAppend(allTags[i].parentNode, true); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This function recursively parses the parent nodes | ||
| * Adds current class to UL tags | ||
| * Adds current class to LI tags | ||
| * Adds aria-expanded attribute to UL and LI tags | ||
| * | ||
| * For all 2nd level and about parent UL nodes, the corresponding | ||
| * input tag is checked so that the navbar is expanded. This is achieved using flag | ||
| * | ||
| * @param {ParentNode | null} element Parent node of last active LI tag | ||
| * @param {Boolean} flag flag to check if input should be checked or not | ||
| */ | ||
| function recursiveParentClassAppend(element, flag) { | ||
| if (element.nodeName == "UL") { | ||
| element.classList.add("current") | ||
| element.setAttribute("aria-expanded", "true") | ||
| if (element.parentNode.nodeName == "LI") { | ||
| element.parentNode.classList.add("current"); | ||
| element.parentNode.setAttribute("aria-expanded", "true") | ||
| recursiveParentClassAppend(element.parentNode.parentNode, true); | ||
| } | ||
| else { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $(document).ready(function () { | ||
| findCurrentRoute(); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.