Merge pull request #23041 from edx/ahtisham/PROD-920

Video Transcripts setting not preserved
This commit is contained in:
Ahtisham Shahid
2020-02-17 13:58:15 +05:00
committed by GitHub
2 changed files with 46 additions and 2 deletions

View File

@@ -36,13 +36,15 @@
'previousLanguageMenuItem', 'nextLanguageMenuItem', 'handleCaptionToggle',
'showClosedCaptions', 'hideClosedCaptions', 'toggleClosedCaptions',
'updateCaptioningCookie', 'handleCaptioningCookie', 'handleTranscriptToggle',
'listenForDragDrop'
'listenForDragDrop', 'handleTranscriptCookie', 'updateTranscriptCookie'
);
this.state = state;
this.state.videoCaption = this;
this.renderElements();
this.handleCaptioningCookie();
this.listenForDragDrop();
this.handleTranscriptCookie();
return $.Deferred().resolve().promise();
};
@@ -1142,11 +1144,12 @@
*/
toggle: function(event) {
event.preventDefault();
if (this.state.el.hasClass('closed')) {
this.hideCaptions(false, true, true);
this.updateTranscriptCookie(true);
} else {
this.hideCaptions(true, true, true);
this.updateTranscriptCookie(false);
}
},
@@ -1232,6 +1235,31 @@
});
}
},
handleTranscriptCookie: function() {
if ($.cookie('show_transcript') === null) {
return;
}
if ($.cookie('show_transcript') !== 'false') {
this.state.hideCaptions = false;
// keep it going until turned off or in case of null initially change to true
this.updateTranscriptCookie(true);
} else {
this.state.hideCaptions = true;
}
this.hideCaptions(this.state.hideCaptions, true, true);
},
updateTranscriptCookie: function(showTranscript) {
if (showTranscript) {
$.cookie('show_transcript', 'true', {
expires: 3650,
path: '/'
});
} else {
$.cookie('show_transcript', 'false', {
path: '/'
});
}
},
listenForDragDrop: function() {
var captions = this.captionDisplayEl['0'];

View File

@@ -288,6 +288,22 @@ class CMSVideoTest(CMSVideoBaseTest):
self.assertTrue(self.video.is_captions_visible())
def test_transcript_state_is_saved_on_reload(self):
"""
Scenario: Transcripts state is preserved
Given I have created a Video component with subtitles
And I have toggled off the transcript
After page reload transcript is already off
Then when I view the video it does show the captions
"""
self._create_course_unit(subtitles=True)
self.video.click_player_button('transcript_button')
self.assertFalse(self.video.is_captions_visible())
self.video.click_player_button('transcript_button')
self.assertTrue(self.video.is_captions_visible())
self.browser.refresh()
self.assertTrue(self.video.is_captions_visible())
def test_caption_line_focus(self):
"""
Scenario: When enter key is pressed on a caption, an outline shows around it