Skip to content

Commit 8aea24b

Browse files
committed
try to clone flyout to smallscreen sidebar too
1 parent a09c9ac commit 8aea24b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,20 @@ function initRTDObserver() {
490490
return;
491491
}
492492
if (mutation.addedNodes[0].data.search("Inserted RTD Footer") != -1) {
493-
mutation.addedNodes.forEach((node) => {
494-
document.getElementById("rtd-footer-container").append(node);
493+
let flyout = mutation.addedNodes[0].cloneNode(true);
494+
// copy the flyout menu to whichever of the 2 target nodes didn't already get
495+
// written to by the RTD injection script.
496+
document.querySelectorAll('[data-rtd-target="rtd"]').forEach((node) => {
497+
if (!node.hasChildNodes()) {
498+
node.appendChild(flyout);
499+
flyout.onclick = toggleFlyout;
500+
// replicate the onclick function RTD uses: it can't be cloned by cloneNode()
501+
flyout
502+
.querySelector(".rst-current-version")
503+
.addEventListener("click", function (e) {
504+
e.currentTarget.classList.toggleClass("shift-up");
505+
});
506+
}
495507
});
496508
}
497509
});
@@ -531,4 +543,4 @@ documentReady(addModeListener);
531543
documentReady(scrollToActive);
532544
documentReady(addTOCInteractivity);
533545
documentReady(setupSearchButtons);
534-
// documentReady(initRTDObserver);
546+
documentReady(initRTDObserver);

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/components/version-switcher.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#}
33
{% if theme_switcher.get('use_rtd') is defined and theme_switcher.get('use_rtd') %}
44
<script>
5-
document.write(`<div id="readthedocs-embed-flyout"></div>`);
5+
document.write(`<div id="readthedocs-embed-flyout" data-rtd-target="rtd"></div>`);
66
</script>
77
{% else %}
88
<script>

0 commit comments

Comments
 (0)