Assign every comment section an ID.

This makes it possible to display several posts on one page.
This commit is contained in:
tastytea 2019-10-31 08:14:03 +01:00
parent 8776d5cea2
commit 3868593605
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 4 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<!-- Comments via Mastodon-API -->
{{ partial "mastodon-api-comments-scripts.html" . }}
<p class="mastodon-api-comments"></p>
<p id="mastodon-api-comments_{{ $status_id }}" class="mastodon-api-comments"></p>
<script type="application/javascript">
fetch_mastodon_api_comments("{{ $instance }}", "{{ $status_id }}");
</script>

View File

@ -2,7 +2,7 @@
function fetch_mastodon_api_comments(instance, status_id)
{
const root = document.getElementById("mastodon-api-comments");
const root = document.getElementById("mastodon-api-comments_" + status_id);
let api = new MastodonAPI(
{
@ -19,7 +19,7 @@ function fetch_mastodon_api_comments(instance, status_id)
// Get all the replies to the status and write them to the page.
api.get("statuses/" + status_id + "/context", function(data)
{
write_comments(data);
write_comments(root, data);
});
}
@ -39,10 +39,8 @@ function comments_intro(url)
}
function write_comments(data)
function write_comments(root, data)
{
const root = document.getElementById("mastodon-api-comments");
for (const status of data.descendants)
{
let content = status.content;