refactor: externalize navigation handlers and fix hyperscript syntax errors

- Created keyboard._hs as reference documentation (inline handler in body tag)
- Externalized 9 hamburger menu navigation links to scrollToSection()
- Added scrollToSection() as JavaScript function (CSP-safe, no eval needed)
- Restored original keyboard handler format in body tag (working correctly)
- Removed problematic navigation._hs (had syntax/CSP issues)
- Added Rule 4 to HYPERSCRIPT-RULES.md on event handler externalization
- Updated PROJECT-MEMORY.md with externalization guidelines

Key learnings:
- Complex event handlers that inspect event properties must stay inline
- JavaScript functions avoid CSP unsafe-eval restrictions
- Navigation successfully externalized: 9 links → 1 function (91% reduction)
This commit is contained in:
juanatsap
2025-11-20 09:17:09 +00:00
parent 27f5e8eb79
commit 925a95c1b4
6 changed files with 236 additions and 42 deletions
+19
View File
@@ -85,6 +85,21 @@ function highlightZoomControl(show) {
}
}
/**
* Scroll to Section
* @param {Event} event - The click event (for preventDefault)
* @param {string} sectionId - The ID of the section to scroll to
*/
function scrollToSection(event, sectionId) {
if (event) {
event.preventDefault();
}
const element = document.getElementById(sectionId);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
// Make functions globally available for hyperscript `call` command
window.toggleCVLength = toggleCVLength;
window.toggleIcons = toggleIcons;
@@ -92,3 +107,7 @@ window.toggleTheme = toggleTheme;
window.syncPdfHover = syncPdfHover;
window.syncPrintHover = syncPrintHover;
window.highlightZoomControl = highlightZoomControl;
window.scrollToSection = scrollToSection;
// Note: handleGlobalKeydown() is defined in keyboard._hs as reference only
// The actual keyboard handler is inline in templates/index.html (body tag)