Skip to content

Commit d102c2d

Browse files
committed
claude refactor nav js logic
1 parent c2567b7 commit d102c2d

File tree

3 files changed

+41
-63
lines changed

3 files changed

+41
-63
lines changed

src/_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</aside>
1717
{% endif %}
1818

19-
<header id="SiteHeader" class="{% if current_phase == 'landing' %}fixed top-0 z-40 w-full py-4 bg-white lg:py-6 lg:relative{% elsif current_phase == 'archived' %}absolute top-0 z-40 w-full py-4 lg:py-6{% else %}lg:top-0 site-header is-closed lg:is-open{% endif %}">
19+
<header id="SiteHeader" class="{% if current_phase == 'landing' %}fixed top-0 z-40 w-full py-4 bg-white lg:py-6 lg:relative{% elsif current_phase == 'archived' and page.url == '/' %}absolute top-0 z-40 w-full py-4 lg:py-6{% else %}lg:top-0 site-header is-closed lg:is-open{% endif %}">
2020
<div class="wrapper">
2121
<nav class="flex flex-wrap" role="navigation">
2222
<div class="flex items-center justify-between w-full lg:max-w-max lg:flex-1">

src/assets/js/main.js

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,43 @@ const siteNav = document.getElementById('SiteNav');
55

66
if (siteNav) {
77
const navToggler = document.getElementById('NavToggler');
8+
const siteBody = document.getElementById('SiteBody');
9+
const siteHeader = document.getElementById('SiteHeader');
810
const allMenus = siteNav.querySelectorAll('[data-menu-list]');
11+
const navMenuTriggers = document.querySelectorAll('[data-menu-trigger]');
912

10-
navToggler.addEventListener('click', () => {
11-
const siteBody = document.getElementById('SiteBody');
12-
const siteHeader = document.getElementById('SiteHeader');
13-
14-
console.log('Toggling site navigation');
15-
console.log(siteNav.classList.contains('hidden'));
16-
17-
if (siteNav.classList.contains('is-closed')) {
18-
siteNav.classList.replace('is-closed', 'is-open');
19-
siteHeader.classList.replace('is-closed', 'is-open');
20-
navToggler.classList.replace('is-closed', 'is-open');
21-
} else {
22-
siteNav.classList.replace('is-open', 'is-closed');
23-
siteHeader.classList.replace('is-open', 'is-closed');
24-
navToggler.classList.replace('is-open', 'is-closed');
25-
}
13+
const closeAllMenus = () => {
14+
allMenus.forEach(menu => menu.classList.replace('flex', 'hidden'));
15+
navMenuTriggers.forEach(trigger => trigger.setAttribute('aria-expanded', 'false'));
16+
};
2617

27-
/*
28-
Hide the main content and footer when the mobile menu is open.
29-
This allows the menu to be scrollable and limits the DOM for screen readers.
30-
*/
18+
navToggler.addEventListener('click', () => {
19+
const isOpen = siteNav.classList.contains('is-open');
20+
[siteNav, siteHeader, navToggler].forEach(el => {
21+
el.classList.toggle('is-open', !isOpen);
22+
el.classList.toggle('is-closed', isOpen);
23+
});
3124
siteBody.classList.toggle('mobile-nav-open');
3225
});
3326

34-
const navMenuTriggers = document.querySelectorAll('[data-menu-trigger]');
35-
3627
navMenuTriggers.forEach(trigger => {
3728
trigger.addEventListener('click', (evt) => {
3829
evt.preventDefault();
3930
const target = trigger.nextElementSibling;
31+
const willOpen = target.classList.contains('hidden');
4032

41-
navMenuTriggers.forEach((trigger) => {
42-
trigger.setAttribute('aria-expanded', 'false');
43-
});
33+
closeAllMenus();
4434

45-
allMenus.forEach((menu) => {
46-
if (menu !== target) {
47-
menu.classList.replace('flex', 'hidden');
48-
}
49-
});
50-
51-
if (target.classList.contains('hidden')) {
35+
if (willOpen) {
5236
target.classList.replace('hidden', 'flex');
5337
trigger.setAttribute('aria-expanded', 'true');
54-
} else {
55-
target.classList.replace('flex', 'hidden');
56-
trigger.setAttribute('aria-expanded', 'false');
5738
}
5839
});
5940
});
6041

61-
// Close all menus when the user clicks outside
62-
document.addEventListener('click', function (evt) {
63-
if (!siteNav.contains(evt.target) && navToggler !== evt.target) {
64-
// Close all menus if you click outside of menu
65-
allMenus.forEach((menu) => {
66-
menu.classList.replace('flex', 'hidden');
67-
});
68-
69-
navMenuTriggers.forEach((trigger) => {
70-
trigger.setAttribute('aria-expanded', 'false');
71-
});
42+
document.addEventListener('click', (evt) => {
43+
if (!siteNav.contains(evt.target) && evt.target !== navToggler) {
44+
closeAllMenus();
7245
}
7346
});
7447
}

src/index.html

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
title: Welcome to DjangoCon US 2025
55

6-
# Set custom_header for active phase (hero wraps header)
6+
# Set custom_header so homepage controls its own header
77
custom_header: true
88

99
# Featured talks (talks only). Max 6.
@@ -38,16 +38,19 @@
3838
---
3939

4040
{% if site.phase == "active" %}
41+
{%- comment -%} Active: header wrapped in hero section {%- endcomment -%}
4142
<div class="home-hero">
4243
{% include "header.html" %}
4344

44-
{% include 'home/landing-conf-home.html' %}
45-
{% elsif site.phase == "archived" %}
46-
{% include 'home/archived-conf-home.html' %}
47-
{% else %}
48-
{% comment %}
49-
The conference site is fully live
50-
{% endcomment %}
45+
<div id="SiteHero" class="flex justify-center lg:justify-start flex:block wrapper">
46+
<section class="home-hero-content">
47+
<h2 class="pt-8">
48+
Join us for five days of inspiration, education, and networking
49+
</h2>
50+
51+
<p class="py-3 mb-4 text-2xl lg:text-3xl">
52+
September 8-12th, 2025
53+
</p>
5154

5255
<a
5356
href="https://www.ihg.com/voco/hotels/us/en/chicago/chiwp/hoteldetail"
@@ -74,14 +77,16 @@
7477

7578
<img src="/assets/img/theme/hero-wave-invert.svg" class="object-cover object-center w-full h-20 pointer-events-none 2xl:h-auto" role="presentation" />
7679
</div>
77-
{% else %}
78-
{% include "header.html" %}
79-
{% endif %}
80+
{% include 'home/active-conf-home.html' %}
8081

81-
{% if site.phase == "landing" %}
82-
{% include 'home/landing-conf-home.html' %}
8382
{% elsif site.phase == "archived" %}
84-
{% include 'home/archived-conf-home.html' %}
85-
{% elsif site.phase == "active" %}
86-
{% include 'home/active-conf-home.html' %}
83+
{%- comment -%} Archived: standard header {%- endcomment -%}
84+
{% include "header.html" %}
85+
{% include 'home/archived-conf-home.html' %}
86+
87+
{% else %}
88+
{%- comment -%} Landing: standard header {%- endcomment -%}
89+
{% include "header.html" %}
90+
{% include 'home/landing-conf-home.html' %}
91+
8792
{% endif %}

0 commit comments

Comments
 (0)