|
32 | 32 | </head> |
33 | 33 |
|
34 | 34 | <body class="min-h-screen relative"> |
| 35 | + <!-- Which nav section we're in, worked out once so the desktop and mobile |
| 36 | + menus can't drift apart --> |
| 37 | + {% if page.url == '/try' or page.url == '/try/' %}{% assign nav_section = 'try' %} |
| 38 | + {% elsif page.url contains '/examples' %}{% assign nav_section = 'examples' %} |
| 39 | + {% elsif page.url contains '/learn/' %}{% assign nav_section = 'learn' %} |
| 40 | + {% elsif page.url == '/community/' %}{% assign nav_section = 'community' %} |
| 41 | + {% endif %} |
| 42 | + |
35 | 43 | <!-- Navigation --> |
36 | 44 | <nav class="sticky top-0 z-50 border-b-2 border-[var(--surface-border)] bg-[var(--surface-bg)]/90 backdrop-blur-xl"> |
37 | 45 | <div class="max-w-6xl mx-auto px-4 sm:px-6 flex items-center justify-between h-16"> |
|
47 | 55 |
|
48 | 56 | <!-- Desktop links --> |
49 | 57 | <div class="hidden sm:flex items-center gap-8"> |
50 | | - <a href="/try" class="nav-link {% if page.url == '/try/' %}active{% endif %}">Try</a> |
51 | | - <a href="/examples" class="nav-link {% if page.url contains '/examples' %}active{% endif %}">Examples</a> |
52 | | - <a href="/learn/get-started" class="nav-link {% if page.url contains '/learn/' %}active{% endif %}">Learn</a> |
53 | | - <a href="/community" class="nav-link {% if page.url == '/community/' %}active{% endif %}">Community</a> |
| 58 | + <a href="/try" class="nav-link {% if nav_section == 'try' %}active{% endif %}" {% if nav_section == 'try' %}aria-current="page"{% endif %}>Try</a> |
| 59 | + <a href="/examples" class="nav-link {% if nav_section == 'examples' %}active{% endif %}" {% if nav_section == 'examples' %}aria-current="page"{% endif %}>Examples</a> |
| 60 | + <a href="/learn/get-started" class="nav-link {% if nav_section == 'learn' %}active{% endif %}" {% if nav_section == 'learn' %}aria-current="page"{% endif %}>Learn</a> |
| 61 | + <a href="/community" class="nav-link {% if nav_section == 'community' %}active{% endif %}" {% if nav_section == 'community' %}aria-current="page"{% endif %}>Community</a> |
54 | 62 | <a href="https://github.com/ruby2d/ruby2d" class="text-[var(--text-muted)] hover:text-[var(--ruby-red)] transition-colors" aria-label="GitHub"> |
55 | 63 | <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/></svg> |
56 | 64 | </a> |
57 | 65 | </div> |
58 | 66 |
|
59 | 67 | <!-- Mobile hamburger --> |
60 | | - <button id="mobile-menu-btn" class="sm:hidden text-[var(--text-secondary)] hover:text-[var(--ruby-red)] p-1 transition-colors cursor-pointer" aria-label="Menu"> |
| 68 | + <button id="mobile-menu-btn" class="sm:hidden text-[var(--text-secondary)] hover:text-[var(--ruby-red)] p-1 transition-colors cursor-pointer" aria-label="Menu" aria-controls="mobile-menu" aria-expanded="false"> |
61 | 69 | <svg class="w-6 h-6" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"> |
62 | 70 | <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16"/> |
63 | 71 | </svg> |
64 | 72 | </button> |
65 | 73 | </div> |
66 | 74 |
|
67 | 75 | <!-- Mobile menu --> |
68 | | - <div id="mobile-menu" class="sm:hidden hidden border-t-2 border-[var(--surface-border)] bg-[var(--surface-card)]"> |
| 76 | + <div id="mobile-menu" class="sm:hidden hidden absolute top-full inset-x-0 border-t-2 border-[var(--surface-border)] bg-[var(--surface-card)]"> |
69 | 77 | <div class="px-4 py-3 flex flex-col gap-1"> |
70 | | - <a href="/try" class="block px-3 py-2 rounded-xl text-[var(--text-secondary)] hover:text-[var(--ruby-red)] hover:bg-[var(--ruby-glow)] font-semibold text-sm transition-colors">Try</a> |
71 | | - <a href="/examples" class="block px-3 py-2 rounded-xl text-[var(--text-secondary)] hover:text-[var(--ruby-red)] hover:bg-[var(--ruby-glow)] font-semibold text-sm transition-colors">Examples</a> |
72 | | - <a href="/learn/get-started" class="block px-3 py-2 rounded-xl text-[var(--text-secondary)] hover:text-[var(--ruby-red)] hover:bg-[var(--ruby-glow)] font-semibold text-sm transition-colors">Learn</a> |
73 | | - <a href="/community" class="block px-3 py-2 rounded-xl text-[var(--text-secondary)] hover:text-[var(--ruby-red)] hover:bg-[var(--ruby-glow)] font-semibold text-sm transition-colors">Community</a> |
74 | | - <a href="https://github.com/ruby2d/ruby2d" class="block px-3 py-2 rounded-xl text-[var(--text-secondary)] hover:text-[var(--ruby-red)] hover:bg-[var(--ruby-glow)] font-semibold text-sm transition-colors">GitHub</a> |
| 78 | + <a href="/try" class="mobile-nav-link {% if nav_section == 'try' %}current{% endif %}" {% if nav_section == 'try' %}aria-current="page"{% endif %}>Try</a> |
| 79 | + <a href="/examples" class="mobile-nav-link {% if nav_section == 'examples' %}current{% endif %}" {% if nav_section == 'examples' %}aria-current="page"{% endif %}>Examples</a> |
| 80 | + <a href="/learn/get-started" class="mobile-nav-link {% if nav_section == 'learn' %}current{% endif %}" {% if nav_section == 'learn' %}aria-current="page"{% endif %}>Learn</a> |
| 81 | + <a href="/community" class="mobile-nav-link {% if nav_section == 'community' %}current{% endif %}" {% if nav_section == 'community' %}aria-current="page"{% endif %}>Community</a> |
| 82 | + <a href="https://github.com/ruby2d/ruby2d" class="mobile-nav-link">GitHub</a> |
75 | 83 | </div> |
76 | 84 | </div> |
77 | 85 | </nav> |
|
109 | 117 | var menuBtn = document.getElementById('mobile-menu-btn'); |
110 | 118 | var mobileMenu = document.getElementById('mobile-menu'); |
111 | 119 | if (menuBtn && mobileMenu) { |
| 120 | + var isOpen = function() { return !mobileMenu.classList.contains('hidden'); }; |
| 121 | + var setMenu = function(open) { |
| 122 | + mobileMenu.classList.toggle('hidden', !open); |
| 123 | + menuBtn.setAttribute('aria-expanded', open ? 'true' : 'false'); |
| 124 | + }; |
| 125 | + |
112 | 126 | menuBtn.addEventListener('click', function() { |
113 | | - mobileMenu.classList.toggle('hidden'); |
| 127 | + setMenu(!isOpen()); |
| 128 | + }); |
| 129 | + |
| 130 | + // The menu floats over the page, so it needs a way out that isn't the |
| 131 | + // hamburger itself: tap anywhere else, or press Escape. |
| 132 | + document.addEventListener('click', function(e) { |
| 133 | + if (!isOpen()) return; |
| 134 | + if (menuBtn.contains(e.target) || mobileMenu.contains(e.target)) return; |
| 135 | + setMenu(false); |
114 | 136 | }); |
| 137 | + |
| 138 | + // Capture phase, because the Try page's wasm runtime binds its own |
| 139 | + // keydown handler to `window` and consumes plain keys like Escape. |
| 140 | + document.addEventListener('keydown', function(e) { |
| 141 | + if (e.key !== 'Escape' || !isOpen()) return; |
| 142 | + setMenu(false); |
| 143 | + menuBtn.focus(); |
| 144 | + }, true); |
| 145 | + |
| 146 | + // Only on a real width change — mobile browsers fire `resize` while |
| 147 | + // scrolling, as the URL bar hides and shows. |
115 | 148 | window.addEventListener('resize', function() { |
116 | | - if (window.innerWidth >= 640) mobileMenu.classList.add('hidden'); |
| 149 | + if (window.innerWidth >= 640) setMenu(false); |
117 | 150 | }); |
118 | 151 | } |
119 | 152 | </script> |
|
0 commit comments