templates/recommandation/index.html.twig line 1

Open in your IDE?
  1. {% block content %}
  2.   <div id="carrousel-wrapper"
  3.     data-size="{{articlesRecos|length}}" 
  4.     data-favs="{{favs|serialize(format='json')}}"
  5.     data-user="{{app.user}}">
  6.     <div class="onglets">
  7.       <button class="onglet" id="onglet-1" onclick="openTab(this.id, 'p1')">Trajectoire 1</button>
  8.       <button class="onglet" id="onglet-2" onclick="openTab(this.id, 'p2')">Trajectoire 2</button>
  9.       <button class="onglet" id="onglet-3" onclick="openTab(this.id, 'p3')">Trajectoire 3</button>
  10.       <button class="onglet" id="onglet-4" onclick="openTab(this.id, 'p4')">Trajectoire 4</button>
  11.     </div>
  12.     {% for i in 0..articlesRecos|length - 1 %}
  13.       <div id='p{{loop.index}}' class="tabcontent">
  14.         {% if not is_mobile() %}
  15.           <div class="carrousel" id="carrousel-{{loop.index0}}" data-size="{{articlesRecos[i]|length}}">
  16.             {% for article in articlesRecos[i] %}
  17.               {% if loop.index0 is divisible by(3) %}
  18.                 {% if not loop.first %}
  19.                   </span>
  20.                   <a class="prev" onclick="plusSlides(-1,{{i}})">&#10094;</a>
  21.                   <a class="next" onclick="plusSlides(1,{{i}})">&#10095;</a>
  22.                 {% endif %}
  23.                 <span class="slide fade slides-carrousel-{{i}}" id="slide-{{loop.index0 /3}}-carrousel-{{i}}">
  24.               {% endif %}
  25.               <div class="article">
  26.                 <span id='carrousel-{{i}}-carte-{{loop.index0}}'
  27.                 data-article="{{article|serialize(format='json')}}">
  28.                 </span>
  29.               </div>
  30.             {% endfor %}
  31.             {% if loop.last %}
  32.               </span>
  33.               <a class="prev" onclick="plusSlides(-1,{{i}})">&#10094;</a>
  34.               <a class="next" onclick="plusSlides(1,{{i}})">&#10095;</a>
  35.             {% endif %}
  36.           </div>
  37.         {% else %}
  38.           {% for article in articlesRecos[i] %}
  39.             <div class="carrousel" id="carrousel-{{loop.index0}}" data-size="{{articlesRecos[i]|length}}">
  40.               <span class="slide fade slides-carrousel-{{i}}" id="slide-{{loop.index0}}-carrousel-{{i}}">
  41.                 <div class="article">
  42.                   <span id='carrousel-{{i}}-carte-{{loop.index0}}'
  43.                   data-article="{{article|serialize(format='json')}}">
  44.                   </span>
  45.                 </div>
  46.               {% if loop.last %}
  47.                 </span>
  48.                 <div style="/*display: inline-flex;*/ text-align: center;">
  49.                   <a class="prev" style="margin-left: 0;" onclick="plusSlides(-1,{{i}})">&#10094;</a>
  50.                   <a class="next" style="margin-left: 0;" onclick="plusSlides(1,{{i}})">&#10095;</a>
  51.                 </div>
  52.               {% endif %}
  53.             </div>
  54.           {% endfor %}
  55.         {% endif %}
  56.       </div>
  57.     {% endfor %} 
  58.   </div>
  59.   
  60. <script type="module">
  61.         import ui_article from "/assets/js/ui/ui_article.js";
  62.         import article from "/assets/js/article.js";
  63.         import favoris from "/assets/js/favoris.js";
  64.         
  65.         
  66.         let size = $('#carrousel-wrapper').data('size');
  67.         let favs = $('#carrousel-wrapper').data('favs');
  68.         let connecte = $('#carrousel-wrapper').data('user') !== '';
  69.         $(document).ready( function(){ 
  70.           for(let i=0;i<size;i++){
  71.               showSlides(slideIndex,i);
  72.               let nbArticles = $('#carrousel-'+i).data('size');
  73.               for(let j=0;j<nbArticles;j++){
  74.                 let data = $('#carrousel-'+i+'-carte-'+j).data('article');
  75.                 $('#carrousel-'+i+'-carte-'+j).replaceWith(ui_article.creerCarteArticle(data,connecte,favs));
  76.               }
  77.               
  78.               openTab('onglet-1','p1');
  79.           }
  80.           article.init();
  81.         })
  82.          
  83. </script>
  84. <script>
  85.   let slideIndex = 0;
  86.   // Next/previous controls
  87.   function plusSlides(n, idCarrousel) {
  88.     showSlides(slideIndex += n, idCarrousel);
  89.   }
  90.   function showSlides(n, idCarrousel) {
  91.     let slides = $('.slides-carrousel-' + idCarrousel);
  92.     if (n >= slides.length) {slideIndex = 0}
  93.     if (n < 0) {slideIndex = slides.length - 1}
  94.     for (i = 0; i < slides.length; i++) {
  95.       slides[i].style.display = "none";
  96.     }
  97.     slides[slideIndex].style.display = "flex";
  98.   }
  99.   function openTab(tabId, parcoursId) {
  100.     let i, tabcontent, tablinks;
  101.     tabcontent = document.getElementsByClassName("tabcontent");
  102.     for (i = 0; i < tabcontent.length; i++) {
  103.       tabcontent[i].style.display = "none";
  104.     }
  105.     tablinks = document.getElementsByClassName("onglet");
  106.     for (i = 0; i < tablinks.length; i++) {
  107.       tablinks[i].className = tablinks[i].className.replace(" active", "");
  108.     }
  109.     document.getElementById(parcoursId).style.display = "block";
  110.     document.getElementById(tabId).className += " active";
  111.   } 
  112. </script>
  113. {% endblock %}