feat: keyboard shortcut to toggle sidebar
This commit is contained in:
parent
bd323fb930
commit
f07ee957a5
|
@ -77,6 +77,21 @@
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{{!-- Add Ctrl + Shift + S as a shortcut to toggle the sidebar. --}}
|
||||||
|
<script>
|
||||||
|
document.addEventListener('keydown', function({ ctrlKey, key, shiftKey }) {
|
||||||
|
if (ctrlKey && shiftKey && key === 'S') {
|
||||||
|
const sidebar = document.getElementById('sidebar-toggle-anchor');
|
||||||
|
sidebar.checked = !sidebar.checked;
|
||||||
|
localStorage.setItem('mdbook-sidebar', sidebar.checked ? 'visible' : 'hidden');
|
||||||
|
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar.checked ? 'false' : 'true');
|
||||||
|
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
||||||
|
link.setAttribute('tabIndex', sidebar.checked ? 0 : -1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||||
<script>
|
<script>
|
||||||
var theme;
|
var theme;
|
||||||
|
|
Loading…
Reference in New Issue