88const darkThemes = [ "dark" , "ayu" ] ;
99window . currentTheme = document . getElementById ( "themeStyle" ) ;
1010
11- // WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
12- // If you update this line, then you also need to update the media query with the same
13- // warning in rustdoc.css
14- window . RUSTDOC_MOBILE_BREAKPOINT = 700 ;
15-
1611const settingsDataset = ( function ( ) {
1712 const settingsElement = document . getElementById ( "default-settings" ) ;
18- if ( settingsElement === null ) {
19- return null ;
20- }
21- const dataset = settingsElement . dataset ;
22- if ( dataset === undefined ) {
23- return null ;
24- }
25- return dataset ;
13+ return settingsElement && settingsElement . dataset ? settingsElement . dataset : null ;
2614} ) ( ) ;
2715
2816function getSettingValue ( settingName ) {
2917 const current = getCurrentValue ( settingName ) ;
30- if ( current !== null ) {
31- return current ;
32- }
33- if ( settingsDataset !== null ) {
18+ if ( current === null && settingsDataset !== null ) {
3419 // See the comment for `default_settings.into_iter()` etc. in
3520 // `Options::from_matches` in `librustdoc/config.rs`.
3621 const def = settingsDataset [ settingName . replace ( / - / g, "_" ) ] ;
3722 if ( def !== undefined ) {
3823 return def ;
3924 }
4025 }
41- return null ;
26+ return current ;
4227}
4328
4429const localStoredTheme = getSettingValue ( "theme" ) ;
@@ -49,18 +34,16 @@ function hasClass(elem, className) {
4934}
5035
5136function addClass ( elem , className ) {
52- if ( ! elem || ! elem . classList ) {
53- return ;
37+ if ( elem && elem . classList ) {
38+ elem . classList . add ( className ) ;
5439 }
55- elem . classList . add ( className ) ;
5640}
5741
5842// eslint-disable-next-line no-unused-vars
5943function removeClass ( elem , className ) {
60- if ( ! elem || ! elem . classList ) {
61- return ;
44+ if ( elem && elem . classList ) {
45+ elem . classList . remove ( className ) ;
6246 }
63- elem . classList . remove ( className ) ;
6447}
6548
6649/**
@@ -127,11 +110,7 @@ function getCurrentValue(name) {
127110// Rust to the JS. If there is no such element, return null.
128111const getVar = ( function getVar ( name ) {
129112 const el = document . getElementById ( "rustdoc-vars" ) ;
130- if ( el ) {
131- return el . attributes [ "data-" + name ] . value ;
132- } else {
133- return null ;
134- }
113+ return el ? el . attributes [ "data-" + name ] . value : null ;
135114} ) ;
136115
137116function switchTheme ( newThemeName , saveTheme ) {
0 commit comments