Skip to content

Instantly share code, notes, and snippets.

@jdorrance
Created December 12, 2013 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdorrance/7936219 to your computer and use it in GitHub Desktop.
Save jdorrance/7936219 to your computer and use it in GitHub Desktop.
define ["jquery"], ($) ->
init: ->
tag = document.createElement("script")
tag.src = "https://www.youtube.com/iframe_api"
firstScriptTag = document.getElementsByTagName("script")[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)
window.onYouTubePlayerAPIReady = ->
$(".acs-youtube-player").each ->
config = $(@).data("youtube")
console.log "youtube loading " + config.playerID
buildPlayer(config)
buildPlayer = (config) ->
done = false
player = new YT.Player(config.playerID,
height: config.height
width: config.width
videoId: config.videoId
events:
onReady: (event) -> event.target.playVideo()
onStateChange: (event) ->
if event.data is YT.PlayerState.PLAYING and not done
setTimeout(player.stopVideo(), 6000)
done = true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment