Commit 6713d6c7 by Valera Rozuvan

Work in progress.

parent 7cfe279f
...@@ -271,6 +271,7 @@ function (VideoPlayer) { ...@@ -271,6 +271,7 @@ function (VideoPlayer) {
// The parent element of the video, and the ID. // The parent element of the video, and the ID.
this.el = $(element).find('.video'); this.el = $(element).find('.video');
this.elVideoWrapper = this.el.find('.video-wrapper');
this.id = this.el.attr('id').replace(/video_/, ''); this.id = this.el.attr('id').replace(/video_/, '');
console.log( console.log(
......
...@@ -34,11 +34,15 @@ function () { ...@@ -34,11 +34,15 @@ function () {
// function _makeFunctionsPublic(state) // function _makeFunctionsPublic(state)
// //
// Functions which will be accessible via 'state' object. When called, these functions will // Functions which will be accessible via 'state' object. When called,
// get the 'state' object as a context. // these functions will get the 'state' object as a context.
function _makeFunctionsPublic(state) { function _makeFunctionsPublic(state) {
state.videoCaption.autoShowCaptions = _.bind(autoShowCaptions, state); state.videoCaption.autoShowCaptions = _.bind(
state.videoCaption.autoHideCaptions = _.bind(autoHideCaptions, state); autoShowCaptions, state
);
state.videoCaption.autoHideCaptions = _.bind(
autoHideCaptions, state
);
state.videoCaption.resize = _.bind(resize, state); state.videoCaption.resize = _.bind(resize, state);
state.videoCaption.toggle = _.bind(toggle, state); state.videoCaption.toggle = _.bind(toggle, state);
state.videoCaption.onMouseEnter = _.bind(onMouseEnter, state); state.videoCaption.onMouseEnter = _.bind(onMouseEnter, state);
...@@ -46,24 +50,36 @@ function () { ...@@ -46,24 +50,36 @@ function () {
state.videoCaption.onMovement = _.bind(onMovement, state); state.videoCaption.onMovement = _.bind(onMovement, state);
state.videoCaption.renderCaption = _.bind(renderCaption, state); state.videoCaption.renderCaption = _.bind(renderCaption, state);
state.videoCaption.captionHeight = _.bind(captionHeight, state); state.videoCaption.captionHeight = _.bind(captionHeight, state);
state.videoCaption.topSpacingHeight = _.bind(topSpacingHeight, state); state.videoCaption.topSpacingHeight = _.bind(
state.videoCaption.bottomSpacingHeight = _.bind(bottomSpacingHeight, state); topSpacingHeight, state
);
state.videoCaption.bottomSpacingHeight = _.bind(
bottomSpacingHeight, state
);
state.videoCaption.scrollCaption = _.bind(scrollCaption, state); state.videoCaption.scrollCaption = _.bind(scrollCaption, state);
state.videoCaption.search = _.bind(search, state); state.videoCaption.search = _.bind(search, state);
state.videoCaption.play = _.bind(play, state); state.videoCaption.play = _.bind(play, state);
state.videoCaption.pause = _.bind(pause, state); state.videoCaption.pause = _.bind(pause, state);
state.videoCaption.seekPlayer = _.bind(seekPlayer, state); state.videoCaption.seekPlayer = _.bind(seekPlayer, state);
state.videoCaption.hideCaptions = _.bind(hideCaptions, state); state.videoCaption.hideCaptions = _.bind(hideCaptions, state);
state.videoCaption.calculateOffset = _.bind(calculateOffset, state); state.videoCaption.calculateOffset = _.bind(
calculateOffset, state
);
state.videoCaption.updatePlayTime = _.bind(updatePlayTime, state); state.videoCaption.updatePlayTime = _.bind(updatePlayTime, state);
state.videoCaption.setSubtitlesHeight = _.bind(setSubtitlesHeight, state); state.videoCaption.setSubtitlesHeight = _.bind(
setSubtitlesHeight, state
);
state.videoCaption.renderElements = _.bind(renderElements, state); state.videoCaption.renderElements = _.bind(renderElements, state);
state.videoCaption.bindHandlers = _.bind(bindHandlers, state); state.videoCaption.bindHandlers = _.bind(bindHandlers, state);
state.videoCaption.fetchCaption = _.bind(fetchCaption, state); state.videoCaption.fetchCaption = _.bind(fetchCaption, state);
state.videoCaption.captionURL = _.bind(captionURL, state); state.videoCaption.captionURL = _.bind(captionURL, state);
state.videoCaption.captionMouseOverOut = _.bind(captionMouseOverOut, state); state.videoCaption.captionMouseOverOut = _.bind(
state.videoCaption.captionMouseDown = _.bind(captionMouseDown, state); captionMouseOverOut, state
);
state.videoCaption.captionMouseDown = _.bind(
captionMouseDown, state
);
state.videoCaption.captionClick = _.bind(captionClick, state); state.videoCaption.captionClick = _.bind(captionClick, state);
state.videoCaption.captionFocus = _.bind(captionFocus, state); state.videoCaption.captionFocus = _.bind(captionFocus, state);
state.videoCaption.captionBlur = _.bind(captionBlur, state); state.videoCaption.captionBlur = _.bind(captionBlur, state);
...@@ -72,8 +88,9 @@ function () { ...@@ -72,8 +88,9 @@ function () {
// *************************************************************** // ***************************************************************
// Public functions start here. // Public functions start here.
// These are available via the 'state' object. Their context ('this' keyword) is the 'state' object. // These are available via the 'state' object. Their context ('this'
// The magic private function that makes them available and sets up their context is makeFunctionsPublic(). // keyword) is the 'state' object. The magic private function that makes
// them available and sets up their context is makeFunctionsPublic().
// *************************************************************** // ***************************************************************
/** /**
...@@ -109,10 +126,13 @@ function () { ...@@ -109,10 +126,13 @@ function () {
// function bindHandlers() // function bindHandlers()
// //
// Bind any necessary function callbacks to DOM events (click, mousemove, etc.). // Bind any necessary function callbacks to DOM events (click,
// mousemove, etc.).
function bindHandlers() { function bindHandlers() {
$(window).bind('resize', this.videoCaption.resize); $(window).bind('resize', this.videoCaption.resize);
this.videoCaption.hideSubtitlesEl.on('click', this.videoCaption.toggle); this.videoCaption.hideSubtitlesEl.on(
'click', this.videoCaption.toggle
);
this.videoCaption.subtitlesEl this.videoCaption.subtitlesEl
.on( .on(
...@@ -138,8 +158,12 @@ function () { ...@@ -138,8 +158,12 @@ function () {
// Moving slider on subtitles is not a mouse move, // Moving slider on subtitles is not a mouse move,
// but captions and controls should be showed. // but captions and controls should be showed.
this.videoCaption.subtitlesEl.on('scroll', this.videoCaption.autoShowCaptions); this.videoCaption.subtitlesEl.on(
this.videoCaption.subtitlesEl.on('scroll', this.videoControl.showControls); 'scroll', this.videoCaption.autoShowCaptions
);
this.videoCaption.subtitlesEl.on(
'scroll', this.videoControl.showControls
);
} }
} }
...@@ -209,7 +233,8 @@ function () { ...@@ -209,7 +233,8 @@ function () {
} }
function captionURL() { function captionURL() {
return '' + this.config.caption_asset_path + this.youtubeId('1.0') + '.srt.sjson'; return '' + this.config.caption_asset_path +
this.youtubeId('1.0') + '.srt.sjson';
} }
function autoShowCaptions(event) { function autoShowCaptions(event) {
...@@ -224,13 +249,17 @@ function () { ...@@ -224,13 +249,17 @@ function () {
this.videoCaption.subtitlesEl.show(); this.videoCaption.subtitlesEl.show();
this.captionState = 'visible'; this.captionState = 'visible';
} else if (this.captionState === 'hiding') { } else if (this.captionState === 'hiding') {
this.videoCaption.subtitlesEl.stop(true, false).css('opacity', 1).show(); this.videoCaption.subtitlesEl
.stop(true, false).css('opacity', 1).show();
this.captionState = 'visible'; this.captionState = 'visible';
} else if (this.captionState === 'visible') { } else if (this.captionState === 'visible') {
clearTimeout(this.captionHideTimeout); clearTimeout(this.captionHideTimeout);
} }
this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); this.captionHideTimeout = setTimeout(
this.videoCaption.autoHideCaptions,
this.videoCaption.fadeOutTimeout
);
this.captionsShowLock = false; this.captionsShowLock = false;
} }
...@@ -249,15 +278,20 @@ function () { ...@@ -249,15 +278,20 @@ function () {
_this = this; _this = this;
this.videoCaption.subtitlesEl.fadeOut(this.videoCaption.fadeOutTimeout, function () { this.videoCaption.subtitlesEl.fadeOut(
this.videoCaption.fadeOutTimeout,
function () {
_this.captionState = 'invisible'; _this.captionState = 'invisible';
}); });
} }
function resize() { function resize() {
this.videoCaption.subtitlesEl this.videoCaption.subtitlesEl
.find('.spacing:first').height(this.videoCaption.topSpacingHeight()) .find('.spacing:first')
.find('.spacing:last').height(this.videoCaption.bottomSpacingHeight()); .height(this.videoCaption.topSpacingHeight())
.find('.spacing:last')
.height(this.videoCaption.bottomSpacingHeight());
this.videoCaption.scrollCaption(); this.videoCaption.scrollCaption();
...@@ -269,7 +303,10 @@ function () { ...@@ -269,7 +303,10 @@ function () {
clearTimeout(this.videoCaption.frozen); clearTimeout(this.videoCaption.frozen);
} }
this.videoCaption.frozen = setTimeout(this.videoCaption.onMouseLeave, 10000); this.videoCaption.frozen = setTimeout(
this.videoCaption.onMouseLeave,
10000
);
} }
function onMouseLeave() { function onMouseLeave() {
...@@ -292,8 +329,9 @@ function () { ...@@ -292,8 +329,9 @@ function () {
var container = $('<ol>'), var container = $('<ol>'),
_this = this; _this = this;
this.el.find('.video-wrapper').after(this.videoCaption.subtitlesEl); this.elVideoWrapper.after(this.videoCaption.subtitlesEl);
this.el.find('.video-controls .secondary-controls').append(this.videoCaption.hideSubtitlesEl); this.el.find('.video-controls .secondary-controls')
.append(this.videoCaption.hideSubtitlesEl);
this.videoCaption.setSubtitlesHeight(); this.videoCaption.setSubtitlesHeight();
...@@ -301,7 +339,10 @@ function () { ...@@ -301,7 +339,10 @@ function () {
this.videoCaption.fadeOutTimeout = this.config.fadeOutTimeout; this.videoCaption.fadeOutTimeout = this.config.fadeOutTimeout;
this.videoCaption.subtitlesEl.addClass('html5'); this.videoCaption.subtitlesEl.addClass('html5');
this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); this.captionHideTimeout = setTimeout(
this.videoCaption.autoHideCaptions,
this.videoCaption.fadeOutTimeout
);
} }
this.videoCaption.hideCaptions(this.hide_captions); this.videoCaption.hideCaptions(this.hide_captions);
...@@ -344,16 +385,23 @@ function () { ...@@ -344,16 +385,23 @@ function () {
this.videoCaption.autoScrolling = true; this.videoCaption.autoScrolling = true;
// Keeps track of where the focus is situated in the array of captions. // Keeps track of where the focus is situated in the array of captions.
// Used to implement the automatic scrolling behavior and decide if the // Used to implement the automatic scrolling behavior and decide if the
// outline around a caption has to be hidden or shown on a mouseenter or // outline around a caption has to be hidden or shown on a mouseenter
// mouseleave. Initially, no caption has the focus, set the index to -1. // or mouseleave. Initially, no caption has the focus, set the
// index to -1.
this.videoCaption.currentCaptionIndex = -1; this.videoCaption.currentCaptionIndex = -1;
// Used to track if the focus is coming from a click or tabbing. This // Used to track if the focus is coming from a click or tabbing. This
// has to be known to decide if, when a caption gets the focus, an // has to be known to decide if, when a caption gets the focus, an
// 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($('<li class="spacing">').height(this.videoCaption.topSpacingHeight())); this.videoCaption.subtitlesEl.prepend(
this.videoCaption.subtitlesEl.append($('<li class="spacing">').height(this.videoCaption.bottomSpacingHeight())); $('<li class="spacing">')
.height(this.videoCaption.topSpacingHeight())
);
this.videoCaption.subtitlesEl.append(
$('<li class="spacing">')
.height(this.videoCaption.bottomSpacingHeight())
);
this.videoCaption.rendered = true; this.videoCaption.rendered = true;
} }
...@@ -403,7 +451,10 @@ function () { ...@@ -403,7 +451,10 @@ function () {
caption.addClass('focused'); caption.addClass('focused');
// The second and second to last elements turn automatic scrolling // The second and second to last elements turn automatic scrolling
// off again as it may have been enabled in captionBlur. // off again as it may have been enabled in captionBlur.
if (captionIndex <= 1 || captionIndex >= this.videoCaption.captions.length-2) { if (
captionIndex <= 1 ||
captionIndex >= this.videoCaption.captions.length - 2
) {
this.videoCaption.autoScrolling = false; this.videoCaption.autoScrolling = false;
} }
} }
...@@ -413,11 +464,11 @@ function () { ...@@ -413,11 +464,11 @@ function () {
var caption = $(event.target), var caption = $(event.target),
captionIndex = parseInt(caption.attr('data-index'), 10); captionIndex = parseInt(caption.attr('data-index'), 10);
caption.removeClass('focused'); caption.removeClass('focused');
// If we are on first or last index, we have to turn automatic scroll on // If we are on first or last index, we have to turn automatic scroll
// again when losing focus. There is no way to know in what direction we // on again when losing focus. There is no way to know in what
// are tabbing. So we could be on the first element and tabbing back out // direction we are tabbing. So we could be on the first element and
// of the captions or on the last element and tabbing forward out of the // tabbing back out of the captions or on the last element and tabbing
// captions. // forward out of the captions.
if (captionIndex === 0 || if (captionIndex === 0 ||
captionIndex === this.videoCaption.captions.length-1) { captionIndex === this.videoCaption.captions.length-1) {
this.videoCaption.autoScrolling = true; this.videoCaption.autoScrolling = true;
...@@ -434,9 +485,13 @@ function () { ...@@ -434,9 +485,13 @@ function () {
function scrollCaption() { function scrollCaption() {
var el = this.videoCaption.subtitlesEl.find('.current:first'); var el = this.videoCaption.subtitlesEl.find('.current:first');
// Automatic scrolling gets disabled if one of the captions has received // Automatic scrolling gets disabled if one of the captions has
// focus through tabbing. // received focus through tabbing.
if (!this.videoCaption.frozen && el.length && this.videoCaption.autoScrolling) { if (
!this.videoCaption.frozen &&
el.length &&
this.videoCaption.autoScrolling
) {
this.videoCaption.subtitlesEl.scrollTo( this.videoCaption.subtitlesEl.scrollTo(
el, el,
{ {
...@@ -565,11 +620,15 @@ function () { ...@@ -565,11 +620,15 @@ function () {
} }
function topSpacingHeight() { function topSpacingHeight() {
return this.videoCaption.calculateOffset(this.videoCaption.subtitlesEl.find('li:not(.spacing):first')); return this.videoCaption.calculateOffset(
this.videoCaption.subtitlesEl.find('li:not(.spacing):first')
);
} }
function bottomSpacingHeight() { function bottomSpacingHeight() {
return this.videoCaption.calculateOffset(this.videoCaption.subtitlesEl.find('li:not(.spacing):last')); return this.videoCaption.calculateOffset(
this.videoCaption.subtitlesEl.find('li:not(.spacing):last')
);
} }
function toggle(event) { function toggle(event) {
...@@ -588,14 +647,20 @@ function () { ...@@ -588,14 +647,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')); this.videoCaption.hideSubtitlesEl.attr(
this.videoCaption.hideSubtitlesEl.text(gettext('Turn on captions')); 'title', gettext('Turn on captions')
);
this.videoCaption.hideSubtitlesEl
.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')); this.videoCaption.hideSubtitlesEl.attr(
this.videoCaption.hideSubtitlesEl.text(gettext('Turn off captions')); 'title', gettext('Turn off captions')
);
this.videoCaption.hideSubtitlesEl
.text(gettext('Turn off captions'));
this.el.removeClass('closed'); this.el.removeClass('closed');
this.videoCaption.scrollCaption(); this.videoCaption.scrollCaption();
} }
...@@ -615,12 +680,19 @@ function () { ...@@ -615,12 +680,19 @@ function () {
} }
function captionHeight() { function captionHeight() {
var paddingTop;
if (this.isFullScreen) { if (this.isFullScreen) {
return $(window).height() - this.el.find('.video-controls').height() - paddingTop = parseInt(
this.videoCaption.subtitlesEl.css('padding-top'), 10
);
return $(window).height() -
this.videoControl.el.height() -
0.5 * this.videoControl.sliderEl.height() - 0.5 * this.videoControl.sliderEl.height() -
2 * parseInt(this.videoCaption.subtitlesEl.css('padding-top'), 10); 2 * paddingTop;
} else { } else {
return this.el.find('.video-wrapper').height(); return this.elVideoWrapper.height();
} }
} }
...@@ -629,13 +701,19 @@ function () { ...@@ -629,13 +701,19 @@ function () {
if (this.videoType === 'html5'){ if (this.videoType === 'html5'){
// on page load captionHidden = undefined // on page load captionHidden = undefined
if ( if (
(this.captionsHidden === undefined && this.hide_captions === true ) || (
(this.captionsHidden === true) ) { this.captionsHidden === undefined &&
// In case of html5 autoshowing subtitles, this.hide_captions === true
// we ajdust height of subs, by height of scrollbar ) ||
height = this.videoControl.el.height() + 0.5 * this.videoControl.sliderEl.height(); (this.captionsHidden === true)
// height of videoControl does not contain height of slider. ) {
// (css is set to absolute, to avoid yanking when slider autochanges its height) // In case of html5 autoshowing subtitles, we adjust height of
// subs, by height of scrollbar.
height = this.videoControl.el.height() +
0.5 * this.videoControl.sliderEl.height();
// Height of videoControl does not contain height of slider.
// css is set to absolute, to avoid yanking when slider
// autochanges its height.
} }
} }
this.videoCaption.subtitlesEl.css({ this.videoCaption.subtitlesEl.css({
......
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