Skip to content

Commit 811adae

Browse files
committed
fix navbar elements
1 parent b3b302d commit 811adae

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

themes/arm-design-system-hugo-theme/static/js/authentication.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,83 @@ function renderAuthInTopNav() {
243243

244244
}
245245

246+
function setArmAccountLoginButtonLevel() {
247+
const shadowRoot = document.querySelector("arm-top-navigation")?.shadowRoot;
248+
if (!shadowRoot) return;
249+
250+
const loginButton = shadowRoot.querySelector(".c-utility-navigation-login__sign-in-button") ||
251+
Array.from(shadowRoot.querySelectorAll("ads-button, button, a, [role='button']")).find((element) => {
252+
return (element.textContent || "").trim() === "Login";
253+
});
254+
if (!loginButton) return;
255+
256+
if (loginButton.tagName.toLowerCase() === "ads-button") {
257+
loginButton.classList.add("learning-paths-account-login-button");
258+
loginButton.setAttribute("level", "primary");
259+
loginButton.setAttribute("sr-label", "Login");
260+
return;
261+
}
262+
263+
if (loginButton.dataset.learningPathsAdsButtonProxy === "true") return;
264+
265+
const adsButton = document.createElement("ads-button");
266+
adsButton.classList.add("learning-paths-account-login-button");
267+
adsButton.setAttribute("level", "primary");
268+
adsButton.setAttribute("sr-label", "Login");
269+
adsButton.textContent = "Login";
270+
adsButton.addEventListener("click", () => {
271+
document.dispatchEvent(new CustomEvent("arm-account-signin"));
272+
});
273+
274+
loginButton.dataset.learningPathsAdsButtonProxy = "true";
275+
loginButton.replaceWith(adsButton);
276+
}
277+
278+
function setArmAccountLinkColors() {
279+
const shadowRoot = document.querySelector("arm-top-navigation")?.shadowRoot;
280+
if (!shadowRoot) return;
281+
282+
shadowRoot.querySelectorAll(".learning-paths-account-link").forEach((element) => {
283+
element.classList.remove("learning-paths-account-link");
284+
});
285+
286+
const accountHeading = Array.from(shadowRoot.querySelectorAll("*")).find((element) => {
287+
return (element.textContent || "").trim() === "ARM ACCOUNT";
288+
});
289+
if (!accountHeading) return;
290+
291+
let panel = null;
292+
let candidate = accountHeading.parentElement;
293+
while (candidate && candidate !== shadowRoot) {
294+
const text = candidate.textContent || "";
295+
const isAccountPanel = text.includes("ARM ACCOUNT") &&
296+
text.includes("Quick Links") &&
297+
text.includes("Manage Your Account");
298+
const isWholeNavigation = text.includes("Blogs") &&
299+
text.includes("CPU & Hardware") &&
300+
text.includes("Documentation");
301+
302+
if (isAccountPanel && !isWholeNavigation) {
303+
panel = candidate;
304+
break;
305+
}
306+
307+
candidate = candidate.parentElement;
308+
}
309+
if (!panel) return;
310+
311+
panel.querySelectorAll("a, [role='link']").forEach((element) => {
312+
element.classList.add("learning-paths-account-link");
313+
});
314+
}
315+
316+
function scheduleArmAccountPanelUpdates() {
317+
[0, 100, 250, 500, 1000].forEach((delay) => {
318+
window.setTimeout(setArmAccountLoginButtonLevel, delay);
319+
window.setTimeout(setArmAccountLinkColors, delay);
320+
});
321+
}
322+
246323
function applyTopNavHighlightColor() {
247324
const topnav = document.querySelector("arm-top-navigation");
248325
const shadowRoot = topnav?.shadowRoot;
@@ -315,6 +392,27 @@ function applyTopNavHighlightColor() {
315392
background-color: ${highlightColor} !important;
316393
border-color: ${highlightColor} !important;
317394
}
395+
396+
ads-button.learning-paths-account-login-button {
397+
display: block;
398+
margin-top: 1rem;
399+
margin-bottom: 1.5rem;
400+
width: 100%;
401+
}
402+
403+
.learning-paths-account-link,
404+
.learning-paths-account-link * {
405+
color: ${highlightColor} !important;
406+
-webkit-text-fill-color: ${highlightColor} !important;
407+
}
408+
409+
.learning-paths-account-link:hover,
410+
.learning-paths-account-link:hover *,
411+
.learning-paths-account-link:focus-visible,
412+
.learning-paths-account-link:focus-visible * {
413+
color: #00C1DE !important;
414+
-webkit-text-fill-color: #00C1DE !important;
415+
}
318416
`;
319417
shadowRoot.appendChild(style);
320418
}
@@ -399,9 +497,17 @@ document.addEventListener("arm-top-navigation-ready", function (e) {
399497

400498
window.requestAnimationFrame(applyTopNavHighlightColor);
401499
window.setTimeout(applyTopNavHighlightColor, 250);
500+
window.requestAnimationFrame(setArmAccountLoginButtonLevel);
501+
window.requestAnimationFrame(setArmAccountLinkColors);
502+
scheduleArmAccountPanelUpdates();
402503
renderAuthInTopNav();
403504
});
404505

506+
document.addEventListener("click", function (event) {
507+
if (!event.target.closest("arm-top-navigation")) return;
508+
scheduleArmAccountPanelUpdates();
509+
});
510+
405511
function scheduleTopNavHighlightColor() {
406512
[0, 250, 1000].forEach((delay) => {
407513
window.setTimeout(applyTopNavHighlightColor, delay);

0 commit comments

Comments
 (0)