script.js 4.83 KB
$(document).ready(function(){
    footer();
    search();
    phonesTab();
    openMobMenu();
    closeMobMenu();
    openSubMenuMob();
    homeSlider();
    hoverCatList();
    expandAllCatList();

    var width = $(window).width()

    function footer(){
        footerBottom();
        resizeFooterBottom();

        function footerBottom(){
            var heightHeader = $('.section-box-header').height()
            var heightFooter = $('.section-box-footer').height()
            var windowHeight = $(window).height()
            $('.section-box-content>.container.shadow').css({minHeight:windowHeight-heightHeader-heightFooter-3})
        }

        function resizeFooterBottom(){
            $(window).resize(function(){
                footerBottom();
            })
        }
    }

    function mobOverlayAdd() {
        $('body').append('<div class="mob-overlay"></div>')
    }
    function mobOverlayRemove() {
        $('.mob-overlay').remove()
    }
    
    function search() {
        $('.search-btn').click(function () {

            $('.hidden-search').addClass('vis')
            
        })
        $('.close-search-btn').click(function () {
            $('.hidden-search').removeClass('vis')
        })

    }
    
    function phonesTab() {
        $('.phones-table-wr').click(function () {
            $(this).toggleClass('vis-phone')
        })

        var timerPhone
        $('.phones-table-wr').hover(function () {
            clearTimeout(timerPhone)
        },function () {
            timerPhone = setTimeout(function () {
                $('.phones-table-wr').removeClass('vis-phone')
            },320)

        })

    }

    function openMobMenu() {
        $('.menu_mob').click(function () {
            mobOverlayAdd()
            $('body').addClass('off-scroll')
            $('.xs-sm-menu').addClass('open')
            setTimeout(function () {
                $('.xs-sm-menu').addClass('visible')
            },10)
        })
    }
    
    function openSubMenuMob() {
        $('.xs-sm-menu ul.main-menu li a').click(function (e) {
            var checkSubMEnu = $(this).parent().find('ul')
            if(checkSubMEnu.length>0){
                e.preventDefault();
                $(this).parent().toggleClass('show-sub-menu')
            }
        })
    }

    function closeMobMenu() {
        $('body').on('click','.mob-overlay',function () {
            mobOverlayRemove()
            if($('.xs-sm-menu').hasClass('visible')) {
                $('.xs-sm-menu').removeClass('visible')
                setTimeout(function () {
                    $('.xs-sm-menu').removeClass('open')
                },200)
                $('body').removeClass('off-scroll')
            }
            $('.xs-sm-menu .show-sub-menu').removeClass('show-sub-menu')

        })
        $('.close-menu-mob').click(function () {
            mobOverlayRemove()
            $('.xs-sm-menu').removeClass('visible')
            setTimeout(function () {
                $('.xs-sm-menu').removeClass('open')
            },200)
            $('body').removeClass('off-scroll')
            $('.xs-sm-menu .show-sub-menu').removeClass('show-sub-menu')
        })
    }

    function homeSlider() {
        var slideA = $('.slider-img a')
        var numA = slideA.length

        setInterval(function () {
            var activeNumA = $('.slider-img a.active-slide').index()+1;

            if(activeNumA<numA) {
                $('.slider-img a').removeClass('active-slide')
                $(slideA[activeNumA]).addClass('active-slide')
            } else {
                $('.slider-img a').removeClass('active-slide')
                $(slideA[0]).addClass('active-slide')
            }
        },4000)
    }

    function hoverCatList() {
        $('.cat-list-wr').hover(function () {
            $(this).addClass('hover')
        }, function () {
            $(this).removeClass('hover')
        })
    }

    function expandAllCatList() {
        $('.expand_brands').click(function () {
            var oldTxt = 'развернуть';
            var newTxt = 'свернуть';

            if($(this).parents('.cat-list-wr').hasClass('expand')){
                $('.cat-list-wr').removeClass('expand');
                $(this).find('p').html(oldTxt);
            } else {
                $('.cat-list-wr').removeClass('expand');
                $('.expand_brands').find('p').html(oldTxt);
                $(this).parents('.cat-list-wr').addClass('expand');

                $(this).find('p').html(newTxt);
            }


        })
    }


    // var w    = screen.width,
    //     h = screen.height;
    //  alert(w + 'x' + h + '('+$(window).width()+'x'+$(window).height()+')')


     // alert($(window).width()+'x'+$(window).height())

});