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); }); // 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); }); });