From 210da2c4f04c29073c5603c7880e986f0f4fe37a Mon Sep 17 00:00:00 2001 From: kimth Date: Fri, 14 Sep 2012 16:53:23 -0400 Subject: [PATCH 1/5] Start to remember caption state --- common/lib/xmodule/xmodule/js/src/video/display.coffee | 6 ++++++ .../xmodule/js/src/video/display/video_caption.coffee | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index 3880091661..90e465d0ec 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -9,6 +9,12 @@ class @Video @parseVideos @el.data('streams') @fetchMetadata() @parseSpeed() + + if $.cookie('hide_captions') == 'true' + @el.addClass('closed') + else + @el.removeClass('closed') + $("#video_#{@id}").data('video', this).addClass('video-load-complete') if YT.Player diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee index f65debb1a2..ae6b0c8ed1 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee @@ -1,6 +1,6 @@ class @VideoCaption extends Subview initialize: -> - @loaded = false + @loaded = false bind: -> $(window).bind('resize', @resize) @@ -49,7 +49,7 @@ class @VideoCaption extends Subview @$('.subtitles').html(container.html()) @$('.subtitles li[data-index]').click @seekPlayer - # prepend and append an empty
  • for cosmatic reason + # prepend and append an empty
  • for cosmetic reason @$('.subtitles').prepend($('
  • ').height(@topSpacingHeight())) .append($('
  • ').height(@bottomSpacingHeight())) @@ -131,10 +131,12 @@ class @VideoCaption extends Subview toggle: (event) => event.preventDefault() if @el.hasClass('closed') + $.cookie('hide_captions', 'false', expires: 3650, path: '/') @$('.hide-subtitles').attr('title', 'Turn off captions') @el.removeClass('closed') @scrollCaption() else + $.cookie('hide_captions', 'true', expires: 3650, path: '/') @$('.hide-subtitles').attr('title', 'Turn on captions') @el.addClass('closed') From d893a14a531eb6c636ca2a3c56bcbdae14812a50 Mon Sep 17 00:00:00 2001 From: kimth Date: Fri, 14 Sep 2012 17:24:15 -0400 Subject: [PATCH 2/5] Load player before turning off caption --- common/lib/xmodule/xmodule/js/src/video/display.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index 90e465d0ec..e226072b50 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -10,11 +10,6 @@ class @Video @fetchMetadata() @parseSpeed() - if $.cookie('hide_captions') == 'true' - @el.addClass('closed') - else - @el.removeClass('closed') - $("#video_#{@id}").data('video', this).addClass('video-load-complete') if YT.Player @@ -24,6 +19,11 @@ class @Video $('.course-content .video').each -> $(this).data('video').embed() + if $.cookie('hide_captions') == 'true' + @el.addClass('closed') + else + @el.removeClass('closed') + youtubeId: (speed)-> @videos[speed || @speed] From 1625125e6fa4c539fc5e973101f9a876adf19b37 Mon Sep 17 00:00:00 2001 From: kimth Date: Sat, 15 Sep 2012 16:55:43 -0400 Subject: [PATCH 3/5] Respect object boundaries --- common/lib/xmodule/xmodule/js/src/video/display.coffee | 7 ++----- .../xmodule/js/src/video/display/video_player.coffee | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index e226072b50..2d7cb5fcfa 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -12,6 +12,8 @@ class @Video $("#video_#{@id}").data('video', this).addClass('video-load-complete') + @hide_captions = $.cookie('hide_captions') == 'true' + if YT.Player @embed() else @@ -19,11 +21,6 @@ class @Video $('.course-content .video').each -> $(this).data('video').embed() - if $.cookie('hide_captions') == 'true' - @el.addClass('closed') - else - @el.removeClass('closed') - youtubeId: (speed)-> @videos[speed || @speed] diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee index 4b265d20c8..79d27d2633 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee @@ -1,5 +1,6 @@ class @VideoPlayer extends Subview initialize: -> + console.log(@['video'].hide_captions) # Define a missing constant of Youtube API YT.PlayerState.UNSTARTED = -1 From 439ca1dd59fce07c46ec450d45b6e4f6ed6df7dd Mon Sep 17 00:00:00 2001 From: kimth Date: Sat, 15 Sep 2012 17:18:21 -0400 Subject: [PATCH 4/5] Write setter, toggle uses setter --- .../js/src/video/display/video_caption.coffee | 19 ++++++++++++------- .../js/src/video/display/video_player.coffee | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee index ae6b0c8ed1..b1e41afc3c 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_caption.coffee @@ -130,16 +130,21 @@ class @VideoCaption extends Subview toggle: (event) => event.preventDefault() - if @el.hasClass('closed') - $.cookie('hide_captions', 'false', expires: 3650, path: '/') + if @el.hasClass('closed') # Captions are "closed" e.g. turned off + @hideCaptions(false) + else # Captions are on + @hideCaptions(true) + + hideCaptions: (hide_captions) => + if hide_captions + @$('.hide-subtitles').attr('title', 'Turn on captions') + @el.addClass('closed') + else @$('.hide-subtitles').attr('title', 'Turn off captions') @el.removeClass('closed') @scrollCaption() - else - $.cookie('hide_captions', 'true', expires: 3650, path: '/') - @$('.hide-subtitles').attr('title', 'Turn on captions') - @el.addClass('closed') - + $.cookie('hide_captions', hide_captions, expires: 3650, path: '/') + captionHeight: -> if @el.hasClass('fullscreen') $(window).height() - @$('.video-controls').height() diff --git a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee index 79d27d2633..bb89def63d 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display/video_player.coffee @@ -1,6 +1,5 @@ class @VideoPlayer extends Subview initialize: -> - console.log(@['video'].hide_captions) # Define a missing constant of Youtube API YT.PlayerState.UNSTARTED = -1 @@ -46,6 +45,7 @@ class @VideoPlayer extends Subview events: onReady: @onReady onStateChange: @onStateChange + @caption.hideCaptions(@['video'].hide_captions) addToolTip: -> @$('.add-fullscreen, .hide-subtitles').qtip From 68e0701113616d03779974fc9b20bde4f7fc969a Mon Sep 17 00:00:00 2001 From: kimth Date: Sat, 15 Sep 2012 17:23:41 -0400 Subject: [PATCH 5/5] Remove extra line --- common/lib/xmodule/xmodule/js/src/video/display.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/display.coffee b/common/lib/xmodule/xmodule/js/src/video/display.coffee index 2d7cb5fcfa..6587f05899 100644 --- a/common/lib/xmodule/xmodule/js/src/video/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/video/display.coffee @@ -9,7 +9,6 @@ class @Video @parseVideos @el.data('streams') @fetchMetadata() @parseSpeed() - $("#video_#{@id}").data('video', this).addClass('video-load-complete') @hide_captions = $.cookie('hide_captions') == 'true'