diff --git a/functions.php b/functions.php
index d4f57be..b4a3c68 100644
--- a/functions.php
+++ b/functions.php
@@ -12,9 +12,9 @@ require_once(__DIR__ . '/includes/social-networks.php');
require_once(__DIR__ . '/includes/forms.php');
require_once(__DIR__ . '/includes/rapport-activites.php');
require_once(__DIR__ . '/includes/equipe.php');
-
+require_once(__DIR__ . '/includes/navwalker.php');
// require_once(__DIR__ . '/includes/widget.php');
// require_once( __DIR__ . '/includes/taxonomy.php');
// require_once( __DIR__ . '/includes/errorlog.php');
-// require_once( __DIR__ . '/includes/logos.php');
\ No newline at end of file
+// require_once( __DIR__ . '/includes/logos.php');
diff --git a/includes/navwalker.php b/includes/navwalker.php
index 7b9bdb0..78865ae 100644
--- a/includes/navwalker.php
+++ b/includes/navwalker.php
@@ -1,28 +1,93 @@
theme_location === "secondary" && in_array('menu-item-has-children', $item->classes, true)) {
- function start_lvl(&$output, $depth = 0, $args = null)
- {
-
- $tmp_class = "child-" . $depth;
-
- $output .= "
";
-
+ $output = '';
}
- function start_el(&$output, $item, $depth = 0, $args = null, $id = 0)
- {
+ return $output;
+}
+add_filter('walker_nav_menu_start_el', 'wrap_parent_menu_item_buttons', 10, 4);
- $output .= "- I like pie" . $item->title;
- // var_dump($args);
+
+/* ----------------------------------------------------------------
+ ##### Adds option 'li_class' to 'wp_nav_menu
+ ------------------------------------------------------------------*/
+
+function tailpress_nav_menu_add_li_class($classes, $item, $args, $depth)
+{
+ if (isset($args->li_class)) {
+ $classes[] = $args->li_class;
}
- function end_el(&$output, $item, $depth = 0, $args = null)
- {
- $output .= "...
";
+ if (isset($args->{"li_class_$depth"})) {
+ $classes[] = $args->{"li_class_$depth"};
}
-}
\ No newline at end of file
+ return $classes;
+}
+
+add_filter('nav_menu_css_class', 'tailpress_nav_menu_add_li_class', 10, 4);
+
+
+
+/* ----------------------------------------------------------------
+ ##### Adds option 'submenu_class' to 'wp_nav_menu'
+ ------------------------------------------------------------------*/
+
+function tailpress_nav_menu_add_submenu_class($classes, $args, $depth)
+{
+ if (isset($args->submenu_class)) {
+ $classes[] = $args->submenu_class;
+ }
+
+ if (isset($args->{"submenu_class_$depth"})) {
+ $classes[] = $args->{"submenu_class_$depth"};
+ }
+
+ return $classes;
+}
+
+add_filter('nav_menu_submenu_css_class', 'tailpress_nav_menu_add_submenu_class', 10, 3);
+
+/* ----------------------------------------------------------------
+ ##### Inject ACF page_icon into submenu items
+ ------------------------------------------------------------------*/
+function carhop_add_submenu_item_icon($output, $item, $depth, $args)
+{
+ // Only for submenu items (depth >= 1
+ if (!isset($args->theme_location) || $args->theme_location !== 'secondary' || $depth < 1 || !function_exists('get_field')) {
+ return $output;
+ }
+
+ // Try fetching the icon from the menu item itself, then fallback to linked object (e.g., page)
+ $pageIcon = get_field('page_icon', $item->object_id);
+
+ if (empty($pageIcon)) {
+ return $output;
+ }
+
+
+ $icon_html = '';
+ $excerpt_html = '';
+ // Attachment array with ID (ACF image field)
+ if (is_array($pageIcon) && isset($pageIcon['url'])) {
+ $icon_html = '';
+ }
+
+ if (has_excerpt($item->object_id)) {
+ $excerpt_html = '';
+ }
+
+
+ return '';
+}
+add_filter('walker_nav_menu_start_el', 'carhop_add_submenu_item_icon', 15, 4);
diff --git a/resources/js/header.js b/resources/js/header.js
index 9b5c7f3..e64b668 100644
--- a/resources/js/header.js
+++ b/resources/js/header.js
@@ -1,61 +1,49 @@
export default function menuInit() {
- let main_navigation =
- document.querySelector('#primary-menu');
+ let main_navigation = document.querySelector('#primary-menu');
const header = document.querySelector('#primary-header');
- const primary_menu =
- header.querySelector('#primary-menu');
- const burgerMenuToggle = header.querySelector(
- '#burger-menu-toggle'
- );
- const submenuToggles = primary_menu.querySelectorAll(
- '.menu-item-submenu-toggle'
- );
+ const primary_menu = header.querySelector('#primary-menu');
+ const burgerMenuToggle = header.querySelector('#burger-menu-toggle');
+ const submenuToggles = header.querySelectorAll('.menu-item__submenu-toggle');
+
+ console.log(submenuToggles);
// #### Open/close burger nav
- burgerMenuToggle.addEventListener('click', function (e) {
- e.preventDefault();
- header.classList.toggle('nav-open');
- burgerMenuToggle.toggleAttribute('aria-expanded');
- gsap.from(primary_menu, {
- opacity: 20,
- y: '-100vh',
- duration: 0.5,
- ease: Power4.easeOut,
- });
- });
+ // burgerMenuToggle.addEventListener('click', function (e) {
+ // e.preventDefault();
+ // header.classList.toggle('nav-open');
+ // burgerMenuToggle.toggleAttribute('aria-expanded');
+ // gsap.from(primary_menu, {
+ // opacity: 20,
+ // y: '-100vh',
+ // duration: 0.5,
+ // ease: Power4.easeOut,
+ // });
+ // });
- // #### Close nav when reaching the end of the menu with tab
- document.addEventListener(
- 'focusin',
- (e) => {
- const header = document.querySelector(
- '#primary-header'
- );
- if (
- header.classList.contains('nav-open') &&
- !header.contains(document.activeElement)
- ) {
- header.classList.remove('nav-open');
- burgerMenuToggle.setAttribute(
- 'aria-expanded',
- false
- );
+ // // #### Close nav when reaching the end of the menu with tab
+ // document.addEventListener(
+ // 'focusin',
+ // (e) => {
+ // const header = document.querySelector('#primary-header');
+ // if (
+ // header.classList.contains('nav-open') &&
+ // !header.contains(document.activeElement)
+ // ) {
+ // header.classList.remove('nav-open');
+ // burgerMenuToggle.setAttribute('aria-expanded', false);
- burgerMenuToggle.focus();
- }
- },
- true
- );
+ // burgerMenuToggle.focus();
+ // }
+ // },
+ // true
+ // );
submenuToggles.forEach((button) => {
button.addEventListener('click', function (e) {
- let isExpanded =
- button.getAttribute('aria-expanded') === 'true';
+ let isExpanded = button.getAttribute('aria-expanded') === 'true';
button.setAttribute('aria-expanded', !isExpanded);
- button.parentElement
- .querySelector('.sub-menu')
- .classList.toggle('sub-menu-open');
+ button.parentElement.querySelector('.sub-menu').classList.toggle('sub-menu-open');
});
});
}