I solved this part: see So I got it to work below for new problem. Following is the initial problem for reference and context: I have a custom.js file in app/javascript folder. I have a bit of code that adds a listener for a player:
// Add Listeners
document.getElementById('file').addEventListener('change', handleFileSelect, false);
list.addEventListener("click", function(e)
{
audio.src = e.target.dataset.additionalInfo;
});
The audio player is rendered as a partial.
The target for the audio source is set by the listener when the user clicks the list item. The list item code (included in the partial) is: <li data-additional-info= <%=track_url%>><%= sanitize_filename(track.key) %></li>
Everything works beautifully for rendering the partial on the home page, but when I try to render the partial on a different page (in addition to the home page), everything works except the listener, so I get the list items as I should but they are not clickable to load a selected file into the player.
my application.html.rb has the following code loading javascript
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
So I got it to work..sort of. Here's my silly error. I was using advice from this post:
I went back to the post and followed the instructions. Ichanged the event listener from above to the following:
var list = document.querySelector('.js-interactive-list');
list.addEventListener("click", function(e)
{
audio.src = e.target.dataset.additionalInfo;
});
Not paying enough attention to detail is a killer...but now if i play the file on one page and navigate to the other page that holds the same partial, I have to do a browser refresh to get it to play on the new page.