Skip to content

Commit 0bc3544

Browse files
sorin-davidoiMichael-F-Bryan
authored andcommitted
refactor: Remove store.js (use localStorage) (#550)
1 parent c89245b commit 0bc3544

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ impl HtmlHandlebars {
161161
self.write_file(destination, "ayu-highlight.css", &theme.ayu_highlight_css)?;
162162
self.write_file(destination, "highlight.js", &theme.highlight_js)?;
163163
self.write_file(destination, "clipboard.min.js", &theme.clipboard_js)?;
164-
self.write_file(destination, "store.js", &theme.store_js)?;
165164
self.write_file(
166165
destination,
167166
"_FontAwesome/css/font-awesome.css",

src/theme/book.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,14 @@ function playpen_text(playpen) {
331331
});
332332
}
333333

334-
store.set('mdbook-theme', theme);
334+
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
335335

336336
document.body.className = theme;
337337
}
338338

339339
// Set theme
340-
var theme = store.get('mdbook-theme');
340+
var theme;
341+
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
341342
if (theme === null || theme === undefined) { theme = 'light'; }
342343

343344
set_theme(theme);
@@ -387,7 +388,7 @@ function playpen_text(playpen) {
387388
});
388389
sidebarToggleButton.setAttribute('aria-expanded', true);
389390
sidebar.setAttribute('aria-hidden', false);
390-
store.set('mdbook-sidebar', 'visible');
391+
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
391392
}
392393

393394
function hideSidebar() {
@@ -398,7 +399,7 @@ function playpen_text(playpen) {
398399
});
399400
sidebarToggleButton.setAttribute('aria-expanded', false);
400401
sidebar.setAttribute('aria-hidden', true);
401-
store.set('mdbook-sidebar', 'hidden');
402+
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
402403
}
403404

404405
// Toggle sidebar

src/theme/index.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@
4141
}
4242
</script>
4343

44-
<!-- Fetch store.js from local - TODO add CDN when 2.x.x is available on cdnjs -->
45-
<script src="store.js"></script>
46-
4744
</head>
4845
<body class="light">
4946
<!-- Set the theme before any content is loaded, prevents flash -->
5047
<script type="text/javascript">
51-
var theme = store.get('mdbook-theme');
48+
var theme;
49+
try { theme = store.get('mdbook-theme'); } catch(e) { }
5250
if (theme === null || theme === undefined) { theme = 'light'; }
5351
document.body.className = theme;
5452
</script>
5553

5654
<!-- Hide / unhide sidebar before it is displayed -->
5755
<script type="text/javascript">
5856
var sidebar = 'hidden';
59-
if (document.body.clientWidth >= 1080)
60-
sidebar = store.get('mdbook-sidebar') || 'visible';
57+
if (document.body.clientWidth >= 1080) {
58+
try { sidebar = store.get('mdbook-sidebar'); } catch(e) { }
59+
sidebar = sidebar || 'visible';
60+
}
6161
document.querySelector('html').classList.add("sidebar-" + sidebar);
6262
</script>
6363

src/theme/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.cs
1717
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
1818
pub static AYU_HIGHLIGHT_CSS: &'static [u8] = include_bytes!("ayu-highlight.css");
1919
pub static CLIPBOARD_JS: &'static [u8] = include_bytes!("clipboard.min.js");
20-
pub static STORE_JS: &'static [u8] = include_bytes!("store.js");
2120
pub static FONT_AWESOME: &'static [u8] = include_bytes!("_FontAwesome/css/font-awesome.min.css");
2221
pub static FONT_AWESOME_EOT: &'static [u8] =
2322
include_bytes!("_FontAwesome/fonts/fontawesome-webfont.eot");
@@ -50,7 +49,6 @@ pub struct Theme {
5049
pub ayu_highlight_css: Vec<u8>,
5150
pub highlight_js: Vec<u8>,
5251
pub clipboard_js: Vec<u8>,
53-
pub store_js: Vec<u8>,
5452
}
5553

5654
impl Theme {
@@ -73,7 +71,6 @@ impl Theme {
7371
(theme_dir.join("favicon.png"), &mut theme.favicon),
7472
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
7573
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
76-
(theme_dir.join("store.js"), &mut theme.store_js),
7774
(theme_dir.join("highlight.css"), &mut theme.highlight_css),
7875
(theme_dir.join("tomorrow-night.css"), &mut theme.tomorrow_night_css),
7976
(theme_dir.join("ayu-highlight.css"), &mut theme.ayu_highlight_css),
@@ -107,7 +104,6 @@ impl Default for Theme {
107104
ayu_highlight_css: AYU_HIGHLIGHT_CSS.to_owned(),
108105
highlight_js: HIGHLIGHT_JS.to_owned(),
109106
clipboard_js: CLIPBOARD_JS.to_owned(),
110-
store_js: STORE_JS.to_owned(),
111107
}
112108
}
113109
}
@@ -178,7 +174,6 @@ mod tests {
178174
ayu_highlight_css: Vec::new(),
179175
highlight_js: Vec::new(),
180176
clipboard_js: Vec::new(),
181-
store_js: Vec::new(),
182177
};
183178

184179
assert_eq!(got, empty);

0 commit comments

Comments
 (0)