Commit 28888bda by Valera Rozuvan

Initial commit.

parent f8a49edd
...@@ -15,6 +15,13 @@ div.video { ...@@ -15,6 +15,13 @@ div.video {
@include clearfix; @include clearfix;
} }
div.focus_grabber {
position: relative;
display: inline;
width: 0px;
height: 0px;
}
article.video-wrapper { article.video-wrapper {
float: left; float: left;
margin-right: flex-gutter(9); margin-right: flex-gutter(9);
......
(function (requirejs, require, define) {
// FocusGrabber module.
define(
'video/025_focus_grabber.js',
[],
function () {
return function (state) {
state.focusGrabber = {};
_makeFunctionsPublic(state);
_renderElements(state);
_bindHandlers(state);
};
// Private functions.
function _makeFunctionsPublic(state) {
state.focusGrabber.enableFocusGrabber = _.bind(enableFocusGrabber, state);
state.focusGrabber.disableFocusGrabber = _.bind(disableFocusGrabber, state);
state.focusGrabber.onFocus = _.bind(onFocus, state);
state.focusGrabber.onBlur = _.bind(onBlur, state);
}
function _renderElements(state) {
state.focusGrabber.elFirst = state.el.find('.focus_grabber.first');
state.focusGrabber.elLast = state.el.find('.focus_grabber.last');
state.focusGrabber.disableFocusGrabber();
}
function _bindHandlers(state) {
state.focusGrabber.elFirst.on('focus', state.focusGrabber.onFocus);
state.focusGrabber.elLast.on('focus', state.focusGrabber.onFocus);
state.focusGrabber.elFirst.on('blur', state.focusGrabber.onBlur);
state.focusGrabber.elLast.on('blur', state.focusGrabber.onBlur);
}
// Public functions.
function enableFocusGrabber() {
var tabIndex;
if ($(document.activeElement).parents().hasClass('video')) {
tabIndex = -1;
} else {
tabIndex = 0;
}
this.focusGrabber.elFirst.attr('tabindex', tabIndex);
this.focusGrabber.elLast.attr('tabindex', tabIndex);
$(document.activeElement).blur();
if (tabIndex === -1) {
this.focusGrabber.elFirst.trigger(
'focus',
{
simpleFocus: true
}
);
}
}
function disableFocusGrabber() {
this.focusGrabber.elFirst.attr('tabindex', -1);
this.focusGrabber.elLast.attr('tabindex', -1);
}
function onFocus(event, params) {
if (params && params.simpleFocus) {
this.focusGrabber.elFirst.attr('tabindex', 0);
this.focusGrabber.elLast.attr('tabindex', 0);
return;
}
this.el.trigger('mousemove');
this.el.trigger('focus');
$('html, body').animate({
scrollTop: this.el.offset().top
}, 200);
this.focusGrabber.disableFocusGrabber();
}
function onBlur(event) {
this.el.trigger('mousemove');
this.el.trigger('focus');
$('html, body').animate({
scrollTop: this.el.offset().top
}, 200);
}
});
}(RequireJS.requirejs, RequireJS.require, RequireJS.define));
...@@ -77,7 +77,7 @@ function () { ...@@ -77,7 +77,7 @@ function () {
state.el.on('mousemove', state.videoControl.showControls); state.el.on('mousemove', state.videoControl.showControls);
state.el.on('keydown', state.videoControl.showControls); state.el.on('keydown', state.videoControl.showControls);
} }
// The state.previousFocus is used in video_speed_control to track // The state.previousFocus is used in video_speed_control to track
// the element that had the focus before it. // the element that had the focus before it.
state.videoControl.playPauseEl.on('blur', function () { state.videoControl.playPauseEl.on('blur', function () {
state.previousFocus = 'playPause'; state.previousFocus = 'playPause';
...@@ -128,6 +128,8 @@ function () { ...@@ -128,6 +128,8 @@ function () {
this.videoControl.el.fadeOut(this.videoControl.fadeOutTimeout, function () { this.videoControl.el.fadeOut(this.videoControl.fadeOutTimeout, function () {
_this.controlState = 'invisible'; _this.controlState = 'invisible';
_this.focusGrabber.enableFocusGrabber();
}); });
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
require( require(
[ [
'video/01_initialize.js', 'video/01_initialize.js',
'video/025_focus_grabber.js',
'video/04_video_control.js', 'video/04_video_control.js',
'video/05_video_quality_control.js', 'video/05_video_quality_control.js',
'video/06_video_progress_slider.js', 'video/06_video_progress_slider.js',
...@@ -13,6 +14,7 @@ require( ...@@ -13,6 +14,7 @@ require(
], ],
function ( function (
Initialize, Initialize,
FocusGrabber,
VideoControl, VideoControl,
VideoQualityControl, VideoQualityControl,
VideoProgressSlider, VideoProgressSlider,
...@@ -60,6 +62,7 @@ function ( ...@@ -60,6 +62,7 @@ function (
youtubeXhr = state.youtubeXhr; youtubeXhr = state.youtubeXhr;
} }
FocusGrabber(state);
VideoControl(state); VideoControl(state);
VideoQualityControl(state); VideoQualityControl(state);
VideoProgressSlider(state); VideoProgressSlider(state);
......
...@@ -136,6 +136,7 @@ class VideoModule(VideoFields, XModule): ...@@ -136,6 +136,7 @@ class VideoModule(VideoFields, XModule):
js = { js = {
'js': [ 'js': [
resource_string(__name__, 'js/src/video/01_initialize.js'), resource_string(__name__, 'js/src/video/01_initialize.js'),
resource_string(__name__, 'js/src/video/025_focus_grabber.js'),
resource_string(__name__, 'js/src/video/02_html5_video.js'), resource_string(__name__, 'js/src/video/02_html5_video.js'),
resource_string(__name__, 'js/src/video/03_video_player.js'), resource_string(__name__, 'js/src/video/03_video_player.js'),
resource_string(__name__, 'js/src/video/04_video_control.js'), resource_string(__name__, 'js/src/video/04_video_control.js'),
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
data-yt-test-timeout="${yt_test_timeout}" data-yt-test-timeout="${yt_test_timeout}"
data-yt-test-url="${yt_test_url}" data-yt-test-url="${yt_test_url}"
> >
<div class="focus_grabber first"></div>
<div class="tc-wrapper"> <div class="tc-wrapper">
<article class="video-wrapper"> <article class="video-wrapper">
<div class="video-player-pre"></div> <div class="video-player-pre"></div>
...@@ -70,6 +72,8 @@ ...@@ -70,6 +72,8 @@
<ol class="subtitles" tabindex="0" title="Captions"><li></li></ol> <ol class="subtitles" tabindex="0" title="Captions"><li></li></ol>
</div> </div>
<div class="focus_grabber last"></div>
</div> </div>
% if sources.get('main'): % if sources.get('main'):
......
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