document.addEventListener('DOMContentLoaded', () => {
// Add “Filter wrapper” element class
const filterPanel = document.querySelector('.filter-3__filter-wrapper');
// Adds the class of the “Content” element of the offcanvas element
const mobileContainer = document.querySelector('.filter-3__offcanvas-content');
// Adds the class of the “Content container” element
const desktopContainer = document.querySelector('.filter-3__content-container');
// Add the media query that you want to display the filters inside the offcanvas
const mediaQuery = window.matchMedia('(max-width: 991px)');
function moveFilterContent(e) {
if (e.matches) {
// If the screen width is less than or equal to 991px (mobile/tablet)
if (!mobileContainer.contains(filterPanel)) {
mobileContainer.appendChild(filterPanel);
}
} else {
// If the screen width is greater than 991px (desktop)
if (!desktopContainer.contains(filterPanel)) {
desktopContainer.appendChild(filterPanel);
}
}
}
// Listen for changes in the media query
mediaQuery.addEventListener('change', moveFilterContent);
// Execute on page load to ensure the filter is placed correctly
moveFilterContent(mediaQuery);
});