11'use strict' ;
22
3+ // File URIs must begin with either one (1) or three (3) forward slashes
4+ const _is_file_uri = ( uri ) => uri . startsWith ( 'file:/' ) ;
5+
6+ const _IS_LOCAL = _is_file_uri ( window . location . href ) ;
37const _CURRENT_RELEASE = DOCUMENTATION_OPTIONS . VERSION || '' ;
48const _CURRENT_VERSION = _CURRENT_RELEASE . split ( '.' , 2 ) . join ( '.' ) ;
59const _CURRENT_LANGUAGE = DOCUMENTATION_OPTIONS . LANGUAGE ?. toLowerCase ( ) || 'en' ;
610const _CURRENT_PREFIX = ( ( ) => {
11+ if ( _IS_LOCAL ) return null ;
712 // Sphinx 7.2+ defines the content root data attribute in the HTML element.
813 const _CONTENT_ROOT = document . documentElement . dataset . content_root ;
914 if ( _CONTENT_ROOT !== undefined ) {
@@ -20,6 +25,10 @@ const all_languages = $LANGUAGES;
2025const _create_version_select = ( ) => {
2126 const select = document . createElement ( 'select' ) ;
2227 select . className = 'version_select' ;
28+ if ( _IS_LOCAL ) {
29+ select . disabled = true ;
30+ select . title = 'Version switching is disabled in local builds' ;
31+ }
2332
2433 for ( const [ version , title ] of Object . entries ( all_versions ) ) {
2534 const option = document . createElement ( 'option' ) ;
@@ -44,6 +53,10 @@ const _create_language_select = () => {
4453
4554 const select = document . createElement ( 'select' ) ;
4655 select . className = 'language_select' ;
56+ if ( _IS_LOCAL ) {
57+ select . disabled = true ;
58+ select . title = 'Language switching is disabled in local builds' ;
59+ }
4760
4861 for ( const [ language , title ] of Object . entries ( all_languages ) ) {
4962 const option = document . createElement ( 'option' ) ;
@@ -59,10 +72,6 @@ const _create_language_select = () => {
5972const _navigate_to_first_existing = ( urls ) => {
6073 // Navigate to the first existing URL in urls.
6174 for ( const url of urls ) {
62- if ( url . startsWith ( 'file:///' ) ) {
63- window . location . href = url ;
64- return ;
65- }
6675 fetch ( url )
6776 . then ( ( response ) => {
6877 if ( response . ok ) {
@@ -77,6 +86,7 @@ const _navigate_to_first_existing = (urls) => {
7786} ;
7887
7988const _on_version_switch = ( event ) => {
89+ if ( _IS_LOCAL ) return ;
8090 const selected_version = event . target . value ;
8191 // English has no language prefix.
8292 const new_prefix_en = `/${ selected_version } /` ;
@@ -100,6 +110,7 @@ const _on_version_switch = (event) => {
100110} ;
101111
102112const _on_language_switch = ( event ) => {
113+ if ( _IS_LOCAL ) return ;
103114 const selected_language = event . target . value ;
104115 // English has no language prefix.
105116 const new_prefix =
0 commit comments