Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.3 kB
3
Indexable
Never
document.addEventListener('DOMContentLoaded', function() {
    const sidebarFilters = document.getElementById("sidebar-filters");
    const productsColumn = document.getElementById("products-column");

    // Fonction de redimensionnement avec debounce
    function debounce(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this, args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };

    function shopResize() {
        if (window.matchMedia("(max-width:767px)").matches) {
            sidebarFilters.style.display = "none";
            sidebarFilters.style.opacity = "1";
            productsColumn.style.width = "100%";
            sidebarFilters.style.height = "auto";
        } else {
            productsColumn.style.width = "75%";
            sidebarFilters.style.display = "block";
            sidebarFilters.style.width = "25%";
        }
    }

    // Appliquer debounce à la fonction shopResize
    window.addEventListener('resize', debounce(shopResize, 250)); // 250 ms de délai

    jQuery(function($) {
        $('.showme').click(function(){
            if (window.matchMedia("(min-width:768px)").matches) {
                if (sidebarFilters.style.width === "0%") {
                    sidebarFilters.style.width = "25%";
                    sidebarFilters.style.height = "auto";
                    sidebarFilters.style.opacity = "1";
                    productsColumn.style.width = "75%";
                } else {
                    sidebarFilters.style.overflow = "hidden";
                    sidebarFilters.style.width = "0%";
                    sidebarFilters.style.height = "0";
                    sidebarFilters.style.opacity = "0";
                    productsColumn.style.width = "100%";
                }
            } else {
                $("#sidebar-filters").css("width","100%");
                $("#products-column").css("width","100%");
                $("#sidebar-filters").slideToggle();
            }
        });
    });
});
Leave a Comment