2021-03-12 00:09:19 +01:00
|
|
|
<div id="articles">
|
|
|
|
{% for post in posts %}
|
|
|
|
<article>
|
|
|
|
<h2>{{ post.title }}</h2>
|
|
|
|
<p>Author: {{ post.author }}</p>
|
|
|
|
<p><button data-id="{{ post.id }}" class="btn">More</button></p>
|
|
|
|
<hr>
|
|
|
|
</article>
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
<ul class="pagination">
|
2021-03-12 21:16:23 +01:00
|
|
|
<li class="page-item{% if pag == 1 %} disabled{% endif %}">
|
|
|
|
<a id="pag-previous" href="#">Previous</a>
|
2021-03-12 00:09:19 +01:00
|
|
|
</li>
|
|
|
|
<li class="page-item">
|
2021-03-12 21:16:23 +01:00
|
|
|
<a id="pag-next" href="#">Next</a>
|
2021-03-12 00:09:19 +01:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<script>
|
2021-03-12 21:16:23 +01:00
|
|
|
|
|
|
|
// Open article
|
|
|
|
buttons = document.querySelectorAll('.btn');
|
2021-03-12 00:09:19 +01:00
|
|
|
|
|
|
|
buttons.forEach((button) => {
|
|
|
|
button.addEventListener('click', event => {
|
2021-03-21 14:24:02 +01:00
|
|
|
document.$CHAT_TEMPLATE = "partials/blog/single.html";
|
2021-03-12 00:09:19 +01:00
|
|
|
document.$CHAT_SOCKET.send(JSON.stringify({
|
|
|
|
selector: "#main",
|
2021-03-21 14:24:02 +01:00
|
|
|
template: document.$CHAT_TEMPLATE,
|
2021-03-12 00:09:19 +01:00
|
|
|
data: {
|
|
|
|
id: event.target.dataset.id
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
});
|
2021-03-12 21:16:23 +01:00
|
|
|
|
|
|
|
// Paginator
|
|
|
|
pagPrevious = document.querySelector('#pag-previous');
|
|
|
|
pagNext = document.querySelector('#pag-next');
|
|
|
|
|
|
|
|
pagPrevious.addEventListener('click', (event) => {
|
|
|
|
event.preventDefault();
|
2021-03-21 14:24:02 +01:00
|
|
|
document.$CHAT_TEMPLATE = "partials/blog/all_articles.html";
|
2021-03-12 21:16:23 +01:00
|
|
|
document.$CHAT_SOCKET.send(JSON.stringify({
|
|
|
|
selector: "#main",
|
2021-03-21 14:24:02 +01:00
|
|
|
template: document.$CHAT_TEMPLATE,
|
2021-03-12 21:16:23 +01:00
|
|
|
data: {
|
|
|
|
pag: {% if pag > 1 %}{{ pag }} - 1{% else %}1{% endif %}
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
pagNext.addEventListener('click', (event) => {
|
|
|
|
event.preventDefault();
|
2021-03-21 14:24:02 +01:00
|
|
|
document.$CHAT_TEMPLATE = "partials/blog/all_articles.html";
|
2021-03-12 21:16:23 +01:00
|
|
|
document.$CHAT_SOCKET.send(JSON.stringify({
|
|
|
|
selector: "#main",
|
2021-03-21 14:24:02 +01:00
|
|
|
template: document.$CHAT_TEMPLATE,
|
2021-03-12 21:16:23 +01:00
|
|
|
data: {
|
|
|
|
pag: {{ pag }} + 1
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|