header.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!-- wp:html -->
  2. <header id="header">
  3. <div class="navbar fixed-top">
  4. <div class="container">
  5. <div class="site-title">
  6. <a href="#nav" class="navbar-brand navbar-right light" aria-controls="nav" title="David A. Windham" rel="home">David A. Windham</a>
  7. </div>
  8. </div>
  9. </div>
  10. </header>
  11. <div class="dw-offcanvas text-bg-blue" tabindex="-1" id="nav" aria-labelledby="navLabel">
  12. <nav class="d-flex justify-content-center" role="navigation">
  13. <ul class="nav list-group list-group-horizontal pt-3 fs-5">
  14. <li class="list-group-item"><a href="/about">About</a></li>
  15. <li class="list-group-item"><a href="/desk">Desk</a></li>
  16. <li class="list-group-item"><a href="/studio">Studio</a></li>
  17. <li class="list-group-item"><a href="/work">Work</a></li>
  18. <span class="dw-nav-underline" aria-hidden="true"></span>
  19. </ul>
  20. </nav>
  21. </div>
  22. <a href="#" class="dw-offcanvas-backdrop" tabindex="-1" aria-hidden="true"></a>
  23. <script>
  24. /* Floating "magic line" underline for the #nav items: one shared underline slides
  25. between items on hover and rests under the current-page item. Positions come from
  26. offset* (layout geometry), unaffected by the offcanvas translateY transform, so it
  27. measures correctly while the panel is closed or mid-slide. Inlined here because the
  28. nav is global but the js bundle (v4-script.min.js) is only enqueued on some pages. */
  29. (function () {
  30. function init() {
  31. var nav = document.querySelector('#nav ul.nav');
  32. if (!nav) return;
  33. var line = nav.querySelector('.dw-nav-underline');
  34. if (!line) return;
  35. var links = Array.prototype.slice.call(nav.querySelectorAll('.list-group-item > a'));
  36. if (!links.length) return;
  37. function rel(el) {
  38. var left = 0, top = 0, node = el;
  39. while (node && node !== nav) { left += node.offsetLeft; top += node.offsetTop; node = node.offsetParent; }
  40. return { left: left, top: top, width: el.offsetWidth, height: el.offsetHeight };
  41. }
  42. function place(el, show) {
  43. var r = rel(el);
  44. line.style.left = r.left + 'px';
  45. line.style.width = r.width + 'px';
  46. line.style.top = (r.top + r.height) + 'px';
  47. line.style.opacity = show ? '1' : '0';
  48. }
  49. function activeLink() {
  50. var here = location.pathname.replace(/\/+$/, '') || '/';
  51. var seg = '/' + (here.split('/')[1] || '');
  52. var exact = null, section = null;
  53. links.forEach(function (a) {
  54. var p = a.pathname.replace(/\/+$/, '') || '/';
  55. if (p === here) exact = a;
  56. if (p === seg) section = a;
  57. });
  58. return exact || section;
  59. }
  60. var active = activeLink();
  61. function rest() { if (active) place(active, true); else line.style.opacity = '0'; }
  62. links.forEach(function (a) { a.addEventListener('mouseenter', function () { place(a, true); }); });
  63. nav.addEventListener('mouseleave', rest);
  64. window.addEventListener('resize', rest);
  65. rest();
  66. }
  67. if (document.readyState !== 'loading') init();
  68. else document.addEventListener('DOMContentLoaded', init);
  69. })();
  70. </script>
  71. <!-- /wp:html -->