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