|
43 | 43 | {{ super() }} |
44 | 44 |
|
45 | 45 | {%- if not embedded %} |
46 | | -<meta name="readthedocs-addons-api-version" content="1"> |
47 | | -<script type="text/javascript"> |
48 | | - function onSwitch(event) { |
49 | | - const option = event.target.selectedIndex; |
50 | | - const item = event.target.options[option]; |
51 | | - window.location.href = item.dataset.url; |
52 | | - } |
53 | | - |
54 | | - document.addEventListener("readthedocs-addons-data-ready", function(event) { |
55 | | - const config = event.detail.data() |
56 | | - |
57 | | - // Add some mocked hardcoded versions pointing to the official |
58 | | - // documentation while migrating to Read the Docs. |
59 | | - // These are only for testing purposes. |
60 | | - // TODO: remove them when managing all the versions on Read the Docs, |
61 | | - // since all the "active, built and not hidden" versions will be shown automatically. |
62 | | - let versions = config.versions.active.concat([ |
63 | | - { |
64 | | - slug: "dev (3.14)", |
65 | | - urls: { |
66 | | - documentation: "https://docs.python.org/3.14/", |
67 | | - } |
68 | | - }, |
69 | | - { |
70 | | - slug: "pre (3.13)", |
71 | | - urls: { |
72 | | - documentation: "https://docs.python.org/3.13/", |
73 | | - } |
74 | | - }, |
75 | | - { |
76 | | - slug: "3.12", |
77 | | - urls: { |
78 | | - documentation: "https://docs.python.org/3.12/", |
79 | | - } |
80 | | - }, |
81 | | - { |
82 | | - slug: "3.11", |
83 | | - urls: { |
84 | | - documentation: "https://docs.python.org/3.11/", |
85 | | - } |
86 | | - }, |
87 | | - ]); |
88 | | - |
89 | | - const versionSelect = ` |
90 | | - <select id="version_select"> |
91 | | - ${ versions.map( |
92 | | - (version) => ` |
93 | | - <option |
94 | | - value="${ version.slug }" |
95 | | - ${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' } |
96 | | - data-url="${ version.urls.documentation }"> |
97 | | - ${ version.slug } |
98 | | - </option>` |
99 | | - ).join("\n") } |
100 | | - </select> |
101 | | - `; |
102 | | - |
103 | | - // Prepend the current language to the options on the selector |
104 | | - let languages = config.projects.translations.concat(config.projects.current); |
105 | | - languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name)); |
106 | | - |
107 | | - const languageSelect = ` |
108 | | - <select id="language_select"> |
109 | | - ${ languages.map( |
110 | | - (translation) => ` |
111 | | - <option |
112 | | - value="${ translation.slug }" |
113 | | - ${ config.projects.current.slug === translation.slug ? 'selected="selected"' : '' } |
114 | | - data-url="${ translation.urls.documentation }"> |
115 | | - ${ translation.language.name } |
116 | | - </option>` |
117 | | - ).join("\n") } |
118 | | - </select> |
119 | | - `; |
120 | | - |
121 | | - // Query all the placeholders because there are different ones for Desktop/Mobile |
122 | | - const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder"); |
123 | | - for (placeholder of versionPlaceholders) { |
124 | | - placeholder.innerHTML = versionSelect; |
125 | | - let selectElement = placeholder.querySelector("select"); |
126 | | - selectElement.addEventListener("change", onSwitch); |
127 | | - } |
128 | | - |
129 | | - const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder"); |
130 | | - for (placeholder of languagePlaceholders) { |
131 | | - placeholder.innerHTML = languageSelect; |
132 | | - let selectElement = placeholder.querySelector("select"); |
133 | | - selectElement.addEventListener("change", onSwitch); |
134 | | - } |
135 | | - }); |
136 | | -</script> |
| 46 | + <script type="text/javascript" src="{{ pathto('_static/rtd_switcher.js', 1) }}"></script> |
| 47 | + <meta name="readthedocs-addons-api-version" content="1"> |
137 | 48 | {%- endif %} |
138 | 49 | {% endblock %} |
0 commit comments