| 
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.13)",  | 
65 |  | -           urls: {  | 
66 |  | -               documentation: "https://docs.python.org/3.13/",  | 
67 |  | -           }  | 
68 |  | -       },  | 
69 |  | -       {  | 
70 |  | -           slug: "3.12",  | 
71 |  | -           urls: {  | 
72 |  | -               documentation: "https://docs.python.org/3.12/",  | 
73 |  | -           }  | 
74 |  | -       },  | 
75 |  | -       {  | 
76 |  | -           slug: "3.11",  | 
77 |  | -           urls: {  | 
78 |  | -               documentation: "https://docs.python.org/3.11/",  | 
79 |  | -           }  | 
80 |  | -       },  | 
81 |  | -   ]);  | 
82 |  | - | 
83 |  | -   const versionSelect = `  | 
84 |  | -   <select id="version_select">  | 
85 |  | -   ${ versions.map(  | 
86 |  | -       (version) => `  | 
87 |  | -       <option  | 
88 |  | -           value="${ version.slug }"  | 
89 |  | -           ${ config.versions.current.slug === version.slug ? 'selected="selected"' : '' }  | 
90 |  | -           data-url="${ version.urls.documentation }">  | 
91 |  | -           ${ version.slug }  | 
92 |  | -       </option>`  | 
93 |  | -   ).join("\n") }  | 
94 |  | -   </select>  | 
95 |  | -   `;  | 
96 |  | - | 
97 |  | -   // Prepend the current language to the options on the selector  | 
98 |  | -   let languages = config.projects.translations.concat(config.projects.current);  | 
99 |  | -   languages = languages.sort((a, b) => a.language.name.localeCompare(b.language.name));  | 
100 |  | - | 
101 |  | -   const languageSelect = `  | 
102 |  | -   <select id="language_select">  | 
103 |  | -   ${ languages.map(  | 
104 |  | -       (translation) => `  | 
105 |  | -       <option  | 
106 |  | -           value="${ translation.slug }"  | 
107 |  | -           ${ config.projects.current.slug === translation.slug ? 'selected="selected"' : '' }  | 
108 |  | -           data-url="${ translation.urls.documentation }">  | 
109 |  | -           ${ translation.language.name }  | 
110 |  | -       </option>`  | 
111 |  | -   ).join("\n") }  | 
112 |  | -   </select>  | 
113 |  | -   `;  | 
114 |  | - | 
115 |  | -   // Query all the placeholders because there are different ones for Desktop/Mobile  | 
116 |  | -   const versionPlaceholders = document.querySelectorAll(".version_switcher_placeholder");  | 
117 |  | -   for (placeholder of versionPlaceholders) {  | 
118 |  | -       placeholder.innerHTML = versionSelect;  | 
119 |  | -       let selectElement = placeholder.querySelector("select");  | 
120 |  | -       selectElement.addEventListener("change", onSwitch);  | 
121 |  | -   }  | 
122 |  | - | 
123 |  | -   const languagePlaceholders = document.querySelectorAll(".language_switcher_placeholder");  | 
124 |  | -   for (placeholder of languagePlaceholders) {  | 
125 |  | -       placeholder.innerHTML = languageSelect;  | 
126 |  | -       let selectElement = placeholder.querySelector("select");  | 
127 |  | -       selectElement.addEventListener("change", onSwitch);  | 
128 |  | -   }  | 
129 |  | - });  | 
130 |  | -</script>  | 
 | 46 | +            <script type="text/javascript" src="{{ pathto('_static/rtd_switcher.js', 1) }}"></script>  | 
 | 47 | +            <meta name="readthedocs-addons-api-version" content="1">  | 
131 | 48 | {%- endif %}  | 
132 | 49 | {% endblock %}  | 
0 commit comments