Commit f57d5a61 by polesye Committed by Valera Rozuvan

Tidy up the code.

parent 92494ccd
...@@ -47,19 +47,19 @@ Feature: CMS.Video Component ...@@ -47,19 +47,19 @@ Feature: CMS.Video Component
Given I have created a Video component with subtitles Given I have created a Video component with subtitles
And Make sure captions are closed And Make sure captions are closed
Then Captions become invisible after 3 seconds Then Captions become invisible after 3 seconds
And Hover over CC button And I hover over button "CC"
Then Captions become visible after 0 seconds Then Captions become visible
And Hover over volume button And I hover over button "volume"
Then Captions become invisible after 3 seconds Then Captions become invisible after 3 seconds
# 8 # 8
Scenario: Open captions never become invisible Scenario: Open captions never become invisible
Given I have created a Video component with subtitles Given I have created a Video component with subtitles
And Make sure captions are open And Make sure captions are open
Then Captions are visible after 0 seconds Then Captions are visible
And Hover over CC button And I hover over button "CC"
Then Captions are visible after 3 seconds Then Captions are visible after 3 seconds
And Hover over volume button And I hover over button "volume"
Then Captions are visible after 3 seconds Then Captions are visible after 3 seconds
# 9 # 9
...@@ -67,5 +67,5 @@ Feature: CMS.Video Component ...@@ -67,5 +67,5 @@ Feature: CMS.Video Component
Given I have created a Video component with subtitles Given I have created a Video component with subtitles
And Make sure captions are closed And Make sure captions are closed
Then Captions become invisible after 3 seconds Then Captions become invisible after 3 seconds
And Hover over volume button And I hover over button "volume"
Then Captions are invisible after 0 seconds Then Captions are invisible
...@@ -4,6 +4,11 @@ from lettuce import world, step ...@@ -4,6 +4,11 @@ from lettuce import world, step
from xmodule.modulestore import Location from xmodule.modulestore import Location
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
BUTTONS = {
'CC': '.hide-subtitles',
'volume': '.volume',
}
@step('I have created a Video component$') @step('I have created a Video component$')
def i_created_a_video_component(step): def i_created_a_video_component(step):
...@@ -19,6 +24,7 @@ def i_created_a_video_component(step): ...@@ -19,6 +24,7 @@ def i_created_a_video_component(step):
def i_created_a_video_with_subs(_step): def i_created_a_video_with_subs(_step):
_step.given('I have created a Video component with subtitles "OEoXaMPEzfM"') _step.given('I have created a Video component with subtitles "OEoXaMPEzfM"')
@step('I have created a Video component with subtitles "([^"]*)"$') @step('I have created a Video component with subtitles "([^"]*)"$')
def i_created_a_video_with_subs_with_name(_step, sub_id): def i_created_a_video_with_subs_with_name(_step, sub_id):
_step.given('I have created a Video component') _step.given('I have created a Video component')
...@@ -127,15 +133,17 @@ def set_captions_visibility_state(_step, captions_state): ...@@ -127,15 +133,17 @@ def set_captions_visibility_state(_step, captions_state):
world.browser.find_by_css('.hide-subtitles').click() world.browser.find_by_css('.hide-subtitles').click()
@step('Hover over (.+) button$') @step('I hover over button "([^"]*)"$')
def hover_over_button(_step, button): def hover_over_button(_step, button):
if button.strip() == 'CC': world.browser.find_by_css(BUTTONS[button.strip()]).mouse_over()
world.browser.find_by_css('.hide-subtitles').mouse_over()
else:
world.browser.find_by_css('.volume').mouse_over()
@step('Captions (?:are|become) (.+)$')
def are_captions_visibile(_step, visibility_state):
_step.given('Captions are {0} after 0 seconds'.format(visibility_state))
@step('Captions become (.+) after (.+) seconds$')
@step('Captions (?:are|become) (.+) after (.+) seconds$')
def check_captions_visibility_state(_step, visibility_state, timeout): def check_captions_visibility_state(_step, visibility_state, timeout):
timeout = int(timeout.strip()) timeout = int(timeout.strip())
...@@ -148,8 +156,3 @@ def check_captions_visibility_state(_step, visibility_state, timeout): ...@@ -148,8 +156,3 @@ def check_captions_visibility_state(_step, visibility_state, timeout):
else: else:
assert not world.css_visible('.subtitles') assert not world.css_visible('.subtitles')
@step('Captions are (.+) after (.+) seconds$')
def check_captions_visibility_state2(_step, visibility_state, timeout):
check_captions_visibility_state(_step, visibility_state, timeout)
...@@ -264,7 +264,9 @@ function (VideoPlayer) { ...@@ -264,7 +264,9 @@ function (VideoPlayer) {
// The function set initial configuration and preparation. // The function set initial configuration and preparation.
function initialize(element) { function initialize(element) {
var _this = this, tempYtTestTimeout; var _this = this,
regExp = /^true$/i,
data, tempYtTestTimeout;
// This is used in places where we instead would have to check if an // This is used in places where we instead would have to check if an
// element has a CSS class 'fullscreen'. // element has a CSS class 'fullscreen'.
this.isFullScreen = false; this.isFullScreen = false;
...@@ -274,6 +276,9 @@ function (VideoPlayer) { ...@@ -274,6 +276,9 @@ function (VideoPlayer) {
this.elVideoWrapper = this.el.find('.video-wrapper'); this.elVideoWrapper = this.el.find('.video-wrapper');
this.id = this.el.attr('id').replace(/video_/, ''); this.id = this.el.attr('id').replace(/video_/, '');
// jQuery .data() return object with keys in lower camelCase format.
data = this.el.data();
console.log( console.log(
'[Video info]: Initializing video with id "' + this.id + '".' '[Video info]: Initializing video with id "' + this.id + '".'
); );
...@@ -284,37 +289,26 @@ function (VideoPlayer) { ...@@ -284,37 +289,26 @@ function (VideoPlayer) {
this.config = { this.config = {
element: element, element: element,
start: this.el.data('start'), start: data['start'],
end: this.el.data('end'), end: data['end'],
caption_data_dir: data['captionDataDir'],
caption_data_dir: this.el.data('caption-data-dir'), caption_asset_path: data['captionAssetPath'],
caption_asset_path: this.el.data('caption-asset-path'), show_captions: regExp.test(data['showCaptions'].toString()),
show_captions: ( youtubeStreams: data['streams'],
this.el.data('show-captions') autohideHtml5: regExp.test(data['autohideHtml5'].toString()),
.toString().toLowerCase() === 'true' sub: data['sub'],
), mp4Source: data['mp4Source'],
youtubeStreams: this.el.data('streams'), webmSource: data['webmSource'],
oggSource: data['oggSource'],
autohideHtml5: ( ytTestUrl: data['ytTestUrl'],
this.el.data('autohide-html5')
.toString().toLowerCase() === 'true'
),
sub: this.el.data('sub'),
mp4Source: this.el.data('mp4-source'),
webmSource: this.el.data('webm-source'),
oggSource: this.el.data('ogg-source'),
ytTestUrl: this.el.data('yt-test-url'),
fadeOutTimeout: 1400, fadeOutTimeout: 1400,
captionsFreezeTime: 10000,
availableQualities: ['hd720', 'hd1080', 'highres'] availableQualities: ['hd720', 'hd1080', 'highres']
}; };
// Check if the YT test timeout has been set. If not, or it is in // Check if the YT test timeout has been set. If not, or it is in
// improper format, then set to default value. // improper format, then set to default value.
tempYtTestTimeout = parseInt(this.el.data('yt-test-timeout'), 10); tempYtTestTimeout = parseInt(data['ytTestTimeout'], 10);
if (!isFinite(tempYtTestTimeout)) { if (!isFinite(tempYtTestTimeout)) {
tempYtTestTimeout = 1500; tempYtTestTimeout = 1500;
} }
......
...@@ -294,12 +294,13 @@ function () { ...@@ -294,12 +294,13 @@ function () {
_this = this; _this = this;
this.videoCaption.subtitlesEl.fadeOut( this.videoCaption.subtitlesEl
this.videoCaption.fadeOutTimeout, .fadeOut(
function () { this.videoCaption.fadeOutTimeout,
function () {
_this.captionState = 'invisible'; _this.captionState = 'invisible';
}); }
);
} }
function resize() { function resize() {
...@@ -321,7 +322,7 @@ function () { ...@@ -321,7 +322,7 @@ function () {
this.videoCaption.frozen = setTimeout( this.videoCaption.frozen = setTimeout(
this.videoCaption.onMouseLeave, this.videoCaption.onMouseLeave,
10000 this.config.captionsFreezeTime
); );
} }
...@@ -391,17 +392,18 @@ function () { ...@@ -391,17 +392,18 @@ function () {
container.append(liEl); container.append(liEl);
}); });
this.videoCaption.subtitlesEl.html(container.html()); this.videoCaption.subtitlesEl
.html(container.html())
this.videoCaption.subtitlesEl.find('li[data-index]').on({ .find('li[data-index]')
mouseover: this.videoCaption.captionMouseOverOut, .on({
mouseout: this.videoCaption.captionMouseOverOut, mouseover: this.videoCaption.captionMouseOverOut,
mousedown: this.videoCaption.captionMouseDown, mouseout: this.videoCaption.captionMouseOverOut,
click: this.videoCaption.captionClick, mousedown: this.videoCaption.captionMouseDown,
focus: this.videoCaption.captionFocus, click: this.videoCaption.captionClick,
blur: this.videoCaption.captionBlur, focus: this.videoCaption.captionFocus,
keydown: this.videoCaption.captionKeyDown blur: this.videoCaption.captionBlur,
}); keydown: this.videoCaption.captionKeyDown
});
// Enables or disables automatic scrolling of the captions when the // Enables or disables automatic scrolling of the captions when the
// video is playing. This feature has to be disabled when tabbing // video is playing. This feature has to be disabled when tabbing
...@@ -422,14 +424,15 @@ function () { ...@@ -422,14 +424,15 @@ function () {
// outline has to be drawn (tabbing) or not (mouse click). // outline has to be drawn (tabbing) or not (mouse click).
this.videoCaption.isMouseFocus = false; this.videoCaption.isMouseFocus = false;
this.videoCaption.subtitlesEl.prepend( this.videoCaption.subtitlesEl
$('<li class="spacing">') .prepend(
.height(this.videoCaption.topSpacingHeight()) $('<li class="spacing">')
); .height(this.videoCaption.topSpacingHeight())
this.videoCaption.subtitlesEl.append( )
$('<li class="spacing">') .append(
.height(this.videoCaption.bottomSpacingHeight()) $('<li class="spacing">')
); .height(this.videoCaption.bottomSpacingHeight())
);
this.videoCaption.rendered = true; this.videoCaption.rendered = true;
} }
...@@ -685,7 +688,8 @@ function () { ...@@ -685,7 +688,8 @@ function () {
} }
function hideCaptions(hide_captions, update_cookie) { function hideCaptions(hide_captions, update_cookie) {
var type; var hideSubtitlesEl = this.videoCaption.hideSubtitlesEl,
type;
if (typeof update_cookie === 'undefined') { if (typeof update_cookie === 'undefined') {
update_cookie = true; update_cookie = true;
...@@ -694,20 +698,20 @@ function () { ...@@ -694,20 +698,20 @@ function () {
if (hide_captions) { if (hide_captions) {
type = 'hide_transcript'; type = 'hide_transcript';
this.captionsHidden = true; this.captionsHidden = true;
this.videoCaption.hideSubtitlesEl.attr(
'title', gettext('Turn on captions') hideSubtitlesEl
); .attr('title', gettext('Turn on captions'))
this.videoCaption.hideSubtitlesEl
.text(gettext('Turn on captions')); .text(gettext('Turn on captions'));
this.el.addClass('closed'); this.el.addClass('closed');
} else { } else {
type = 'show_transcript'; type = 'show_transcript';
this.captionsHidden = false; this.captionsHidden = false;
this.videoCaption.hideSubtitlesEl.attr(
'title', gettext('Turn off captions') hideSubtitlesEl
); .attr('title', gettext('Turn off captions'))
this.videoCaption.hideSubtitlesEl
.text(gettext('Turn off captions')); .text(gettext('Turn off captions'));
this.el.removeClass('closed'); this.el.removeClass('closed');
this.videoCaption.scrollCaption(); this.videoCaption.scrollCaption();
} }
......
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