theme/templates/partials/elements/program-big-sinopse.html.twig line 1

Open in your IDE?
  1. {% set uid = id ?? random() %}
  2. <style>
  3. .texto-clamp-3 {
  4.     display: -webkit-box;
  5.     -webkit-line-clamp: 3;
  6.     -webkit-box-orient: vertical;
  7.     overflow: hidden;
  8.     line-height: 1.5;
  9.     word-break: break-word;
  10. }
  11. .ver-mais-btn {
  12.     color: var(--bloominggreen);
  13.     text-decoration: none;
  14.     font-size: 0.9em;
  15.     margin-top: 0.5rem;
  16.     display: inline-block;
  17.     background: none;
  18.     border: none;
  19.     padding: 0;
  20.     cursor: pointer;
  21. }
  22. .ver-mais-btn:hover {
  23.     text-decoration: underline;
  24. }
  25. </style>
  26. <div class="texto-container">
  27.     <div class="texto-clamp-3" id="texto-{{ uid }}">
  28.         {{ texto|raw }}
  29.     </div>
  30.     <button type="button" id="verMaisBtn-{{ uid }}" class="ver-mais-btn" style="display:none;">
  31.         Ver mais
  32.     </button>
  33. </div>
  34. <script>
  35. document.addEventListener("DOMContentLoaded", function () {
  36.     const textoElement = document.getElementById("texto-{{ uid }}");
  37.     const verMaisBtn = document.getElementById("verMaisBtn-{{ uid }}");
  38.     const modalTitle = document.getElementById("modalLabel");
  39.     const modalContent = document.getElementById("conteudoModal");
  40.     if (!textoElement || !verMaisBtn || !modalContent || !modalTitle) {
  41.         console.log('Elementos não encontrados:', { textoElement, verMaisBtn, modalContent, modalTitle });
  42.         return;
  43.     }
  44.     // Cria um elemento temporário para medir o tamanho real do texto
  45.     function checkIfNeedsExpansion() {
  46.         // Cria clone temporário sem line-clamp
  47.         const tempDiv = document.createElement('div');
  48.         tempDiv.innerHTML = textoElement.innerHTML;
  49.         tempDiv.style.cssText = `
  50.             position: absolute;
  51.             visibility: hidden;
  52.             width: ${textoElement.offsetWidth}px;
  53.             font-family: ${getComputedStyle(textoElement).fontFamily};
  54.             font-size: ${getComputedStyle(textoElement).fontSize};
  55.             line-height: ${getComputedStyle(textoElement).lineHeight};
  56.             word-break: break-word;
  57.         `;
  58.         document.body.appendChild(tempDiv);
  59.         // Calcula altura de 3 linhas
  60.         const lineHeight = parseFloat(getComputedStyle(textoElement).lineHeight);
  61.         const maxHeight = lineHeight * 3;
  62.         const realHeight = tempDiv.offsetHeight;
  63.         document.body.removeChild(tempDiv);
  64.         return realHeight > maxHeight;
  65.     }
  66.     // Verifica se precisa mostrar o botão "Ver mais"
  67.     const needsExpansion = checkIfNeedsExpansion();
  68.     if (needsExpansion) {
  69.         verMaisBtn.style.display = "inline-block";
  70.     }
  71.     // Evento do botão "Ver mais"
  72.     verMaisBtn.addEventListener("click", function (e) {
  73.         e.preventDefault();
  74.         e.stopPropagation();
  75.         // Se o modal existir, usa-o
  76.         if (modalContent) {
  77.             modalContent.innerHTML = '{{ texto|raw|e('js') }}';
  78.             if (modalTitle) {
  79.                 modalTitle.innerHTML = '{{ title|default('Sinopse completa')|e('js') }}';
  80.             }
  81.             const modalElement = document.getElementById('modalTextoCompleto');
  82.             if (window.bootstrap && window.bootstrap.Modal) {
  83.                 const modal = new window.bootstrap.Modal(modalElement);
  84.                 modal.show();
  85.             } else if (window.$ && $.fn.modal) {
  86.                 setTimeout(() => {
  87.                     $('#modalTextoCompleto').modal('show');
  88.                 }, 50);
  89.             } else {
  90.                 modalElement.style.display = 'block';
  91.                 modalElement.classList.add('show');
  92.                 document.body.classList.add('modal-open');
  93.             }
  94.         }
  95.     });
  96.     // Reajusta quando a janela for redimensionada
  97.     window.addEventListener('resize', function() {
  98.         if (checkIfNeedsExpansion()) {
  99.             verMaisBtn.style.display = "inline-block";
  100.         } else {
  101.             verMaisBtn.style.display = "none";
  102.         }
  103.     });
  104.     });
  105. </script>