Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit a1f7863

Browse files
committed
Responsive menu streamlining
1 parent 3511f71 commit a1f7863

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

src/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
1818
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
1919
</div>
20+
<button id="responsive-menu-toggle"><?php _e( 'Menu', 'voidx' ); ?></button>
2021
<nav id="site-navigation" class="site-navigation">
21-
<button id="responsive-menu-toggle"><?php _e( 'Menu', 'voidx' ); ?></button>
2222
<div id="responsive-menu"><?php wp_nav_menu( array( 'theme_location' => 'header', 'menu_id' => 'menu-header', 'menu_class' => 'menu-inline' ) ); ?></div>
2323
</nav>
2424
</header>

src/js/responsive-menu.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==== RESPONSIVE NAVIGATION MENU ==== //
1+
// ==== RESPONSIVE MENU ==== //
22

33
// Menu toggle script adapted from _s: https://github.com/Automattic/_s
44
;(function() {
@@ -19,16 +19,12 @@
1919

2020
// Toggle navigation; add or remove a class to both the button and the nav element itself
2121
button.onclick = function() {
22-
if (button.className.indexOf( 'toggled' ) !== -1) {
23-
button.className = button.className.replace(' toggled', '');
22+
if (button.className.indexOf( 'active' ) !== -1) {
23+
nav.style.display = 'none';
24+
button.className = button.className.replace(' active', '');
2425
} else {
25-
button.className += ' toggled';
26-
}
27-
28-
if (menu.className.indexOf( 'toggled' ) !== -1) {
29-
menu.className = menu.className.replace(' toggled', '');
30-
} else {
31-
menu.className += ' toggled';
26+
nav.style.display = 'block';
27+
button.className += ' active';
3228
}
3329
};
3430
} )();

src/scss/_layout.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@
7171
@extend %spacer-below-2;
7272
}
7373
}
74+
.site-navigation {
75+
display: none;
76+
@include media-above($break-medium) {
77+
display: block !important; // Handles an edge case where user resizes after menu is hidden on smaller screens
78+
}
79+
&.active {
80+
display: block;
81+
}
82+
}
7483
.alignright {
7584
float: right;
7685
}

src/scss/_menus.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,9 @@
2020
}
2121
}
2222

23-
// Responsive header menu; this container ID handles the fact that `wp_nav_menu()` defaults back to `wp_page_menu()` when no menu is active
24-
#responsive-menu {
25-
display: none;
26-
@include media-above($break-medium) {
27-
display: block;
28-
}
29-
&.toggled {
30-
display: block;
31-
}
32-
}
33-
3423
// Menu toggle for mobile phones and small screens
3524
#responsive-menu-toggle {
3625
@include media-above($break-medium) {
3726
display: none;
3827
}
39-
&.toggled {
40-
display: none;
41-
}
4228
}

0 commit comments

Comments
 (0)