-angular.module('directives.youtubeEmbed', ['app.enums']).directive "youtubeEmbed", ["$log", "$timeout", "$rootScope", "enums", ($log, $timeout, $rootScope, enums) ->
+angular.module('directives.youtubeEmbed', ['app.enums'])
+.directive "youtubeEmbed", ["$log", "$timeout", "$rootScope", "enums", ($log, $timeout, $rootScope, enums) ->
   priority: 0
   template: ""
   replace: false


          if scope.hasStarted && newState.data == YT.PlayerState.ENDED
            $rootScope.$broadcast enums.EventType.VideoEnd, scope.videoData


    post: postLink = (scope, iElement, iAttrs, controller) ->

      ytLoaded = window.YT != undefined && window.YT.Player != undefined
      if !ytLoaded
        _onYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady

  scope: {
    videoData: '=youtubeEmbed'
  }
  compile: ->
    pre: (scope) ->
      scope.hasStarted = false
      scope.loadAPI = ->
        tag = document.createElement("script")
        tag.src = "//www.youtube.com/iframe_api"
        firstScriptTag = document.getElementsByTagName("script")[0]
        firstScriptTag.parentNode.insertBefore tag, firstScriptTag
      scope.onAPIReady = ->
        scope.player = new YT.Player("youtube-player",
          width: "1920", height: "1080"
          videoId: scope.videoData.id
          playerVars:
            enablejsapi: 1
            modestbranding: 1
            origin: document.domain
            showinfo: 0
            theme: "light"
            rel: 0
            vq: 'hd720'
        )
        scope.player.addEventListener 'onStateChange', (newState) ->
          if !scope.hasStarted
            if newState.data == YT.PlayerState.PLAYING
              $log.info 'yt started'
