refactor: Remove store.js (use localStorage) (#550)
This commit is contained in:
parent
c89245b45b
commit
0bc3544c81
|
@ -161,7 +161,6 @@ impl HtmlHandlebars {
|
||||||
self.write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
|
self.write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
|
||||||
self.write_file(destination, "highlight.js", &theme.highlight_js)?;
|
self.write_file(destination, "highlight.js", &theme.highlight_js)?;
|
||||||
self.write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
|
self.write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
|
||||||
self.write_file(destination, "store.js", &theme.store_js)?;
|
|
||||||
self.write_file(
|
self.write_file(
|
||||||
destination,
|
destination,
|
||||||
"_FontAwesome/css/font-awesome.css",
|
"_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;
|
document.body.className = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set 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'; }
|
if (theme === null || theme === undefined) { theme = 'light'; }
|
||||||
|
|
||||||
set_theme(theme);
|
set_theme(theme);
|
||||||
|
@ -387,7 +388,7 @@ function playpen_text(playpen) {
|
||||||
});
|
});
|
||||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||||
sidebar.setAttribute('aria-hidden', false);
|
sidebar.setAttribute('aria-hidden', false);
|
||||||
store.set('mdbook-sidebar', 'visible');
|
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSidebar() {
|
function hideSidebar() {
|
||||||
|
@ -398,7 +399,7 @@ function playpen_text(playpen) {
|
||||||
});
|
});
|
||||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||||
sidebar.setAttribute('aria-hidden', true);
|
sidebar.setAttribute('aria-hidden', true);
|
||||||
store.set('mdbook-sidebar', 'hidden');
|
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle sidebar
|
// Toggle sidebar
|
||||||
|
|
|
@ -41,14 +41,12 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Fetch store.js from local - TODO add CDN when 2.x.x is available on cdnjs -->
|
|
||||||
<script src="store.js"></script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="light">
|
<body class="light">
|
||||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||||
<script type="text/javascript">
|
<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'; }
|
if (theme === null || theme === undefined) { theme = 'light'; }
|
||||||
document.body.className = theme;
|
document.body.className = theme;
|
||||||
</script>
|
</script>
|
||||||
|
@ -56,8 +54,10 @@
|
||||||
<!-- Hide / unhide sidebar before it is displayed -->
|
<!-- Hide / unhide sidebar before it is displayed -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var sidebar = 'hidden';
|
var sidebar = 'hidden';
|
||||||
if (document.body.clientWidth >= 1080)
|
if (document.body.clientWidth >= 1080) {
|
||||||
sidebar = store.get('mdbook-sidebar') || 'visible';
|
try { sidebar = store.get('mdbook-sidebar'); } catch(e) { }
|
||||||
|
sidebar = sidebar || 'visible';
|
||||||
|
}
|
||||||
document.querySelector('html').classList.add("sidebar-" + sidebar);
|
document.querySelector('html').classList.add("sidebar-" + sidebar);
|
||||||
</script>
|
</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 HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
|
||||||
pub static AYU_HIGHLIGHT_CSS: &'static [u8] = include_bytes!("ayu-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 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: &'static [u8] = include_bytes!("_FontAwesome/css/font-awesome.min.css");
|
||||||
pub static FONT_AWESOME_EOT: &'static [u8] =
|
pub static FONT_AWESOME_EOT: &'static [u8] =
|
||||||
include_bytes!("_FontAwesome/fonts/fontawesome-webfont.eot");
|
include_bytes!("_FontAwesome/fonts/fontawesome-webfont.eot");
|
||||||
|
@ -50,7 +49,6 @@ pub struct Theme {
|
||||||
pub ayu_highlight_css: Vec<u8>,
|
pub ayu_highlight_css: Vec<u8>,
|
||||||
pub highlight_js: Vec<u8>,
|
pub highlight_js: Vec<u8>,
|
||||||
pub clipboard_js: Vec<u8>,
|
pub clipboard_js: Vec<u8>,
|
||||||
pub store_js: Vec<u8>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
|
@ -73,7 +71,6 @@ impl Theme {
|
||||||
(theme_dir.join("favicon.png"), &mut theme.favicon),
|
(theme_dir.join("favicon.png"), &mut theme.favicon),
|
||||||
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
|
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
|
||||||
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_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("highlight.css"), &mut theme.highlight_css),
|
||||||
(theme_dir.join("tomorrow-night.css"), &mut theme.tomorrow_night_css),
|
(theme_dir.join("tomorrow-night.css"), &mut theme.tomorrow_night_css),
|
||||||
(theme_dir.join("ayu-highlight.css"), &mut theme.ayu_highlight_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(),
|
ayu_highlight_css: AYU_HIGHLIGHT_CSS.to_owned(),
|
||||||
highlight_js: HIGHLIGHT_JS.to_owned(),
|
highlight_js: HIGHLIGHT_JS.to_owned(),
|
||||||
clipboard_js: CLIPBOARD_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(),
|
ayu_highlight_css: Vec::new(),
|
||||||
highlight_js: Vec::new(),
|
highlight_js: Vec::new(),
|
||||||
clipboard_js: Vec::new(),
|
clipboard_js: Vec::new(),
|
||||||
store_js: Vec::new(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(got, empty);
|
assert_eq!(got, empty);
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue