$(function() { var windowWidth = $(window).width(), windowHeight = $(window).height(), $catalogItem = null, $catalogItemPrev = null, $catalogItemH = null; $('.popup-with-form').magnificPopup({ type: 'inline', preloader: false, focus: '#name', callbacks: { beforeOpen: function() { if($(window).width() < 700) { this.st.focus = false; } else { this.st.focus = '#name'; } } } }); // клик на гамбургер $('.toggle-switch').on('click', function () { if(windowWidth >= 640) { $('.header-menu').fadeToggle(400); } else { $('.mob-cnt').fadeToggle(400); } $(this).toggleClass('open'); }); // клик на елемент списка в catalog-cabinet.php $('.catalog-item > a').on('click', function (e) { e.preventDefault(); $catalogItem = $(this).closest('.catalog-item'); $catalogItemH = $(this).height(); /* !!!ДОБАВИТЬ!!! */ window.location.hash = $(this).attr('id'); /* !!!END ДОБАВИТЬ!!! */ var $expandedBlock = $catalogItem.find('.catalog-item__expanded'), h = 0; if($('.catalog-item.open').length == 0 || $catalogItemPrev.html() == $catalogItem.html()) { if($expandedBlock.is(':visible')) { $expandedBlock.find('.catalog-item__expanded-cnt').css('opacity','0'); setTimeout(function () { $catalogItem.css('height', $catalogItemH); $expandedBlock.slideUp(400, function () { $catalogItem.toggleClass('open'); }); }, 300); } else { $('html, body').animate({ scrollTop: ($(this).offset().top + $(this).height() - $(this).find('.catalog-item__info').outerHeight())-$('header').outerHeight() - 50 }, 700); $expandedBlock.css('opacity','0'); $expandedBlock.show(); h = $catalogItemH + $expandedBlock.find('.catalog-item__expanded-cnt').outerHeight(); $catalogItem.css('height', h+60); $expandedBlock.hide(); $expandedBlock.css('opacity','1'); $catalogItem.toggleClass('open'); $expandedBlock.slideDown(700, function () { if(!$expandedBlock.find('.jcarousel').hasClass('initialised')) { jcInit($expandedBlock.find('.jcarousel')); h = $catalogItemH + $expandedBlock.find('.catalog-item__expanded-cnt').outerHeight(); $catalogItem.css('height', h+60); } $expandedBlock.find('.catalog-item__expanded-cnt').css('opacity','1') }); } } else { var $prevCatalogItem = $('.catalog-item.open'); var $prevExpandedBlock = $('.catalog-item.open').find('.catalog-item__expanded'); $expandedBlock.css('opacity','0'); $expandedBlock.show(); h = $catalogItemH + $expandedBlock.find('.catalog-item__expanded-cnt').height(); $catalogItem.css('height', h+60); $expandedBlock.hide(); $expandedBlock.css('opacity','1'); $catalogItem.toggleClass('open'); $expandedBlock.fadeIn(1, function () { if(!$expandedBlock.find('.jcarousel').hasClass('initialised')) { jcInit($expandedBlock.find('.jcarousel')); } $expandedBlock.find('.catalog-item__expanded-cnt').css('opacity','1'); $prevExpandedBlock.find('.catalog-item__expanded-cnt').css('opacity','0'); $prevCatalogItem.removeAttr('style'); $prevExpandedBlock.hide(); $prevCatalogItem.removeClass('open'); }); } $catalogItemPrev = $catalogItem; return false; }); $('.js-expanded-close').on('click', function (e) { var $expandedBlock = $(this).closest('div'); $catalogItem = $(this).closest('.catalog-item'); $catalogItemH = $catalogItem.children('a').height(); $expandedBlock.find('.catalog-item__expanded-cnt').css('opacity','0'); setTimeout(function () { $catalogItem.css('height', $catalogItemH); $('html, body').animate({ scrollTop: ($catalogItem.offset().top - $('header').outerHeight() - 20) }, 700); $expandedBlock.slideUp(400, function () { $catalogItem.toggleClass('open'); }); }, 300); }); // выставление одинаковой высоты в catalog-cabinet.php if($('.catalog-item').length != 0) { var h = 0; $('.catalog-item__info').each(function () { if($(this).height() > h) h = $(this).height(); }); $('.catalog-item__info').css('height', h+35); } // инициализация карусельки на catalog-cabinet.php if($('#jc-cat-item-page').length != 0) { jcInit($('#jc-cat-item-page')); } // инициализация карусельки на projects-detail.php if($('#page-project-gallery').length != 0) { var jcarousel = $('#page-project-gallery'); jcarousel .on('jcarousel:reload jcarousel:create', function () { var carousel = $(this), width = carousel.innerWidth(); if (width >= 520) { width = width / 5; } else if (width >= 370) { width = width / 4; } else if (width >= 300) { width = width / 3; } else if (width >= 190) { width = width / 2; } carousel.jcarousel('items').css('width', Math.ceil(width) + 'px'); }) .jcarousel({ wrap: 'circular' }) .jcarouselSwipe(); jcarousel.parent().find('.jcarousel-control-prev') .jcarouselControl({ target: '-=1' }); jcarousel.parent().find('.jcarousel-control-next') .jcarouselControl({ target: '+=1' }); } // инициализация карусельки "похожие проекты" на projects-detail.php if($('#page-projects-other').length != 0) { var jcarousel = $('#page-projects-other'); jcarousel .on('jcarousel:reload jcarousel:create', function () { var carousel = $(this), width = carousel.innerWidth(); if (width >= 1300) { width = width / 6; } else if (width >= 900) { width = width / 5; } else if (width >= 700) { width = width / 4; } else if (width >= 500) { width = width / 3; } else if (width >= 400) { width = width / 3; } else if (width >= 350) { width = width / 2; } else if (width >= 300) { width = width / 2; } carousel.jcarousel('items').css('width', Math.ceil(width) + 'px'); }) .jcarousel({ wrap: 'circular' }) .jcarouselSwipe(); jcarousel.parent().find('.jcarousel-control-prev') .jcarouselControl({ target: '-=1' }); jcarousel.parent().find('.jcarousel-control-next') .jcarouselControl({ target: '+=1' }); } $('ul.page-project-gallery-list').on('click', 'li:not(.active)', function() { $(this) .addClass('active').siblings().removeClass('active') .closest('div.page-project__img-cnt').find('a.page-projects__img-wr').removeClass('active').eq($(this).index()).addClass('active'); }); if(document.getElementById('project-gallery') !== null) { document.getElementById('project-gallery').onclick = function (event) { event = event || window.event; var target = event.target || event.srcElement, link = target.style ? target.parentNode : target, options = {index: link, event: event}, links = this.getElementsByTagName('a'); blueimp.Gallery(links, options); }; } $('.blueimp-popup').on('click', function (event) { event = event || window.event; var target = event.target || event.srcElement, link = target.style ? target.parentNode : target, options = {index: link, event: event}, links = this.getElementsByTagName('a'); blueimp.Gallery(links, options); }); $('.js-catalog-item__expanded-gallery').on('click', function (event) { event = event || window.event; var target = event.target || event.srcElement, link = target.style ? target.parentNode : target, options = {index: link, event: event}, links = this.getElementsByTagName('a'); blueimp.Gallery(links, options); }); /* !!!ДОБАВИТЬ!!! */ if(window.location.hash != '' && $('.page-container--cat-items').length > 0) { $(window.location.hash).click(); } /* !!!END ДОБАВИТЬ!!! */ // инициализация карусельки function jcInit(jcarousel) { jcarousel .on('jcarousel:reload jcarousel:create', function () { var carousel = $(this), width = carousel.innerWidth(); carousel.jcarousel('items').css('width', Math.ceil(width) + 'px'); }) .jcarousel({ wrap: 'circular' }) .jcarouselSwipe(); jcarousel.parent().find('.jcarousel-control-prev') .jcarouselControl({ target: '-=1' }); jcarousel.parent().find('.jcarousel-control-next') .jcarouselControl({ target: '+=1' }); jcarousel.addClass('initialised') } });