Your IP : 3.148.106.98


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/plaza/assets/js/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/plaza/assets/js/script.js

$(document).ready(function() {





    // compare
    $('.compare__cell').hover(function() {
      var currentIndex = $(this).index();
      $(this).parents('.compare').find('.c-line').each(function(index, el) {
        $(this).find('.compare__cell').eq( currentIndex).addClass('hover');
      });

    }, function() {
      $(this).parents('.compare').find('.c-line').each(function(index, el) {
        $(this).find('.compare__cell').removeClass('hover');
      });
    });

    findCompareItemCellMaxHeight();
    $('.compare__cell_same').hide();
    $('.compare__slider').slick({
      infinite: false,
      dots: false,
      arrows:true,
      autoplay: true,
      autoplaySpeed:4000,
      slidesToShow: 3,
      slidesToScroll: 3,
      vertical:false,
      responsive: [
      {
        breakpoint: 1680,
        settings: {
          slidesToShow: 3,
          slidesToScroll: 3,
        }
      },
      {
        breakpoint: 1366,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 2,
        }
      },
      {
        breakpoint: 1023,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 2,
        }
      },
      {
        breakpoint: 800,
        settings: {
          slidesToShow: 1,
          slidesToScroll: 1,
        }
      },
      {
        breakpoint: 480,
        settings: {
          slidesToShow: 1,
          slidesToScroll: 1
        }
      }]

    });


    $(".butn-buy").click(function()
    {

        var prod_id = $(this).attr("data-id");

        if(prod_id > 0)
        {
            // alert('ok');
            $.ajax({
                type: 'POST',
                url: '/ajax/add2basket.php',
                data: {
                    "id": prod_id
                },
                success: function (data) {
                  // alert('Load was performed.');
                  $.fancybox.open(data);
                },
                error:function (data) {
                  // alert('Load was NOT performed.');
                },
            });
        }
    });



    $('.buy-button').click(function(e){
        e.preventDefault();
        var anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $(anchor.attr('href')).offset().top
        }, 777);
        e.preventDefault();
        return false;
    });

    //short compare list or long list
    $('.control_delete').click(function() {
      $(this).toggleClass('active');
      var slideToggleCnt = $(this).parents('.compare').find('.compare__cell_same').length;
      $(this).parents('.compare').find('.compare__cell_same').slideToggle('slow',function(){
       slideToggleCnt = slideToggleCnt;
       if(slideToggleCnt === 0){
        findCompareItemCellMaxHeight();


        $(document).trigger('resize');
        $('html,body').animate({
          scrollTop: $(this).parents('.compare').offset().top},
          'fast');
      }

    });

    });
    //color
    $('.colors__item').click(function() {
      $('.colors__item').removeClass('active');
      $(this).addClass('active');
    });


  //cities
    $('.js-show-city-block').click(function(e){
      e.preventDefault();
      $(this).parents('.block').find('.block_city').slideToggle('fast');
      $('html,body').animate({
          scrollTop: $(this).parents('.block').find('.block_city').offset().top},
          'slow');
    });
    $('.city__item').click(function(e) {
      e.preventDefault();

      var currentObject = $(this);
      var country =  $(this).attr('data-country');
      var city =  $(this).attr('data-city');
      var city_name =  $(this).text();
      var category =  $(this).attr('data-category');
      var link = '' + $(this).attr('href') +'&format=json'+ '';

      $.getJSON(link, function( data ) {
        var obj = data;
        var text = '';
        $.each( data, function( key, val ) {
          var output = '';
          for (var property in val) 
          {
           text += '<div class="shops__item">';
           var shop = val[property];
           if (shop.name !== null) {
             text += '<div class="shops_name">' + shop.name + '</div>';
           }
           if (shop.address !== null) {
             text += '<div class="shops_line">' + shop.address + '</div>';
           }
           if (shop.phone !== null) {
             text += '<div class="shops_line">' + shop.phone + '</div>';
           }
           if (shop.site !== null) {
             text += '<div class="shops_line"><a href="http://'+shop.site+'" target="_blank">' + shop.site + '</a></div>';
           }
           text += '</div>';
         }
       });
        $('.cities__modal-block').find('.shops').html(text);
        $('.cities__modal-block').find('.cities__header').text(city_name);

        $('.cities__modal-block').fadeIn('fast', function() {
         $('.cities__modal').addClass('active');
       });
        $(".shops").mCustomScrollbar({
         theme:"minimal",
         autoHideScrollbar:false,
         alwaysShowScrollbar: 2
       });

      });

    });

    $('.cities__close').click(function() {
      $('.cities__modal-block').fadeOut('fast', function() {
        $('.cities__modal').removeClass('active');
      });
      $(".shops").mCustomScrollbar("destroy");
    });
    $(document).click( function(event){
      if(( $(event.target).closest(".cities__body").length )||($(event.target).closest(".city__item").length))
        return;
        $('.cities__modal-block').fadeOut('fast', function() {
          $('.cities__modal').removeClass('active');
        });
        $(".shops").mCustomScrollbar("destroy");
      event.stopPropagation();
    });

    $(document).resize(function(event) {
        block14Resize();
        var maxHeights = [];
         findCompareItemCellMaxHeight();
    });
});

//function to fix compare block cells height
function  findCompareItemCellMaxHeight()
{
  var maxHeights = [];
  setTimeout(function () {
    $('.compare').each(function() {
      currentCompare = $(this);
      for(j=0; j<currentCompare.find('.c-line .compare__cell').length / currentCompare.find('.c-line').length; j++)
      {
        height = 0;

        for(i=0; i < currentCompare.find('.c-line').length; i++)
        {
          cell = currentCompare.find('.c-line').eq(i).find('.compare__cell').eq(j);

          if(cell.is(":visible") === true)
          {
            if(height < cell.height())
            {
              height = cell.height();
            }
          }
        }
        maxHeights.push(height);
      }
      currentCompare.find('.compare__cell').each(function(){
        var index = $(this).index();
        if(maxHeights[index] > 0){
          $(this).height(maxHeights[index]);
        }
      });
    });

  }, 500);
}