Skip to content

Commit

Permalink
#147 fix broken podlovePlayer after htmx pagination by embedding the …
Browse files Browse the repository at this point in the history
…api url into audio element and listening for after:swap pagination area
  • Loading branch information
ephes committed Jun 11, 2024
1 parent 8e51b8c commit 8ffaa6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 6 additions & 1 deletion cast/templates/cast/audio/audio.html
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<div id="audio_{{ value.pk }}" data-variant="xl"></div>
<div
id="audio_{{ value.pk }}"
data-variant="xl"
data-url="{% url 'cast:api:audio_podlove_detail' pk=value.pk post_id=page.pk %}"
>
</div>
27 changes: 20 additions & 7 deletions cast/templates/cast/bootstrap4/blog_list_of_posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,25 @@ <h5 class="mb-0">

{% if use_audio_player %}
<script src={% static 'cast/js/web-player/embed.5.js' %}></script>
{% for post in posts %}
{% for pk, audio in post.media_lookup.audio.items %}
<script>
podlovePlayer("#audio_{{ audio.pk }}", "{% url 'cast:api:audio_podlove_detail' pk=audio.pk post_id=post.pk %}", "{% url 'cast:api:player_config' %}");
</script>
{% endfor %}
{% endfor %}
<script>
function initializePodlovePlayers() {
document.querySelectorAll('section.block-audio div[id^="audio_"]').forEach(div => {
const audioId = div.id;
const url = div.getAttribute('data-url');
podlovePlayer(`#${audioId}`, url, "/api/audios/player_config/");
});
}

document.body.addEventListener('htmx:afterSwap', (event) => {
if (event.detail.target.id === 'paging-area') {
initializePodlovePlayers();
}
});

// Call the function on initial load
document.addEventListener('DOMContentLoaded', (event) => {
initializePodlovePlayers();
});
</script>
{% endif %}
{% endblock javascript %}

0 comments on commit 8ffaa6e

Please sign in to comment.