I'm building an AAC App for my non-verbal daughter. The idea is that she would click on a category (image) nav link and then she would get a page of other images based on that category. each image is linked to a sound. The sound works great in the index and the category filters the images correctly, However when i click on the nav link the page loads the results and redirects too quickly before the nav links play. I tried JS to slow it down without success. Can anyone point me in the right direction please.
posts/_header.html.erb
<% if !@categoriez.nil? %>
<% @categoriez.each do |category| %>
<ul class="navbar-nav me-auto mb-2">
<li class="nav-item">
<%= audio_tag(polymorphic_path(category.sound), class: "audio-play", id: "#{category.category}") %>
<%= link_to image_tag(category.image, class:"category-pic"), posts_path(:cate => category.id), :onclick =>"play(\"#{category.category}\")", class:"p-1 audioButton" %>
</li>
</ul>
<% end %>
<% end %>
<script>
function play(element){
var audio = document.getElementById(element);
var isPlaying = audio.currentTime > 0 && !audio.paused && !audio.ended && audio.readyState > audio.HAVE_CURRENT_DATA;
setTimeout(function(){
if (!isPlaying) {
audio.play();
}
}, 5000);
}
</script>