Skip to content

refactor: Remove store.js (use localStorage) #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@
}
</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>

<!-- 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>

Expand Down
5 changes: 0 additions & 5 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Loading