-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (53 loc) · 1.92 KB
/
Copy pathscript.js
File metadata and controls
61 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file Main Navigation Controller
* @description Handles the site-wide navigation menu with keyboard support,
* loading states, and error handling.
*
* Hook emitted: H53:NavChange — when user navigates to a new section
*/
(function () {
"use strict";
const menu = document.getElementById("menu");
if (!menu) {
console.error("Navigation menu element not found");
return;
}
/**
* Navigate to the selected page.
* Sanitizes the value to prevent XSS — only allows alphanumeric characters and underscores.
* @param {string} value - The directory name to navigate to
*/
function navigateTo(value) {
if (!value || value.trim() === "") {
console.error("Invalid selection: empty value");
return;
}
// Sanitize: only allow alphanumeric, hyphens, and underscores
const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "");
if (sanitized !== value || sanitized.length === 0) {
console.error("Invalid selection: contains disallowed characters");
return;
}
// H53:NavChange hook (custom event for web hook integration)
document.dispatchEvent(new CustomEvent("hook:H53:NavChange", {
detail: {
from: window.location.pathname,
to: "./" + sanitized + "/index.html"
}
}));
window.location.href = "./" + sanitized + "/index.html";
}
// Handle menu change events
menu.addEventListener("change", function (e) {
const selectedValue = e.target.value;
navigateTo(selectedValue);
});
// Keyboard navigation: Enter key on focused menu triggers navigation
menu.addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault();
const selectedValue = menu.value;
navigateTo(selectedValue);
}
});
})();