mirror of
https://github.com/rust-lang/mdBook
synced 2024-12-14 23:02:34 +00:00
refactor: Remove store.js (use localStorage) (#550)
This commit is contained in:
parent
c89245b45b
commit
0bc3544c81
5 changed files with 11 additions and 18 deletions
|
@ -161,7 +161,6 @@ impl HtmlHandlebars {
|
|||
self.write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
|
||||
self.write_file(destination, "highlight.js", &theme.highlight_js)?;
|
||||
self.write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
|
||||
self.write_file(destination, "store.js", &theme.store_js)?;
|
||||
self.write_file(
|
||||
destination,
|
||||
"_FontAwesome/css/font-awesome.css",
|
||||
|
|
|
@ -331,13 +331,14 @@ function playpen_text(playpen) {
|
|||
});
|
||||
}
|
||||
|
||||
store.set('mdbook-theme', theme);
|
||||
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
|
||||
|
||||
document.body.className = theme;
|
||||
}
|
||||
|
||||
// Set theme
|
||||
var theme = store.get('mdbook-theme');
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = 'light'; }
|
||||
|
||||
set_theme(theme);
|
||||
|
@ -387,7 +388,7 @@ function playpen_text(playpen) {
|
|||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||
sidebar.setAttribute('aria-hidden', false);
|
||||
store.set('mdbook-sidebar', 'visible');
|
||||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||
}
|
||||
|
||||
function hideSidebar() {
|
||||
|
@ -398,7 +399,7 @@ function playpen_text(playpen) {
|
|||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||
sidebar.setAttribute('aria-hidden', true);
|
||||
store.set('mdbook-sidebar', 'hidden');
|
||||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
||||
|
|
|
@ -41,14 +41,12 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
<!-- Fetch store.js from local - TODO add CDN when 2.x.x is available on cdnjs -->
|
||||
<script src="store.js"></script>
|
||||
|
||||
</head>
|
||||
<body class="light">
|
||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||
<script type="text/javascript">
|
||||
var theme = store.get('mdbook-theme');
|
||||
var theme;
|
||||
try { theme = store.get('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = 'light'; }
|
||||
document.body.className = theme;
|
||||
</script>
|
||||
|
@ -56,8 +54,10 @@
|
|||
<!-- Hide / unhide sidebar before it is displayed -->
|
||||
<script type="text/javascript">
|
||||
var sidebar = 'hidden';
|
||||
if (document.body.clientWidth >= 1080)
|
||||
sidebar = store.get('mdbook-sidebar') || 'visible';
|
||||
if (document.body.clientWidth >= 1080) {
|
||||
try { sidebar = store.get('mdbook-sidebar'); } catch(e) { }
|
||||
sidebar = sidebar || 'visible';
|
||||
}
|
||||
document.querySelector('html').classList.add("sidebar-" + sidebar);
|
||||
</script>
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.cs
|
|||
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
|
||||
pub static AYU_HIGHLIGHT_CSS: &'static [u8] = include_bytes!("ayu-highlight.css");
|
||||
pub static CLIPBOARD_JS: &'static [u8] = include_bytes!("clipboard.min.js");
|
||||
pub static STORE_JS: &'static [u8] = include_bytes!("store.js");
|
||||
pub static FONT_AWESOME: &'static [u8] = include_bytes!("_FontAwesome/css/font-awesome.min.css");
|
||||
pub static FONT_AWESOME_EOT: &'static [u8] =
|
||||
include_bytes!("_FontAwesome/fonts/fontawesome-webfont.eot");
|
||||
|
@ -50,7 +49,6 @@ pub struct Theme {
|
|||
pub ayu_highlight_css: Vec<u8>,
|
||||
pub highlight_js: Vec<u8>,
|
||||
pub clipboard_js: Vec<u8>,
|
||||
pub store_js: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Theme {
|
||||
|
@ -73,7 +71,6 @@ impl Theme {
|
|||
(theme_dir.join("favicon.png"), &mut theme.favicon),
|
||||
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
|
||||
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
|
||||
(theme_dir.join("store.js"), &mut theme.store_js),
|
||||
(theme_dir.join("highlight.css"), &mut theme.highlight_css),
|
||||
(theme_dir.join("tomorrow-night.css"), &mut theme.tomorrow_night_css),
|
||||
(theme_dir.join("ayu-highlight.css"), &mut theme.ayu_highlight_css),
|
||||
|
@ -107,7 +104,6 @@ impl Default for Theme {
|
|||
ayu_highlight_css: AYU_HIGHLIGHT_CSS.to_owned(),
|
||||
highlight_js: HIGHLIGHT_JS.to_owned(),
|
||||
clipboard_js: CLIPBOARD_JS.to_owned(),
|
||||
store_js: STORE_JS.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +174,6 @@ mod tests {
|
|||
ayu_highlight_css: Vec::new(),
|
||||
highlight_js: Vec::new(),
|
||||
clipboard_js: Vec::new(),
|
||||
store_js: Vec::new(),
|
||||
};
|
||||
|
||||
assert_eq!(got, empty);
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue