Repository navigation
Expand file tree
/
Copy pathchrome.js
More file actions
59 lines (52 loc) · 2.87 KB
/
Copy pathchrome.js
File metadata and controls
59 lines (52 loc) · 2.87 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
/* chrome.js — shared site chrome (nav + footer) injected on every page,
so the menu lives in one place instead of being copy-pasted per file.
Also wires keyboard activation for the site's role="button" controls.
Markup contract:
<nav data-nav></nav> site nav (same width on every page)
<footer data-footer></footer> standard footer
The active link is derived from the current filename.
The nav is intentionally locked to one container width on all pages so the
brand and links never shift when navigating — even on the wide content
pages (finder, compare). */
(function(){
var LINKS = [
{ href: "index.html", label: "Watches" },
{ href: "finder.html", label: "Find your watch" },
{ href: "compare.html", label: "Compare" },
{ href: "activations.html", label: "Activations" },
{ href: "skus.html", label: "SKUs" }
];
function page(){ return location.pathname.split("/").pop() || "index.html"; }
function navHTML(){
var here = page();
var links = LINKS.map(function(l){
return '<a href="' + l.href + '"' + (l.href === here ? ' class="active"' : '') + '>' + l.label + '</a>';
}).join("");
var CART_ICON = '<svg class="carticon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="9" cy="20.5" r="1.6"/><circle cx="18" cy="20.5" r="1.6"/><path d="M2.5 3.5h2.6l2.2 11.6a1.9 1.9 0 0 0 1.9 1.6h8.3a1.9 1.9 0 0 0 1.9-1.6l1.6-8.1H6"/></svg>';
links += '<a href="cart.html" class="baglink' + (here === "cart.html" ? " active" : "") +
'" aria-label="Cart" title="Cart">' + CART_ICON + '<span class="cartbadge" data-cart-count></span></a>';
var brand = (here === "index.html")
? '<div class="brand">▲ NOT-A-GARMIN</div>'
: '<div class="brand"><a href="index.html" style="color:inherit">▲ NOT-A-GARMIN</a></div>';
return '<div class="wrap">' + brand + '<div class="links">' + links + "</div></div>";
}
var FOOTER = '<div class="wrap"><div>Concept lineup proposal · not an official NOT-A-GARMIN ' +
'product page. Product images © NOT-A-GARMIN Ltd.</div></div>';
function mount(){
var nav = document.querySelector("[data-nav]");
if (nav) nav.innerHTML = navHTML();
var ft = document.querySelector("[data-footer]");
if (ft) ft.innerHTML = FOOTER;
}
/* Keyboard support: the configurator and accordions use role="button" divs.
Enter / Space should activate them the way a real button would. */
document.addEventListener("keydown", function(e){
if (e.key !== "Enter" && e.key !== " " && e.key !== "Spacebar") return;
var t = e.target;
if (t && t.nodeType === 1 && t.getAttribute("role") === "button" && t.hasAttribute("tabindex")){
e.preventDefault();
t.click();
}
});
mount();
})();