Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteea26c4

Browse files
authored
Docs: Move inline JavaScript to own file to reduce duplication (#119541)
1 parent3dfa364 commiteea26c4

File tree

2 files changed

+90
-91
lines changed

2 files changed

+90
-91
lines changed

‎Doc/tools/static/rtd_switcher.js‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
functiononSwitch(event){
2+
constoption=event.target.selectedIndex;
3+
constitem=event.target.options[option];
4+
window.location.href=item.dataset.url;
5+
}
6+
7+
document.addEventListener("readthedocs-addons-data-ready",function(event){
8+
constconfig=event.detail.data()
9+
10+
// Add some mocked hardcoded versions pointing to the official
11+
// documentation while migrating to Read the Docs.
12+
// These are only for testing purposes.
13+
// TODO: remove them when managing all the versions on Read the Docs,
14+
// since all the "active, built and not hidden" versions will be shown automatically.
15+
letversions=config.versions.active.concat([
16+
{
17+
slug:"dev (3.14)",
18+
urls:{
19+
documentation:"https://docs.python.org/3.14/",
20+
}
21+
},
22+
{
23+
slug:"dev (3.13)",
24+
urls:{
25+
documentation:"https://docs.python.org/3.13/",
26+
}
27+
},
28+
{
29+
slug:"3.12",
30+
urls:{
31+
documentation:"https://docs.python.org/3.12/",
32+
}
33+
},
34+
{
35+
slug:"3.11",
36+
urls:{
37+
documentation:"https://docs.python.org/3.11/",
38+
}
39+
},
40+
]);
41+
42+
constversionSelect=`
43+
<select id="version_select">
44+
${versions.map(
45+
(version)=>`
46+
<option
47+
value="${version.slug}"
48+
${config.versions.current.slug===version.slug ?'selected="selected"' :''}
49+
data-url="${version.urls.documentation}">
50+
${version.slug}
51+
</option>`
52+
).join("\n")}
53+
</select>
54+
`;
55+
56+
// Prepend the current language to the options on the selector
57+
letlanguages=config.projects.translations.concat(config.projects.current);
58+
languages=languages.sort((a,b)=>a.language.name.localeCompare(b.language.name));
59+
60+
constlanguageSelect=`
61+
<select id="language_select">
62+
${languages.map(
63+
(translation)=>`
64+
<option
65+
value="${translation.slug}"
66+
${config.projects.current.slug===translation.slug ?'selected="selected"' :''}
67+
data-url="${translation.urls.documentation}">
68+
${translation.language.name}
69+
</option>`
70+
).join("\n")}
71+
</select>
72+
`;
73+
74+
// Query all the placeholders because there are different ones for Desktop/Mobile
75+
constversionPlaceholders=document.querySelectorAll(".version_switcher_placeholder");
76+
for(placeholderofversionPlaceholders){
77+
placeholder.innerHTML=versionSelect;
78+
letselectElement=placeholder.querySelector("select");
79+
selectElement.addEventListener("change",onSwitch);
80+
}
81+
82+
constlanguagePlaceholders=document.querySelectorAll(".language_switcher_placeholder");
83+
for(placeholderoflanguagePlaceholders){
84+
placeholder.innerHTML=languageSelect;
85+
letselectElement=placeholder.querySelector("select");
86+
selectElement.addEventListener("change",onSwitch);
87+
}
88+
});

‎Doc/tools/templates/layout.html‎

Lines changed: 2 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -43,96 +43,7 @@
4343
{{ super() }}
4444

4545
{%- if not embedded %}
46-
<metaname="readthedocs-addons-api-version"content="1">
47-
<scripttype="text/javascript">
48-
functiononSwitch(event){
49-
constoption=event.target.selectedIndex;
50-
constitem=event.target.options[option];
51-
window.location.href=item.dataset.url;
52-
}
53-
54-
document.addEventListener("readthedocs-addons-data-ready",function(event){
55-
constconfig=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-
letversions=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-
constversionSelect=`
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-
letlanguages=config.projects.translations.concat(config.projects.current);
105-
languages=languages.sort((a,b)=>a.language.name.localeCompare(b.language.name));
106-
107-
constlanguageSelect=`
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-
constversionPlaceholders=document.querySelectorAll(".version_switcher_placeholder");
123-
for(placeholderofversionPlaceholders){
124-
placeholder.innerHTML=versionSelect;
125-
letselectElement=placeholder.querySelector("select");
126-
selectElement.addEventListener("change",onSwitch);
127-
}
128-
129-
constlanguagePlaceholders=document.querySelectorAll(".language_switcher_placeholder");
130-
for(placeholderoflanguagePlaceholders){
131-
placeholder.innerHTML=languageSelect;
132-
letselectElement=placeholder.querySelector("select");
133-
selectElement.addEventListener("change",onSwitch);
134-
}
135-
});
136-
</script>
46+
<scripttype="text/javascript"src="{{ pathto('_static/rtd_switcher.js', 1) }}"></script>
47+
<metaname="readthedocs-addons-api-version"content="1">
13748
{%- endif %}
13849
{% endblock %}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp