add navigator script

Signed-off-by: Lorenzo Lewis <lorenzo_lewis@icloud.com>
This commit is contained in:
Lorenzo Lewis
2023-07-30 01:46:36 +01:00
parent 571a2b2f2e
commit 61c27e930e
2 changed files with 33 additions and 0 deletions

View File

@@ -123,6 +123,12 @@ export default defineConfig({
editLink: {
baseUrl: 'https://github.com/tauri-apps/tauri-docs/edit/starlight',
},
head: [
{
tag: 'script',
attrs: { src: '/javascript/navigator.js' },
},
],
customCss: ['./src/styles/custom.css'],
sidebar: [
{

View File

@@ -0,0 +1,27 @@
(function chapterNavigation() {
document.addEventListener('keydown', function (e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return;
}
if (window.search && window.search.hasFocus()) {
return;
}
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
var nextButton = document.querySelector('a[rel="next"]');
if (nextButton) {
window.location.href = nextButton.href;
}
break;
case 'ArrowLeft':
e.preventDefault();
var previousButton = document.querySelector('a[rel="prev"]');
if (previousButton) {
window.location.href = previousButton.href;
}
break;
}
});
})();