new_script.js 4.46 KB
$(document).ready(function () {
    showSubMenu();
    activeSubMEnu();
    allSeoTxt();
    loadNewCarousel();


    function showSubMenu() {
        var timeout;
        var timeout2;
        $('.new_catalog').hover(function () {
            var this_ = $(this)
            timeout = setTimeout(function () {
                this_.addClass('show')


                if(!$('.main-cat_ ul li.act').length) {

                    $('.main-cat_ ul li:first-child').addClass('act')


                    $('.sub-cat_ ul:first-child').addClass('active-show')
                }

            },200)

            clearTimeout(timeout2)


        },function () {
            var this_ = $(this)
            clearTimeout(timeout)
            timeout2 = setTimeout(function () {
                this_.removeClass('show')
                $('.main-cat_ ul li').removeClass('act')
                $('.sub-cat_ ul').removeClass('active-show')
            },200)

        })
    }

    function  activeSubMEnu() {
        var timeout;
        var timeout2;
        $('.main-cat_ ul li').hover(function () {
            var this_ = $(this)
            var thisIndex = this_.index()
            var subIndex = $('.sub-cat_ ul')

           timeout = setTimeout(function () {
                $('.main-cat_ ul li').removeClass('act')
                this_.addClass('act')
               $('.sub-cat_ ul').removeClass('active-show')
               $(subIndex[thisIndex]).addClass('active-show')
            },200)
            clearTimeout(timeout2)


        },function () {
            clearTimeout(timeout)
        })
    }

    function allSeoTxt() {
        var txt1 = 'Развернуть текст';
        var txt2 = 'Свернуть';
        $('.all_seo_text').click(function (e) {
            e.preventDefault()
            $('.seo-text').toggleClass('show')
            $(this).toggleClass('show')
            if($(this).hasClass('show')) {
                $(this).html(txt2)
            } else {$(this).html(txt1)}
        })
    }

    
    function  loadNewCarousel() {
        $('.home-popular li a').click(function (e) {
            e.preventDefault();
            $('.home-popular li a').parent().removeClass('active')
            $(this).parent().addClass('active');
            var status = $(this).data('status')
            switch (status) {
                case 'new':
                    $.post( "/ajax/new",function( data ) {
                        $('.home-popular-slider').html(data);
                        $('#product_main_slider').owlCarousel({
                            navigation:true,
                            navigationText: [],
                            responsiveClass: true,
                            loop:true,
                            items:4,
                            mouseDrag:false,
                            navSpeed:200,

                        })
                    });
                    break;
                case 'top':
                    $.post( "/ajax/top", function( data ) {
                        $('.home-popular-slider').html(data);
                        $('#product_main_slider').owlCarousel({
                            navigation:true,
                            navigationText: [],
                            responsiveClass: true,
                            loop:true,
                            items:4,
                            mouseDrag:false,
                            navSpeed:200,

                        })
                    });
                    break;
                case 'prom':
                    $.post(  "/ajax/prom", function( data ) {
                        $('.home-popular-slider').html(data);
                        $('#product_main_slider').owlCarousel({
                            navigation:true,
                            navigationText: [],
                            responsiveClass: true,
                            loop:true,
                            items:4,
                            mouseDrag:false,
                            navSpeed:200,

                        })
                    });
                    break;
            }
        })
    }


    $('.collection .new_collection').owlCarousel({
        navigation : true, // Show next and prev buttons
        slideSpeed : 500,
        autoplayTimeout:3000,
        paginationSpeed : 1000,
        items:3,
        responsiveClass: true,
        responsive: {
           
            1200: {
                items: 2,
                slideBy: 1
            }
        }

    });
  

})