Commit 6ea7545c by Chris Rodriguez

AC-385 adding events for closed captions

parent f7ec039b
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
}); });
it('can emit "show_transcript" event', function () { it('can emit "show_transcript" event', function () {
state.el.trigger('captions:show'); state.el.trigger('transcript:show');
expect(Logger.log).toHaveBeenCalledWith('show_transcript', { expect(Logger.log).toHaveBeenCalledWith('show_transcript', {
id: 'id', id: 'id',
code: 'html5', code: 'html5',
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
}); });
it('can emit "hide_transcript" event', function () { it('can emit "hide_transcript" event', function () {
state.el.trigger('captions:hide'); state.el.trigger('transcript:hide');
expect(Logger.log).toHaveBeenCalledWith('hide_transcript', { expect(Logger.log).toHaveBeenCalledWith('hide_transcript', {
id: 'id', id: 'id',
code: 'html5', code: 'html5',
...@@ -152,6 +152,24 @@ ...@@ -152,6 +152,24 @@
}); });
}); });
it('can emit "edx.video.closed_captions.shown" event', function () {
state.el.trigger('captions:show');
expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.shown', {
id: 'id',
code: 'html5',
current_time: 10
});
});
it('can emit "edx.video.closed_captions.hidden" event', function () {
state.el.trigger('captions:hide');
expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.hidden', {
id: 'id',
code: 'html5',
current_time: 10
});
});
it('can destroy itself', function () { it('can destroy itself', function () {
var plugin = state.videoEventsPlugin; var plugin = state.videoEventsPlugin;
spyOn($.fn, 'off').and.callThrough(); spyOn($.fn, 'off').and.callThrough();
...@@ -167,6 +185,8 @@ ...@@ -167,6 +185,8 @@
'speedchange': plugin.onSpeedChange, 'speedchange': plugin.onSpeedChange,
'language_menu:show': plugin.onShowLanguageMenu, 'language_menu:show': plugin.onShowLanguageMenu,
'language_menu:hide': plugin.onHideLanguageMenu, 'language_menu:hide': plugin.onHideLanguageMenu,
'transcript:show': plugin.onShowTranscript,
'transcript:hide': plugin.onHideTranscript,
'captions:show': plugin.onShowCaptions, 'captions:show': plugin.onShowCaptions,
'captions:hide': plugin.onHideCaptions, 'captions:hide': plugin.onHideCaptions,
'destroy': plugin.destroy 'destroy': plugin.destroy
......
...@@ -17,7 +17,9 @@ define('video/09_events_plugin.js', [], function() { ...@@ -17,7 +17,9 @@ define('video/09_events_plugin.js', [], function() {
_.bindAll(this, 'onReady', 'onPlay', 'onPause', 'onEnded', 'onSeek', _.bindAll(this, 'onReady', 'onPlay', 'onPause', 'onEnded', 'onSeek',
'onSpeedChange', 'onShowLanguageMenu', 'onHideLanguageMenu', 'onSkip', 'onSpeedChange', 'onShowLanguageMenu', 'onHideLanguageMenu', 'onSkip',
'onShowCaptions', 'onHideCaptions', 'destroy'); 'onShowTranscript', 'onHideTranscript', 'onShowCaptions', 'onHideCaptions',
'destroy');
this.state = state; this.state = state;
this.options = _.extend({}, options); this.options = _.extend({}, options);
this.state.videoEventsPlugin = this; this.state.videoEventsPlugin = this;
...@@ -45,6 +47,8 @@ define('video/09_events_plugin.js', [], function() { ...@@ -45,6 +47,8 @@ define('video/09_events_plugin.js', [], function() {
'speedchange': this.onSpeedChange, 'speedchange': this.onSpeedChange,
'language_menu:show': this.onShowLanguageMenu, 'language_menu:show': this.onShowLanguageMenu,
'language_menu:hide': this.onHideLanguageMenu, 'language_menu:hide': this.onHideLanguageMenu,
'transcript:show': this.onShowTranscript,
'transcript:hide': this.onHideTranscript,
'captions:show': this.onShowCaptions, 'captions:show': this.onShowCaptions,
'captions:hide': this.onHideCaptions, 'captions:hide': this.onHideCaptions,
'destroy': this.destroy 'destroy': this.destroy
...@@ -108,14 +112,22 @@ define('video/09_events_plugin.js', [], function() { ...@@ -108,14 +112,22 @@ define('video/09_events_plugin.js', [], function() {
this.log('video_hide_cc_menu', { language: this.getCurrentLanguage() }); this.log('video_hide_cc_menu', { language: this.getCurrentLanguage() });
}, },
onShowCaptions: function () { onShowTranscript: function () {
this.log('show_transcript', {current_time: this.getCurrentTime()}); this.log('show_transcript', {current_time: this.getCurrentTime()});
}, },
onHideCaptions: function () { onHideTranscript: function () {
this.log('hide_transcript', {current_time: this.getCurrentTime()}); this.log('hide_transcript', {current_time: this.getCurrentTime()});
}, },
onShowCaptions: function () {
this.log('edx.video.closed_captions.shown', {current_time: this.getCurrentTime()});
},
onHideCaptions: function () {
this.log('edx.video.closed_captions.hidden', {current_time: this.getCurrentTime()});
},
getCurrentTime: function () { getCurrentTime: function () {
var player = this.state.videoPlayer; var player = this.state.videoPlayer;
return player ? player.currentTime : 0; return player ? player.currentTime : 0;
......
...@@ -1131,6 +1131,8 @@ ...@@ -1131,6 +1131,8 @@
this.captionDisplayEl this.captionDisplayEl
.text(gettext('(Caption will be displayed when you start playing the video.)')); .text(gettext('(Caption will be displayed when you start playing the video.)'));
} }
this.state.el.trigger('captions:show');
}, },
hideClosedCaptions: function() { hideClosedCaptions: function() {
...@@ -1144,6 +1146,8 @@ ...@@ -1144,6 +1146,8 @@
.removeClass('is-active') .removeClass('is-active')
.find('.control-text') .find('.control-text')
.text(gettext('Turn on closed captioning')); .text(gettext('Turn on closed captioning'));
this.state.el.trigger('captions:hide');
}, },
updateCaptioningCookie: function(method) { updateCaptioningCookie: function(method) {
...@@ -1191,7 +1195,7 @@ ...@@ -1191,7 +1195,7 @@
state.el.addClass('closed'); state.el.addClass('closed');
text = gettext('Turn on transcripts'); text = gettext('Turn on transcripts');
if (trigger_event) { if (trigger_event) {
this.state.el.trigger('captions:hide'); this.state.el.trigger('transcript:hide');
} }
transcriptControlEl transcriptControlEl
...@@ -1204,7 +1208,7 @@ ...@@ -1204,7 +1208,7 @@
this.scrollCaption(); this.scrollCaption();
text = gettext('Turn off transcripts'); text = gettext('Turn off transcripts');
if (trigger_event) { if (trigger_event) {
this.state.el.trigger('captions:show'); this.state.el.trigger('transcript:show');
} }
transcriptControlEl transcriptControlEl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment