Files
2026-06-01 18:08:37 -04:00

74 lines
2.6 KiB
PHP

<?php
$_nav_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
function _nav_active(string $href): bool {
global $_nav_path;
return $href === '/'
? ($_nav_path === '/' || $_nav_path === '/index.php')
: strpos($_nav_path, $href) === 0;
}
$_nav_pages = [
'/about/' => 'About',
'/log/' => 'Log',
'/links/' => 'Links',
'/projects/' => 'Projects',
'/contact/' => 'Contact',
];
?>
<div id="grain"></div>
<nav class="site-nav">
<div class="nav-inner">
<a href="/" class="nav-brand">Sistav</a>
<div class="nav-links">
<?php foreach ($_nav_pages as $href => $label): ?>
<a href="<?= $href ?>"<?= _nav_active($href) ? ' class="nav-active"' : '' ?>><?= $label ?></a>
<?php endforeach; ?>
</div>
<button id="nav-toggle" class="nav-toggle-btn" aria-label="Toggle menu" aria-expanded="false">
<svg id="nav-icon-open" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 6h16M4 12h16M4 18h16"/>
</svg>
<svg id="nav-icon-close" class="nav-hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</div>
<div id="nav-mobile" class="nav-mobile nav-hidden">
<div class="nav-mobile-inner">
<?php foreach ($_nav_pages as $href => $label): ?>
<a href="<?= $href ?>"<?= _nav_active($href) ? ' class="nav-active"' : '' ?>><?= $label ?></a>
<?php endforeach; ?>
</div>
</div>
</nav>
<script>
(function () {
var toggle = document.getElementById('nav-toggle');
var mobile = document.getElementById('nav-mobile');
var iconOpen = document.getElementById('nav-icon-open');
var iconClose = document.getElementById('nav-icon-close');
function closeMenu() {
mobile.classList.add('nav-hidden');
iconOpen.classList.remove('nav-hidden');
iconClose.classList.add('nav-hidden');
toggle.setAttribute('aria-expanded', 'false');
}
toggle.addEventListener('click', function () {
var justHid = mobile.classList.toggle('nav-hidden');
iconOpen.classList.toggle('nav-hidden', !justHid);
iconClose.classList.toggle('nav-hidden', justHid);
toggle.setAttribute('aria-expanded', String(!justHid));
});
mobile.querySelectorAll('a').forEach(function (link) {
link.addEventListener('click', closeMenu);
});
})();
</script>