fix(theme/index): Use localStorage, not store (#574)

* fix(theme/index): Use localStorage, not store

* fix(theme/index): Handle quotes values in localStorage
This commit is contained in:
Sorin Davidoi 2018-01-23 13:30:50 +01:00 committed by Michael Bryan
parent 5379a0bdf8
commit 0531b585e4
1 changed files with 18 additions and 2 deletions

View File

@ -43,10 +43,26 @@
</head>
<body class="light">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script type="text/javascript">
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script type="text/javascript">
var theme;
try { theme = store.get('mdbook-theme'); } catch(e) { }
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = 'light'; }
document.body.className = theme;
</script>
@ -55,7 +71,7 @@
<script type="text/javascript">
var sidebar = 'hidden';
if (document.body.clientWidth >= 1080) {
try { sidebar = store.get('mdbook-sidebar'); } catch(e) { }
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
}
document.querySelector('html').classList.add("sidebar-" + sidebar);