Debian Codegraph @

docs/javascript/readthedocs.js

raw
1 // This snippet is used to add the Read the Docs search to MkDocs Material
2 // It is based on the Read the Docs documentation:
3 // https://docs.readthedocs.com/platform/stable/intro/mkdocs.html#configure-read-the-docs-search
4 document.addEventListener("DOMContentLoaded", function(event) {
5 // Trigger Read the Docs' search addon instead of Material MkDocs default
6 document.querySelector(".md-search__input").addEventListener("focus", (e) => {
7 const event = new CustomEvent("readthedocs-search-show");
8 document.dispatchEvent(event);
9 });
10 });
11
12
13 // This snippet is used to add the Read the Docs version dropdown to MkDocs Material
14 // It is based on the Read the Docs documentation:
15 // https://docs.readthedocs.com/platform/stable/intro/mkdocs.html#integrate-the-read-the-docs-version-menu-into-your-site-navigation
16 document.addEventListener(
17 "readthedocs-addons-data-ready",
18 function (event) {
19 const config = event.detail.data();
20 const versioning = `
21 <div class="md-version">
22 <button class="md-version__current" aria-label="Select version">
23 ${config.versions.current.slug}
24 </button>
25
26 <ul class="md-version__list">
27 ${ config.versions.active.map(
28 (version) => `
29 <li class="md-version__item">
30 <a href="${ version.urls.documentation }" class="md-version__link">
31 ${ version.slug }
32 </a>
33 </li>`).join("\n")}
34 </ul>
35 </div>`;
36
37 document.querySelector(".md-header__topic").insertAdjacentHTML("beforeend", versioning);
38 });