const themeFlyoutDisplay = "hidden"; const themeVersionSelector = "True"; const themeLanguageSelector = "True"; if (themeFlyoutDisplay === "attached") { function renderLanguages(config) { if (!config.projects.translations.length) { return ""; } const languagesHTML = `
Languages
${config.projects.translations .map( (translation) => `
${translation.language.code}
`, ) .join("\n")}
`; return languagesHTML; } function renderVersions(config) { if (!config.versions.active.length) { return ""; } const versionsHTML = `
Versions
${config.versions.active .map( (version) => `
${version.slug}
`, ) .join("\n")}
`; return versionsHTML; } function renderDownloads(config) { if (!Object.keys(config.versions.current.downloads).length) { return ""; } const downloadsNameDisplay = { pdf: "PDF", epub: "Epub", htmlzip: "HTML", }; const downloadsHTML = `
Downloads
${Object.entries(config.versions.current.downloads) .map( ([name, url]) => `
${downloadsNameDisplay[name]}
`, ) .join("\n")}
`; return downloadsHTML; } document.addEventListener("readthedocs-addons-data-ready", function (event) { const config = event.detail.data(); const flyout = `
Read the Docs v: ${config.versions.current.slug}
${renderLanguages(config)} ${renderVersions(config)} ${renderDownloads(config)}
On Read the Docs
Project Home
Builds
Downloads
Search

Hosted by Read the Docs
`; // Inject the generated flyout into the body HTML element. document.body.insertAdjacentHTML("beforeend", flyout); // Trigger the Read the Docs Addons Search modal when clicking on the "Search docs" input from inside the flyout. document .querySelector("#flyout-search-form") .addEventListener("focusin", () => { const event = new CustomEvent("readthedocs-search-show"); document.dispatchEvent(event); }); }) } if (themeLanguageSelector || themeVersionSelector) { function onSelectorSwitch(event) { const option = event.target.selectedIndex; const item = event.target.options[option]; window.location.href = item.dataset.url; } document.addEventListener("readthedocs-addons-data-ready", function (event) { const config = event.detail.data(); const versionSwitch = document.querySelector( "div.switch-menus > div.version-switch", ); if (themeVersionSelector) { let versions = config.versions.active; if (config.versions.current.hidden || config.versions.current.type === "external") { versions.unshift(config.versions.current); } const versionSelect = ` `; versionSwitch.innerHTML = versionSelect; versionSwitch.firstElementChild.addEventListener("change", onSelectorSwitch); } const languageSwitch = document.querySelector( "div.switch-menus > div.language-switch", ); if (themeLanguageSelector) { if (config.projects.translations.length) { // Add the current language to the options on the selector let languages = config.projects.translations.concat( config.projects.current, ); languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name), ); const languageSelect = ` `; languageSwitch.innerHTML = languageSelect; languageSwitch.firstElementChild.addEventListener("change", onSelectorSwitch); } else { languageSwitch.remove(); } } }); } document.addEventListener("readthedocs-addons-data-ready", function (event) { // Trigger the Read the Docs Addons Search modal when clicking on "Search docs" input from the topnav. document .querySelector("[role='search'] input") .addEventListener("focusin", () => { const event = new CustomEvent("readthedocs-search-show"); document.dispatchEvent(event); }); });