<script>
jQuery(document).ready(function($) {
var screenWidth = $(window).width();
if (screenWidth <= 768) {
$('.brx-submenu-toggle').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var $submenu = $(this).next('.brx-dropdown-content');
var submenuTitle = $(this).find('span').text();
var $menuHeight = $submenu.outerHeight();
$('.brx-nav-nested-items').css('height', $menuHeight); // Fixed the selector from 'brx-nav-nested-items' to '.brx-nav-nested-items'
$('.nav-menu-link').addClass('li-is-active');
$submenu.addClass('is-active');
if ($submenu.find('.back-btn').length === 0) {
var submenuLink = $submenu.find('h3 a').attr('href');
var submenuTitle = $submenu.find('h3 a').text();
$submenu.prepend('<li class="back-btn"><i class="ion-ios-arrow-back"></i><a href="' + submenuLink + '">' + submenuTitle + '</a></li>');
}
// Change the heading text to "Vezi toate"
var $heading = $submenu.find('h3');
$heading.hide();
});
$(document).on('click', '.back-btn i', function(e) {
e.preventDefault();
var $parentSubMenu = $(this).closest('.brx-dropdown-content');
var $parentSubMenuTitle = $parentSubMenu.find('h3 a').text();
$('.nav-menu-link').removeClass('li-is-active');
$('.brx-nav-nested-items').css('height', 'fit-content');
$parentSubMenu.removeClass('is-active');
});
$(window).scroll(function() {
if ($('header').hasClass('scrolling')) {
$('#mobile-search-top').slideUp();
} else {
$('#mobile-search-top').slideDown();
}
});
}
// Select the target element and create a mutation observer
var target = document.getElementById('brxe-lpnakz');
var observer = new MutationObserver(function(mutationsList, observer) {
for (var mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'aria-expanded') {
var expanded = target.getAttribute('aria-expanded') === 'true';
var menu = document.getElementById('brxe-mbvjdu');
if (expanded) {
menu.style.display = 'flex';
var menuHeight = menu.scrollHeight + 'px';
menu.style.height = '480px';
setTimeout(function() {
menu.style.transition = 'height 0.1s ease-in-out';
menu.style.height = '520px';
}, 50); // Delay to ensure proper height calculation
} else {
menu.style.transition = 'height 0.1s ease-in-out';
menu.style.height = '0px';
setTimeout(function() {
menu.style.display = 'none';
}, 100); // Same duration as transition
}
}
}
});
// Start observing the target node for attribute changes
observer.observe(target, { attributes: true });
});
</script>