{% set uid = id ?? random() %}<style>.texto-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; word-break: break-word;}.ver-mais-btn { color: var(--bloominggreen); text-decoration: none; font-size: 0.9em; margin-top: 0.5rem; display: inline-block; background: none; border: none; padding: 0; cursor: pointer;}.ver-mais-btn:hover { text-decoration: underline;}</style><div class="texto-container"> <div class="texto-clamp-3" id="texto-{{ uid }}"> {{ texto|raw }} </div> <button type="button" id="verMaisBtn-{{ uid }}" class="ver-mais-btn" style="display:none;"> Ver mais </button></div><script>document.addEventListener("DOMContentLoaded", function () { const textoElement = document.getElementById("texto-{{ uid }}"); const verMaisBtn = document.getElementById("verMaisBtn-{{ uid }}"); const modalTitle = document.getElementById("modalLabel"); const modalContent = document.getElementById("conteudoModal"); if (!textoElement || !verMaisBtn || !modalContent || !modalTitle) { console.log('Elementos não encontrados:', { textoElement, verMaisBtn, modalContent, modalTitle }); return; } // Cria um elemento temporário para medir o tamanho real do texto function checkIfNeedsExpansion() { // Cria clone temporário sem line-clamp const tempDiv = document.createElement('div'); tempDiv.innerHTML = textoElement.innerHTML; tempDiv.style.cssText = ` position: absolute; visibility: hidden; width: ${textoElement.offsetWidth}px; font-family: ${getComputedStyle(textoElement).fontFamily}; font-size: ${getComputedStyle(textoElement).fontSize}; line-height: ${getComputedStyle(textoElement).lineHeight}; word-break: break-word; `; document.body.appendChild(tempDiv); // Calcula altura de 3 linhas const lineHeight = parseFloat(getComputedStyle(textoElement).lineHeight); const maxHeight = lineHeight * 3; const realHeight = tempDiv.offsetHeight; document.body.removeChild(tempDiv); return realHeight > maxHeight; } // Verifica se precisa mostrar o botão "Ver mais" const needsExpansion = checkIfNeedsExpansion(); if (needsExpansion) { verMaisBtn.style.display = "inline-block"; } // Evento do botão "Ver mais" verMaisBtn.addEventListener("click", function (e) { e.preventDefault(); e.stopPropagation(); // Se o modal existir, usa-o if (modalContent) { modalContent.innerHTML = '{{ texto|raw|e('js') }}'; if (modalTitle) { modalTitle.innerHTML = '{{ title|default('Sinopse completa')|e('js') }}'; } const modalElement = document.getElementById('modalTextoCompleto'); if (window.bootstrap && window.bootstrap.Modal) { const modal = new window.bootstrap.Modal(modalElement); modal.show(); } else if (window.$ && $.fn.modal) { setTimeout(() => { $('#modalTextoCompleto').modal('show'); }, 50); } else { modalElement.style.display = 'block'; modalElement.classList.add('show'); document.body.classList.add('modal-open'); } } }); // Reajusta quando a janela for redimensionada window.addEventListener('resize', function() { if (checkIfNeedsExpansion()) { verMaisBtn.style.display = "inline-block"; } else { verMaisBtn.style.display = "none"; } }); });</script>