diff --git a/templates/coffee/src/modules/sequence.coffee b/templates/coffee/src/modules/sequence.coffee index e956252927..96450199e8 100644 --- a/templates/coffee/src/modules/sequence.coffee +++ b/templates/coffee/src/modules/sequence.coffee @@ -66,5 +66,3 @@ class window.Sequence mark_active: (position) -> @link_for(position).attr class: "seq_#{@elements[position - 1].type}_active" - - diff --git a/templates/coffee/src/modules/video/video_caption.coffee b/templates/coffee/src/modules/video/video_caption.coffee index 8742c2031a..fd6ade363f 100644 --- a/templates/coffee/src/modules/video/video_caption.coffee +++ b/templates/coffee/src/modules/video/video_caption.coffee @@ -1,7 +1,7 @@ class VideoCaption constructor: (@player, @youtubeId) -> @index = [] - @fetchCaption() + @render() @bind() $: (selector) -> @@ -12,6 +12,37 @@ class VideoCaption $(@player).bind('resize', @onWindowResize) $(@player).bind('updatePlayTime', @onUpdatePlayTime) @$('.hide-subtitles').click @toggle + @$('.subtitles').mouseenter(@onMouseEnter).mouseleave(@onMouseLeave) + .mousemove(@onMovement).bind('mousewheel', @onMovement) + .bind('DOMMouseScroll', @onMovement) + @$('.subtitles li[data-index]').click @seekPlayer + + captionURL: -> + "/static/subs/#{@youtubeId}.srt.sjson" + + render: -> + @$('.video-wrapper').after """ +
  1. Attempting to load captions...
+ """ + @$('.video-controls .secondary-controls').append """ + Captions + """ + @$('.subtitles').css maxHeight: @$('.video-wrapper').height() - 5 + @fetchCaption() + + renderCaption: -> + container = $('
    ') + + $.each @captions, (index, text) => + container.append $('
  1. ').html(text).attr + 'data-index': index + 'data-start': @start[index] + + @$('.subtitles').html(container.html()) + + # prepend and append an empty
  2. for cosmatic reason + @$('.subtitles').prepend($('
  3. ').height(@topSpacingHeight())) + .append($('
  4. ').height(@bottomSpacingHeight())) fetchCaption: -> $.getJSON @captionURL(), (captions) => @@ -21,29 +52,7 @@ class VideoCaption for time in [captions.start[index]..captions.end[index]] @index[time] ||= [] @index[time].push(index) - @render() - - captionURL: -> - "/static/subs/#{@youtubeId}.srt.sjson" - - render: -> - container = $('
      ') - container.css maxHeight: @$('.video-wrapper').height() - 5 - - $.each @captions, (index, text) => - container.append $('
    1. ').html(text).attr - 'data-index': index - 'data-start': @start[index] - - @$('.subtitles').replaceWith(container) - @$('.subtitles').mouseenter(@onMouseEnter).mouseleave(@onMouseLeave) - .mousemove(@onMovement).bind('mousewheel', @onMovement) - .bind('DOMMouseScroll', @onMovement) - @$('.subtitles li[data-index]').click @seekPlayer - - # prepend and append an empty
    2. for cosmatic reason - @$('.subtitles').prepend($('
    3. ').height(@topSpacingHeight())) - .append($('
    4. ').height(@bottomSpacingHeight())) + @renderCaption() onUpdatePlayTime: (event, time) => # This 250ms offset is required to match the video speed diff --git a/templates/coffee/src/modules/video/video_control.coffee b/templates/coffee/src/modules/video/video_control.coffee new file mode 100644 index 0000000000..0f78dc3f84 --- /dev/null +++ b/templates/coffee/src/modules/video/video_control.coffee @@ -0,0 +1,42 @@ +class VideoControl + constructor: (@player) -> + @render() + @bind() + + $: (selector) -> + @player.$(selector) + + bind: -> + $(@player).bind('play', @onPlay) + .bind('pause', @onPause) + .bind('ended', @onPause) + @$('.video_control').click @togglePlayback + + render: -> + @$('.video-controls').append """ +
      +
      +
        +
      • Play
      • +
      • +
        0:00 / 0:00
        +
      • +
      + +
      + """ + + onPlay: => + @$('.video_control').removeClass('play').addClass('pause').html('Pause') + + onPause: => + @$('.video_control').removeClass('pause').addClass('play').html('Play') + + togglePlayback: (event) => + event.preventDefault() + if $(event.target).hasClass('play') + $(@player).trigger('play') + else + $(@player).trigger('pause') diff --git a/templates/coffee/src/modules/video/video_player.coffee b/templates/coffee/src/modules/video/video_player.coffee index b6ae94aabb..b51dbcd95e 100644 --- a/templates/coffee/src/modules/video/video_player.coffee +++ b/templates/coffee/src/modules/video/video_player.coffee @@ -2,7 +2,7 @@ class VideoPlayer constructor: (@video) -> @currentTime = 0 @element = $("#video_#{@video.id}") - @buildPlayer() + @render() @bind() $: (selector) -> @@ -10,11 +10,13 @@ class VideoPlayer bind: -> $(@).bind('seek', @onSeek) - $(@).bind('updatePlayTime', @onUpdatePlayTime) - $(@).bind('speedChange', @onSpeedChange) + .bind('updatePlayTime', @onUpdatePlayTime) + .bind('speedChange', @onSpeedChange) + .bind('play', @onPlay) + .bind('pause', @onPause) + .bind('ended', @onPause) $(document).keyup @bindExitFullScreen - @$('.video_control').click @togglePlayback @$('.add-fullscreen').click @toggleFullScreen @addToolTip unless onTouchBasedDevice() @@ -22,7 +24,8 @@ class VideoPlayer if @element.hasClass('fullscreen') && event.keyCode == 27 @toggleFullScreen(event) - buildPlayer: -> + render: -> + new VideoControl(this) new VideoCaption(this, @video.youtubeId('1.0')) new VideoSpeedControl(this, @video.speeds) new VideoProgressSlider(this) @@ -53,26 +56,20 @@ class VideoPlayer onStateChange: (event) => switch event.data when YT.PlayerState.PLAYING - if window.player && window.player != @player - window.player.pauseVideo() - window.player = @player - @onPlay() + $(@).trigger('play') when YT.PlayerState.PAUSED - if window.player == @player - window.player = null - @onPause() + $(@).trigger('pause') when YT.PlayerState.ENDED - if window.player == @player - window.player = null - @onPause() + $(@).trigger('ended') - onPlay: -> - @$('.video_control').removeClass('play').addClass('pause').html('Pause') + onPlay: => + window.player.pauseVideo() if window.player && window.player != @player + window.player = @player unless @player.interval @player.interval = setInterval(@update, 200) - onPause: -> - @$('.video_control').removeClass('pause').addClass('play').html('Play') + onPause: => + window.player = null if window.player == @player clearInterval(@player.interval) @player.interval = null @@ -109,13 +106,6 @@ class VideoPlayer @$(".vidtime").html(progress) @progress = progress - togglePlayback: (event) => - event.preventDefault() - if $(event.target).hasClass('play') - @play() - else - @pause() - toggleFullScreen: (event) => event.preventDefault() if @element.hasClass('fullscreen') diff --git a/templates/coffee/src/modules/video/video_speed_control.coffee b/templates/coffee/src/modules/video/video_speed_control.coffee index 1214053fd9..3e0b9b7b33 100644 --- a/templates/coffee/src/modules/video/video_speed_control.coffee +++ b/templates/coffee/src/modules/video/video_speed_control.coffee @@ -1,6 +1,6 @@ class VideoSpeedControl constructor: (@player, @speeds) -> - @build() + @render() @bind() $: (selector) -> @@ -18,7 +18,17 @@ class VideoSpeedControl event.preventDefault() $(this).removeClass('open') - build: -> + render: -> + @$('.secondary-controls').prepend """ + + """ + $.each @speeds, (index, speed) => link = $('').attr(href: "#").html("#{speed}x") @$('.video_speeds').prepend($('
    5. ').attr('data-speed', speed).html(link)) diff --git a/templates/video.html b/templates/video.html index c7278bee22..54d6f8fa37 100644 --- a/templates/video.html +++ b/templates/video.html @@ -9,35 +9,8 @@
      -
      -
      -
      - - - -
      -
      +
      - -
        -
      1. Attempting to load captions...
      2. -