Collapsable posts

This commit is contained in:
Jose Palazon 2024-09-17 10:34:59 +01:00
parent 79a1de9968
commit 1ae070a4dd
2 changed files with 28 additions and 1 deletions

View file

@ -18,11 +18,24 @@
{% if g.user['id'] == post['author_id'] %}
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
{% endif %}
<button class="toggle-content" onclick="toggleContent(this)">Expand</button>
</header>
<p class="body">{{ post['body'] }}</p>
<p class="body" style="display: none;">{{ post['body'] }}</p>
</article>
{% if not loop.last %}
<hr>
{% endif %}
{% endfor %}
<script>
function toggleContent(button) {
const body = button.parentElement.nextElementSibling;
if (body.style.display === "none") {
body.style.display = "block";
button.textContent = "Collapse";
} else {
body.style.display = "none";
button.textContent = "Expand";
}
}
</script>
{% endblock %}