|
57 | 57 | displayMode.appendChild(body); |
58 | 58 | slot.replaceWith(displayMode); |
59 | 59 |
|
| 60 | + function roleAwareHref(targetHref) { |
| 61 | + const role = new URLSearchParams(window.location.search).get("role"); |
| 62 | + if (!role || !targetHref) { |
| 63 | + return targetHref; |
| 64 | + } |
| 65 | + |
| 66 | + const targetUrl = new URL(targetHref, window.location.origin + "/"); |
| 67 | + targetUrl.searchParams.set("role", role); |
| 68 | + return targetUrl.pathname.replace(/^\/+/, "") + targetUrl.search + targetUrl.hash; |
| 69 | + } |
| 70 | + |
| 71 | + function createNavigationControl(direction, target) { |
| 72 | + const controlLabel = direction === "previous" ? "Previous Tool" : "Next Tool"; |
| 73 | + const dataAttribute = direction === "previous" ? "toolNavPrevious" : "toolNavNext"; |
| 74 | + |
| 75 | + if (!target || target.disabled) { |
| 76 | + const button = document.createElement("button"); |
| 77 | + button.type = "button"; |
| 78 | + button.className = "btn"; |
| 79 | + button.disabled = true; |
| 80 | + button.dataset[dataAttribute] = "disabled"; |
| 81 | + button.textContent = controlLabel + ": " + (target?.label || "Unavailable"); |
| 82 | + return button; |
| 83 | + } |
| 84 | + |
| 85 | + const link = document.createElement("a"); |
| 86 | + link.className = "btn"; |
| 87 | + link.href = roleAwareHref(target.href); |
| 88 | + link.dataset[dataAttribute] = target.kind; |
| 89 | + if (target.group) { |
| 90 | + link.dataset.toolNavGroup = target.group; |
| 91 | + } |
| 92 | + link.textContent = controlLabel + ": " + target.label; |
| 93 | + return link; |
| 94 | + } |
| 95 | + |
| 96 | + async function renderToolNavigation() { |
| 97 | + try { |
| 98 | + const registry = await import("/toolbox/toolRegistry.js"); |
| 99 | + const navigation = registry.getToolNavigationTargets(toolSlug); |
| 100 | + const navigationRow = document.createElement("nav"); |
| 101 | + navigationRow.className = "content-cluster"; |
| 102 | + navigationRow.setAttribute("aria-label", "Tool build-order navigation"); |
| 103 | + navigationRow.append( |
| 104 | + createNavigationControl("previous", navigation.previous), |
| 105 | + createNavigationControl("next", navigation.next) |
| 106 | + ); |
| 107 | + body.appendChild(navigationRow); |
| 108 | + } catch (error) { |
| 109 | + console.warn("Tool navigation could not be loaded.", error); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + renderToolNavigation(); |
60 | 114 |
|
61 | 115 | async function enterToolMode() { |
62 | 116 | document.body.classList.add("tool-focus-mode"); |
|
0 commit comments