templates/application/compare/index.html.twig line 1

Open in your IDE?
  1. {% extends 'application/layout.html.twig' %}
  2. {% block content %}
  3.     <main class="main">
  4.         <div class="breadcrumb">
  5.             <div class="container">
  6.                 <ol class="breadcrumb__list">
  7.                     <li class="breadcrumb__item"><a href="{{ path('home') }}" class="breadcrumb__link">Главная</a></li>
  8.                     <li class="breadcrumb__item active" aria-current="page">Сравнение товаров</li>
  9.                 </ol>
  10.             </div>
  11.         </div>
  12.         <div class="page">
  13.             <div class="container">
  14.                 {% if products|length %}
  15.                     <div class="page__header">
  16.                         <h1 class="page__title">Сравнение товаров</h1>
  17.                     </div>
  18.                     <div class="tabs">
  19.                         <div class="tabs__header tabs__header--short">
  20.                             <ul class="tabs__nav" id="chooseShop" role="tablist">
  21.                                 <li class="tabs__item active" role="presentation">
  22.                                     <button class="tabs__link" data-tab="tab">Все</button>
  23.                                 </li>
  24.                                 {% for categoryId, list in productsByCategory %}
  25.                                     {% if categoryId %}
  26.                                         <li class="tabs__item" role="presentation">
  27.                                             <button class="tabs__link" data-tab="tab{{ categoryId }}">{{ categories[categoryId].name(app.request.locale) }}: {{ list|length }}</button>
  28.                                         </li>
  29.                                     {% endif %}
  30.                                 {% endfor %}
  31.                             </ul>
  32.                         </div>
  33.                         <div class="tabs__content">
  34.                             {% for categoryId, list in productsByCategory %}
  35.                                 <div class="tabs__pane {% if loop.index == 1 %}show{% endif %}" id="tab{{ categoryId }}">
  36.                                     {{ include('application/compare/product-list.html.twig', {products: list, categoryId: categoryId, differentColor: differentColor[categoryId]}) }}
  37.                                 </div>
  38.                             {% endfor %}
  39.                         </div>
  40.                     </div>
  41.                 {% else %}
  42.                     Товары не выбраны
  43.                 {% endif %}
  44.             </div>
  45.         </div>
  46.     </main>
  47. {% endblock %}
  48. {% block scripts %}
  49. <script>
  50.     $('.show-difference').change(function () {
  51.         let parent = $(this).closest('.comparison');
  52.         if ($(this).is(':checked')) {
  53.             parent.find('.comparison__group').hide();
  54.             parent.find('.different').show();
  55.         } else {
  56.             parent.find('.comparison__group').show();
  57.         }
  58.     });
  59.     /*-------------------------------------------------------------------------------
  60.       Comparison
  61.     -------------------------------------------------------------------------------*/
  62.     const compareItems = document.querySelectorAll('.comparison');
  63.     const swiperParams = {
  64.         slidesPerView: 'auto',
  65.         watchSlidesProgress: true,
  66.         freeMode: true,
  67.         speed: 1000,
  68.         breakpoints: {
  69.             768: {
  70.                 slidesPerView: '2',
  71.                 freeMode: true,
  72.             },
  73.             992: {
  74.                 slidesPerView: '3',
  75.                 freeMode: false,
  76.             },
  77.             1200: {
  78.                 slidesPerView: '4',
  79.                 freeMode: false,
  80.                 watchSlidesProgress: true,
  81.             }
  82.         },
  83.     };
  84.     compareItems.forEach(compareItem => {
  85.         const compareItemMain = compareItem.querySelector('.a-carousel-comparison');
  86.         const compareItemData = compareItem.querySelectorAll('.a-carousel-comparison-data');
  87.         const comparePrev = compareItem.querySelector('.btn-prev');
  88.         const compareNext = compareItem.querySelector('.btn-next');
  89.         const swiperComparisonData = [];
  90.         compareItemData.forEach(item => {
  91.             swiperComparisonData.push(new Swiper(item, swiperParams));
  92.         })
  93.         const swiperComparison = new Swiper(compareItemMain, {
  94.             slidesPerView: 'auto',
  95.             watchSlidesProgress: true,
  96.             freeMode: true,
  97.             speed: 1000,
  98.             navigation: {
  99.                 prevEl: comparePrev,
  100.                 nextEl: compareNext,
  101.             },
  102.             breakpoints: {
  103.                 768: {
  104.                     slidesPerView: '2',
  105.                     freeMode: true,
  106.                 },
  107.                 992: {
  108.                     slidesPerView: '3',
  109.                     freeMode: false,
  110.                 },
  111.                 1200: {
  112.                     slidesPerView: '4',
  113.                     freeMode: false,
  114.                     watchSlidesProgress: true,
  115.                 }
  116.             },
  117.         });
  118.         swiperComparison.controller.control = swiperComparisonData;
  119.     });
  120. </script>
  121. {% endblock %}