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

Version selector #500

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,6 @@ node_modules
/build
/dist
__pycache__
env/

*.sw[a-p]
24 changes: 23 additions & 1 deletion src/furo/assets/scripts/furo.js
Expand Up @@ -160,16 +160,38 @@ function setup() {
setupScrollSpy();
}

////////////////////////////////////////////////////////////////////////////////
// Version dropdown
////////////////////////////////////////////////////////////////////////////////
function versionDropdown() {
const checkbox = document.getElementById("versions-label");
checkbox.addEventListener("click", toggleDropdown);

function toggleDropdown() {
if (localStorage.getItem("version-dropdown-opened") === "true") {
localStorage.setItem("version-dropdown-opened", "false");
} else {
localStorage.setItem("version-dropdown-opened", "true");
}
}
}

////////////////////////////////////////////////////////////////////////////////
// Main entrypoint
////////////////////////////////////////////////////////////////////////////////
function main() {
document.body.parentNode.classList.remove("no-js");

header = document.querySelector("header");
tocScroll = document.querySelector(".toc-scroll");

setup();

// Version dropdown functionality
const checkboxInput = document.getElementById("checkbox_toggle");
if (localStorage.getItem("version-dropdown-opened") === "true") {
checkboxInput.checked = true;
}
versionDropdown();
}

document.addEventListener("DOMContentLoaded", main);
40 changes: 40 additions & 0 deletions src/furo/assets/styles/extensions/_readthedocs.sass
@@ -1,6 +1,46 @@
// This file contains the styles used for tweaking how ReadTheDoc's embedded
// contents would show up inside the theme.

#furo-versions
font-size: var(--sidebar-item-font-size)
margin-bottom: 4em

.latest-version
font-weight: bold

.current-version
font-weight: bold

.caption
display: inline-block
color: var(--color-sidebar-caption-text)
font-weight: bold
text-transform: uppercase
font-size: var(--sidebar-caption-font-size)
padding-right: var(--sidebar-expander-width)
margin-top: 0

input[type=checkbox]
display: none
position: absolute
box-sizing: border-box
padding: 0
overflow: visible

input[type=checkbox]:checked ~ ul
display: inline-block
line-height: var(--sidebar-item-line-height)
margin-left: var(--sidebar-item-spacing-horizontal)
padding: var(--sidebar-item-spacing-vertical) var(--sidebar-item-spacing-horizontal)
text-decoration: none

ul
display: none

.versions-label
position: relative
float: right

#furo-sidebar-ad-placement
padding: var(--sidebar-item-spacing-vertical) var(--sidebar-item-spacing-horizontal)
.ethical-sidebar
Expand Down
23 changes: 23 additions & 0 deletions src/furo/theme/furo/sidebar/variant-selector.html
Expand Up @@ -30,4 +30,27 @@
</dl>
</div>
</div>
{% elif versions %}
<div id="furo-versions" class="rst-versions sidebar-tree" role="note" aria-label="{{ _('Versions') }}" tabindex="0">
<p class="caption">Versions</p>
<input type="checkbox" id="checkbox_toggle" class="toctree-checkbox versions-checkbox" role="switch">
<label id="versions-label" class="versions-label" for="checkbox_toggle">
<div class="visually-hidden">Toggle child pages in navigation</div>
<i class="icon">
<svg>
<use href="#svg-arrow-right"></use>
</svg>
</i>
</label>
<ul id="versions-children">
{#<li class="latest-version">Latest: <a href="{{ latest_version.url }}">{{ latest_version.name }}</a></li>#}
{% for version in versions|reverse -%}
<li{% if version.name == current_version.name %} class="current-version"{%- endif %}>{% if version.name == latest_version.name -%}<b>Latest: </b>{%- endif %}<a href="{{ version.url }}">{{ version.name }}</a></li>
{% endfor -%}
</ul>
</div>
{% endif %}
{#
latest: {{ latest_version }}
current: {{ current_version }}
#}
waynew marked this conversation as resolved.
Show resolved Hide resolved