@@ -29,7 +29,7 @@ the episode that was just clicked.
2929You'll also note that we add ` target: "_top" ` to the ` <turbo-frame> ` . Prior to
3030that change, any ` <a> ` or ` <form> ` elements nested within ` <div id="audio"> `
3131would drive the entire page. For example, clicking the Podcast title in the
32- audio player navigating the whole page to the Podcast in question.
32+ audio player navigates the whole page to the Podcast in question.
3333
3434Now that those ` <a> ` and ` <form> ` elements are nested underneath a
3535` <turbo-frame> ` , their navigations would get "caught" or "trapped", and would
@@ -149,6 +149,7 @@ In short, this just ensures we only load the audio once, even if the play button
149149is clicked multiple times.
150150
151151``` diff
152+ +++ b/app/javascript/controllers/application.js
152153+ application.registerActionOption("reload", ({ event, value }) => {
153154+ if (event.type == "submit") {
154155+ const { submitter, target: form } = event
@@ -203,7 +204,7 @@ export default class extends ApplicationController {
203204--- a/app/views/episodes/show.html.erb
204205+++ b/app/views/episodes/show.html.erb
205206- <%= audio_tag @episode.audio, id: dom_id(@episode, :audio), class: "w-full", controls: true %>
206- + <%= audio_tag @episode.audio, id: dom_id(@episode, :audio), class: "w-full", controls: true
207+ + <%= audio_tag @episode.audio, id: dom_id(@episode, :audio), class: "w-full", controls: true,
207208+ data: {controller: "player", action: "loadeddata->player#play"} %>
208209```
209210
@@ -274,13 +275,24 @@ play state. This works because the `playerOutlet` is an instance of a
274275` player_controller ` , which defines a ` toggle() ` method.
275276
276277``` erb
278+ <%# app/views/episodes/_episode.html.erb %>
277279data-play-button-player-outlet="#<%= dom_id(episode, :audio) %>"
278280```
279281
280282The ` play-button ` controller synchronizes the ` <button> ` element's
281283` [aria-controls] ` and ` [aria-pressed] ` attribute state with any ` player ` -side
282284state changes, and routes ` click ` events to its own ` play-button#toggle ` action.
283285
286+ ### Check in
287+
288+ To complete this lesson:
289+
290+ - run ` ./bin/rails test ` to verify the tests pass
291+ - click on the play buttons in the UI and verify the the audio player is coupled with the multiple
292+ play buttons on the page
293+
294+ When you're ready, move on to the [ next lesson] ( ./lesson-3.md ) .
295+
284296[ data-turbo-permanent ] : https://turbo.hotwired.dev/handbook/building#persisting-elements-across-page-loads
285297[ turbo-frame ] : https://turbo.hotwired.dev/handbook/frames
286298[ data-turbo-frame ] : https://turbo.hotwired.dev/handbook/frames#targeting-navigation-into-or-out-of-a-frame
0 commit comments