{% set isActive = item.category.id == activeId %}
{% set hasChildren = item.category.visibleChildCount > 0 %}
{% set url = category_url(item.category) %}
{% set name = item.category.translated.name %}
<li class="navigation-offcanvas-list-item offcanvas-custom-menu-li">
{% block layout_navigation_offcanvas_navigation_categories_list_category_item_link %}
<a class="navigation-offcanvas-link nav-item nav-link {% if hasChildren %} js-navigation-offcanvas-link {% else %} js-navigation-offcanvas-link-children {% endif %} {% if parentId == item.category.id %} active {% endif %}"
{% if hasChildren %} onclick="toggleActiveParent(this)" {% else %} onclick="toggleActiveChildren(this)" {% endif %}
href="{{ url }}"
{% if hasChildren %}
data-href="{{ path('frontend.menu.offcanvas', {'navigationId': item.category.id}) }}"
{% endif %}
itemprop="url"
{% if category_linknewtab(item.category) %}target="_blank"{% endif %}
title="{{ name }}">
{% block layout_navigation_offcanvas_navigation_categories_list_category_item_link_text %}
<span itemprop="name">{{ name }}</span>
{% if hasChildren %}
{% block layout_navigation_offcanvas_navigation_categories_list_category_item_link_icon %}
<span
class="navigation-offcanvas-link-icon">
{% sw_icon 'arrow-right-menu' %}
</span>
{% endblock %}
{% endif %}
{% endblock %}
</a>
<script>
function toggleActiveParent(link){
if (!link.classList.contains('active')) {
var links = document.querySelectorAll('.js-navigation-offcanvas-link');
links.forEach(function (el) {
el.classList.remove('active');
});
link.classList.add('active');
}
else
{
var links = document.querySelectorAll('.js-navigation-offcanvas-link');
links.forEach(function (el) {
el.classList.remove('active');
});
setTimeout(function() {
var overlayDiv = document.querySelector('.has-transition');
if (overlayDiv) {
overlayDiv.parentNode.removeChild(overlayDiv);
}
}, 500);
}
}
function toggleActiveChildren(link){
link.classList.toggle('active');
var childrenLinks = document.querySelectorAll('.js-navigation-offcanvas-link-children');
childrenLinks.forEach(function (el) {
el.classList.remove('active');
});
}
</script>
{% endblock %}
</li>