function toggleDescription() { const category = document.querySelector('body.tax-product_cat'); const description = document.querySelector('.term-description'); if (category && description) { let paragraphs = description.querySelectorAll('p'); let array = []; let minHeight = 0; let maxHeight = description.offsetHeight; for (let i = 0; i < paragraphs.length; i++) { array.push(paragraphs[i]); minHeight = minHeight + paragraphs[i].offsetHeight + 14; if (paragraphs[i].textContent == 'Czytaj więcej') { break; } } description.dataset.minHeight = minHeight; description.dataset.maxHeight = maxHeight; description.style.maxHeight = minHeight + 'px'; let button = array[array.length - 1]; button.classList.add('description-toggler'); button.addEventListener('click', () => { if (description.offsetHeight == parseInt(description.dataset.maxHeight)) { description.style.maxHeight = description.dataset.minHeight + 'px'; } else { description.style.maxHeight = description.dataset.maxHeight + 'px'; } }); } } window.onload = toggleDescription();