1
1
'use strict' ;
2
2
3
+ // File URIs must begin with either one or three forward slashes
4
+ const _is_file_uri = ( uri ) => uri . startsWith ( 'file:/' ) ;
5
+
6
+ const _IS_LOCAL = _is_file_uri ( window . location . href ) ;
3
7
const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS . VERSION || '' ;
4
8
const _CURRENT_VERSION = _CURRENT_RELEASE . split ( '.' , 2 ) . join ( '.' ) ;
5
9
const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS . LANGUAGE ?. toLowerCase ( ) || 'en' ;
6
10
const _CURRENT_PREFIX = ( ( ) => {
11
+ if ( _IS_LOCAL ) return null ;
7
12
// Sphinx 7.2+ defines the content root data attribute in the HTML element.
8
13
const _CONTENT_ROOT = document . documentElement . dataset . content_root ;
9
14
if ( _CONTENT_ROOT !== undefined ) {
@@ -20,6 +25,10 @@ const all_languages = $LANGUAGES;
20
25
const _create_version_select = ( ) => {
21
26
const select = document . createElement ( 'select' ) ;
22
27
select . className = 'version-select' ;
28
+ if ( _IS_LOCAL ) {
29
+ select . disabled = true ;
30
+ select . title = 'Version switching is disabled in local builds' ;
31
+ }
23
32
24
33
for ( const [ version , title ] of Object . entries ( all_versions ) ) {
25
34
const option = document . createElement ( 'option' ) ;
@@ -44,6 +53,10 @@ const _create_language_select = () => {
44
53
45
54
const select = document . createElement ( 'select' ) ;
46
55
select . className = 'language-select' ;
56
+ if ( _IS_LOCAL ) {
57
+ select . disabled = true ;
58
+ select . title = 'Language switching is disabled in local builds' ;
59
+ }
47
60
48
61
for ( const [ language , title ] of Object . entries ( all_languages ) ) {
49
62
const option = document . createElement ( 'option' ) ;
@@ -59,10 +72,6 @@ const _create_language_select = () => {
59
72
const _navigate_to_first_existing = ( urls ) => {
60
73
// Navigate to the first existing URL in urls.
61
74
for ( const url of urls ) {
62
- if ( url . startsWith ( 'file:///' ) ) {
63
- window . location . href = url ;
64
- return ;
65
- }
66
75
fetch ( url )
67
76
. then ( ( response ) => {
68
77
if ( response . ok ) {
@@ -82,6 +91,8 @@ const _navigate_to_first_existing = (urls) => {
82
91
} ;
83
92
84
93
const _on_version_switch = ( event ) => {
94
+ if ( _IS_LOCAL ) return ;
95
+
85
96
const selected_version = event . target . value ;
86
97
// English has no language prefix.
87
98
const new_prefix_en = `/${ selected_version } /` ;
@@ -105,6 +116,8 @@ const _on_version_switch = (event) => {
105
116
} ;
106
117
107
118
const _on_language_switch = ( event ) => {
119
+ if ( _IS_LOCAL ) return ;
120
+
108
121
const selected_language = event . target . value ;
109
122
// English has no language prefix.
110
123
const new_prefix =
0 commit comments