drupal-erable/web/themes/erabletheme/js/erabletheme.js

77 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-11-30 17:33:32 +01:00
/**
* @file
* erabletheme behaviors.
*/
(function (Drupal) {
'use strict';
Drupal.behaviors.erabletheme = {
attach: function (context, settings) {
(function($, window) {
let slickEl = $('.slick-container').children().first().children().first().children().first().children().first();
$(slickEl).slick({
arrows: false,
dots: true,
appendDots: $('#carousel_dots')
});
})(jQuery, window);
2023-12-14 06:01:09 +01:00
//
// Toggle du menu
//
const hamburgerBtn = document.getElementById("hamburger");
2023-12-14 06:01:09 +01:00
const hamburgerIcon = document.querySelector(".burger-icon");
const menu = hamburgerBtn.nextElementSibling;
2023-12-14 06:01:09 +01:00
const menuItems = menu.children;
const opacityDelay = 50;
function toggleMenuItems(action) {
let delay = opacityDelay;
for (let i = 0; i < menuItems.length; i++) {
setTimeout(() => {
if (action === 'show') {
menuItems[i].classList.add('visible');
} else if (action === 'hide') {
menuItems[menuItems.length - i - 1].classList.remove('visible');
}
}, delay);
delay += opacityDelay;
}
}
// Toggle menu visibility on hamburger click
hamburgerBtn.addEventListener("click", function(event) {
event.stopPropagation();
2023-12-14 06:01:09 +01:00
hamburgerIcon.classList.toggle('open');
if(menu.classList.contains('active')) {
setTimeout(() => {
menu.style.display = "none";
}, 700);
toggleMenuItems('hide');
} else {
menu.style.display = "block";
toggleMenuItems('show');
}
setTimeout(() => {
menu.classList.toggle("active");
}, 1);
});
// Close menu when clicking outside of the menu
document.addEventListener("click", function(event) {
const isHamburgerClicked = event.target === hamburgerBtn;
2023-12-14 06:01:09 +01:00
const isMenuClicked = event.target === menu || event.target.parentElement === menu;
if (!isMenuClicked && !isHamburgerClicked) {
2023-12-14 06:01:09 +01:00
hamburgerIcon.classList.remove('open');
menu.classList.remove("active");
2023-12-14 06:01:09 +01:00
toggleMenuItems('hide');
}
});
2023-11-30 17:33:32 +01:00
}
};
} (Drupal));