Skip to content

Restore create_placeholders_if_missing() #296

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged
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
26 changes: 26 additions & 0 deletions templates/switchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ const _CURRENT_PREFIX = (() => {
const _ALL_VERSIONS = new Map($VERSIONS);
const _ALL_LANGUAGES = new Map($LANGUAGES);

/**
* Required for Python 3.7 and earlier.
* @returns {void}
* @private
*/
const _create_placeholders_if_missing = () => {
if (document.querySelectorAll(".version_switcher_placeholder").length) return;

const items = document.querySelectorAll("body>div.related>ul>li:not(.right)");
for (const item of items) {
if (item.innerText.toLowerCase().includes("documentation")) {
const container = document.createElement("li");
container.className = "switchers";
for (const placeholder_name of ["language", "version"]) {
const placeholder = document.createElement("div");
placeholder.className = `${placeholder_name}_switcher_placeholder`;
container.appendChild(placeholder);
}
item.parentElement.insertBefore(container, item);
return;
}
}
};

/**
* @param {Map<string, string>} versions
* @returns {HTMLSelectElement}
Expand Down Expand Up @@ -175,6 +199,8 @@ const _initialise_switchers = () => {
const versions = _ALL_VERSIONS;
const languages = _ALL_LANGUAGES;

_create_placeholders_if_missing();

document
.querySelectorAll(".version_switcher_placeholder")
.forEach((placeholder) => {
Expand Down