1
- ' use strict' ;
1
+ " use strict" ;
2
2
3
3
// File URIs must begin with either one or three forward slashes
4
- const _is_file_uri = ( uri ) => uri . startsWith ( ' file:/' ) ;
4
+ const _is_file_uri = ( uri ) => uri . startsWith ( " file:/" ) ;
5
5
6
6
const _IS_LOCAL = _is_file_uri ( window . location . href ) ;
7
- const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS . VERSION || '' ;
8
- const _CURRENT_VERSION = _CURRENT_RELEASE . split ( '.' , 2 ) . join ( '.' ) ;
9
- const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS . LANGUAGE ?. toLowerCase ( ) || 'en' ;
7
+ const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS . VERSION || "" ;
8
+ const _CURRENT_VERSION = _CURRENT_RELEASE . split ( "." , 2 ) . join ( "." ) ;
9
+ const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS . LANGUAGE ?. toLowerCase ( ) || "en" ;
10
10
const _CURRENT_PREFIX = ( ( ) => {
11
11
if ( _IS_LOCAL ) return null ;
12
12
// Sphinx 7.2+ defines the content root data attribute in the HTML element.
@@ -15,8 +15,8 @@ const _CURRENT_PREFIX = (() => {
15
15
return new URL ( _CONTENT_ROOT , window . location ) . pathname ;
16
16
}
17
17
// Fallback for older versions of Sphinx (used in Python 3.10 and older).
18
- const _NUM_PREFIX_PARTS = _CURRENT_LANGUAGE === 'en' ? 2 : 3 ;
19
- return window . location . pathname . split ( '/' , _NUM_PREFIX_PARTS ) . join ( '/' ) + '/' ;
18
+ const _NUM_PREFIX_PARTS = _CURRENT_LANGUAGE === "en" ? 2 : 3 ;
19
+ return window . location . pathname . split ( "/" , _NUM_PREFIX_PARTS ) . join ( "/" ) + "/" ;
20
20
} ) ( ) ;
21
21
22
22
const _ALL_VERSIONS = new Map ( $VERSIONS ) ;
@@ -28,15 +28,15 @@ const _ALL_LANGUAGES = new Map($LANGUAGES);
28
28
* @private
29
29
*/
30
30
const _create_version_select = ( versions ) => {
31
- const select = document . createElement ( ' select' ) ;
32
- select . className = ' version-select' ;
31
+ const select = document . createElement ( " select" ) ;
32
+ select . className = " version-select" ;
33
33
if ( _IS_LOCAL ) {
34
34
select . disabled = true ;
35
- select . title = ' Version switching is disabled in local builds' ;
35
+ select . title = " Version switching is disabled in local builds" ;
36
36
}
37
37
38
38
for ( const [ version , title ] of versions ) {
39
- const option = document . createElement ( ' option' ) ;
39
+ const option = document . createElement ( " option" ) ;
40
40
option . value = version ;
41
41
if ( version === _CURRENT_VERSION ) {
42
42
option . text = _CURRENT_RELEASE ;
@@ -61,15 +61,15 @@ const _create_language_select = (languages) => {
61
61
languages . set ( _CURRENT_LANGUAGE , _CURRENT_LANGUAGE ) ;
62
62
}
63
63
64
- const select = document . createElement ( ' select' ) ;
65
- select . className = ' language-select' ;
64
+ const select = document . createElement ( " select" ) ;
65
+ select . className = " language-select" ;
66
66
if ( _IS_LOCAL ) {
67
67
select . disabled = true ;
68
- select . title = ' Language switching is disabled in local builds' ;
68
+ select . title = " Language switching is disabled in local builds" ;
69
69
}
70
70
71
71
for ( const [ language , title ] of languages ) {
72
- const option = document . createElement ( ' option' ) ;
72
+ const option = document . createElement ( " option" ) ;
73
73
option . value = language ;
74
74
option . text = title ;
75
75
if ( language === _CURRENT_LANGUAGE ) option . selected = true ;
@@ -88,7 +88,7 @@ const _navigate_to_first_existing = async (urls) => {
88
88
// Navigate to the first existing URL in urls.
89
89
for ( const url of urls ) {
90
90
try {
91
- const response = await fetch ( url , { method : ' HEAD' } ) ;
91
+ const response = await fetch ( url , { method : " HEAD" } ) ;
92
92
if ( response . ok ) {
93
93
window . location . href = url ;
94
94
return url ;
@@ -99,8 +99,8 @@ const _navigate_to_first_existing = async (urls) => {
99
99
}
100
100
101
101
// if all else fails, redirect to the d.p.o root
102
- window . location . href = '/' ;
103
- return '/' ;
102
+ window . location . href = "/" ;
103
+ return "/" ;
104
104
} ;
105
105
106
106
/**
@@ -116,7 +116,7 @@ const _on_version_switch = async (event) => {
116
116
// English has no language prefix.
117
117
const new_prefix_en = `/${ selected_version } /` ;
118
118
const new_prefix =
119
- _CURRENT_LANGUAGE === 'en'
119
+ _CURRENT_LANGUAGE === "en"
120
120
? new_prefix_en
121
121
: `/${ _CURRENT_LANGUAGE } /${ selected_version } /` ;
122
122
if ( _CURRENT_PREFIX !== new_prefix ) {
@@ -146,7 +146,7 @@ const _on_language_switch = async (event) => {
146
146
const selected_language = event . target . value ;
147
147
// English has no language prefix.
148
148
const new_prefix =
149
- selected_language === 'en'
149
+ selected_language === "en"
150
150
? `/${ _CURRENT_VERSION } /`
151
151
: `/${ selected_language } /${ _CURRENT_VERSION } /` ;
152
152
if ( _CURRENT_PREFIX !== new_prefix ) {
@@ -170,24 +170,24 @@ const _initialise_switchers = () => {
170
170
const languages = _ALL_LANGUAGES ;
171
171
172
172
document
173
- . querySelectorAll ( ' .version_switcher_placeholder' )
173
+ . querySelectorAll ( " .version_switcher_placeholder" )
174
174
. forEach ( ( placeholder ) => {
175
175
const s = _create_version_select ( versions ) ;
176
- s . addEventListener ( ' change' , _on_version_switch ) ;
176
+ s . addEventListener ( " change" , _on_version_switch ) ;
177
177
placeholder . append ( s ) ;
178
178
} ) ;
179
179
180
180
document
181
- . querySelectorAll ( ' .language_switcher_placeholder' )
181
+ . querySelectorAll ( " .language_switcher_placeholder" )
182
182
. forEach ( ( placeholder ) => {
183
183
const s = _create_language_select ( languages ) ;
184
- s . addEventListener ( ' change' , _on_language_switch ) ;
184
+ s . addEventListener ( " change" , _on_language_switch ) ;
185
185
placeholder . append ( s ) ;
186
186
} ) ;
187
187
} ;
188
188
189
- if ( document . readyState !== ' loading' ) {
189
+ if ( document . readyState !== " loading" ) {
190
190
_initialise_switchers ( ) ;
191
191
} else {
192
- document . addEventListener ( ' DOMContentLoaded' , _initialise_switchers ) ;
192
+ document . addEventListener ( " DOMContentLoaded" , _initialise_switchers ) ;
193
193
}
0 commit comments