templates/Services/Main/components/item-service.html.twig line 1

Open in your IDE?
  1. <a href="{{ item_service_url }}" data-href="{{ item_service_url }}"
  2.    class="itemService {% if item_service_is_focus|default and item_service_is_focus == true %}--focus{% endif %}"
  3.    title="{{ item_service_title }}"
  4.    {% if item_service_is_focus|default and item_service_is_focus == true %}target="_blank"{% endif %}>
  5.   <div class="__bg"></div>
  6.   {% if item_service_image|default and item_service_image|length > 0 %}
  7.     <img class="__img" src="{{ asset('upload/images/' ~ item_service_image) }}" alt="">
  8.   {% endif %}
  9.   {% if item_service_is_focus|default and item_service_is_focus == true %}
  10.     <span class="__label"><span class="__text">{{ item_service_title }}</span><span
  11.         class="__icon">{{ source('svg/icons/icon-external.svg') }}</span></span>
  12.     <span class="__desc">{{ item_service_description }}</span>
  13.   {% else %}
  14.     <span class="__label">{{ item_service_title }}</span>
  15.   {% endif %}
  16.   {#<ul class="__tags">
  17.     {% if item_service_sous_profils|length == item_service_count_sous_profils %}
  18.       <li tabindex="0" data-href="{{ path('services_services', {'slug': 'particulier'}) }}" class="tagService"><span>Particulier</span></li>
  19.       {% for gp in item_service_grand_profils %}
  20.         {% if item_service_is_elastic|default and item_service_is_elastic == true %}
  21.           {% set alias = gp.alias %}
  22.         {% else %}
  23.           {% set alias = gp.aliasUrl %}
  24.         {% endif %}
  25.         {% if alias != 'particulier' %}
  26.           <li tabindex="0" data-href="{{ path('services_detail_service', {'slug': alias}) }}"
  27.                 class="tagService">{{ gp.titre }}</li>
  28.         {% endif %}
  29.       {% endfor %}
  30.     {% else %}
  31.       {% for sp in item_service_sous_profils %}
  32.         {% if item_service_is_elastic|default and item_service_is_elastic == true %}
  33.           {% set alias = sp.alias %}
  34.         {% else %}
  35.           {% set alias = sp.aliasUrl %}
  36.         {% endif %}
  37.         <li tabindex="0" data-href="{{ path('services_services', {'slug': 'particulier'}) }}?sp[]={{ alias }}"
  38.               class="tagService"><span>{{ sp.titre }}</span></li>
  39.       {% endfor %}
  40.       {% for gp in item_service_grand_profils %}
  41.         {% if item_service_is_elastic|default and item_service_is_elastic == true %}
  42.           {% set alias = gp.alias %}
  43.         {% else %}
  44.           {% set alias = gp.aliasUrl %}
  45.         {% endif %}
  46.         {% if alias != 'particulier' %}
  47.           <li tabindex="0" data-href="{{ path('services_detail_service', {'slug': alias}) }}"
  48.                 class="tagService">{{ gp.titre }}</li>
  49.         {% endif %}
  50.       {% endfor %}
  51.     {% endif %}
  52.   </ul>#}
  53. </a>
  54. <script>
  55.   (() => {
  56.     const elems = document.querySelectorAll('[data-href]')
  57.     for (let i = 0; i < elems.length; i++) {
  58.       elems[i].addEventListener('click', function (e) {
  59.         e.stopPropagation()
  60.         e.preventDefault()
  61.         const isTargetBlank = elems[i].getAttribute('target') === "_blank"
  62.         const isShortcutKeyPressed = e.ctrlKey || e.shiftKey || e.metaKey
  63.         if (isTargetBlank || isShortcutKeyPressed) {
  64.           if (elems[i].getAttribute('data-href').includes('http') || elems[i].getAttribute('data-href').includes('https')) {
  65.             window.open(elems[i].getAttribute('data-href'), '_blank')
  66.           } else {
  67.             window.open(window.location.origin + elems[i].getAttribute('data-href'), '_blank')
  68.           }
  69.         } else {
  70.           if (elems[i].getAttribute('data-href').includes('http') || elems[i].getAttribute('data-href').includes('https')) {
  71.             window.location.href = elems[i].getAttribute('data-href')
  72.           } else {
  73.             window.location.href = window.location.origin + elems[i].getAttribute('data-href')
  74.           }
  75.         }
  76.       })
  77.     }
  78.   })()
  79. </script>