Note that there are some explanatory texts on larger screens.

plurals
  1. POCan Youtube play nicely with Turbolinks?
    primarykey
    data
    text
    <p>I'm developing a Rails4 app which will be able to embed and play back videos hosted on Youtube in my application's pages. I need to hook into some of the video player's events, so I'm creating the Youtube object via an API call:</p> <pre><code>&lt;script id="video_script" &gt;&lt;/script&gt; &lt;div id="player"&gt;&lt;/div&gt; &lt;%= javascript_tag do %&gt; var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var scriptTag = $("script#video_script"); scriptTag.parent()[0].insertBefore(tag, scriptTag[0]); var youtube_player; function onYouTubeIframeAPIReady() { youtube_player = new YT.Player('player', { videoId: &lt;%= @video.id %&gt;, events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } function onPlayerReady(event) { .... } function onPlayerStateChange(event) { .... } &lt;% end %&gt; </code></pre> <p>This works perfectly well when the page is first loaded, but doesn't work when a user navigates between pages with turbolinks enabled, since the document ready event doesn't fire, and consequently the Youtube code doesn't know to issue the callback to <code>onYouTubeIframeAPIReady()</code>.</p> <p>So, I was wondering if there are any workaround that would get the Youtube API to call the API Ready method for the <code>page:change</code> event to make it work with turbolinks, in addition to the <code>document.ready</code> event? I've tried digging through the api script that gets downloaded from Youtube, but couldn't find anything in there that would solve the issue, and I'm also a little hesitant to be running a local version of Youtube's script.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload