}
});
+/* Implement "skip to main" button */
+document.querySelector('#skip-to-main').addEventListener('click', e => {
+ e.preventDefault();
+ document.querySelector('main').querySelector('a')?.focus(); // Assumes first focusable element is always <a>
+});
+
/* Implement client-side routing. Handles view logic for /home and /:post routes. */
async function showPage(path) {
// Determine which placeholders to show
/* Set event handlers for client-side routing. */
globalThis.addEventListener('popstate', _ => showPage(location.pathname));
document.addEventListener('click', e => {
- if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
- return; // Use default behavior if any keyboard modifier is applied to the click
+ if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.id === 'skip-to-main') {
+ return; // Use default behavior if any keyboard modifier is applied to the click or it's a special link
}
const anchor = e.target.closest('a');