Commit eeab7847 by polesye

Add resizing.

parent cca057df
...@@ -74,10 +74,8 @@ div.video { ...@@ -74,10 +74,8 @@ div.video {
} }
section.video-player { section.video-player {
height: 0;
overflow: hidden; overflow: hidden;
padding-bottom: 56.25%; min-height: 300px;
position: relative;
div { div {
&.hidden { &.hidden {
...@@ -85,12 +83,9 @@ div.video { ...@@ -85,12 +83,9 @@ div.video {
} }
} }
object, iframe { object, iframe, video {
border: none; border: none;
height: 100%; height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%; width: 100%;
} }
...@@ -701,15 +696,12 @@ div.video { ...@@ -701,15 +696,12 @@ div.video {
display: table-cell; display: table-cell;
vertical-align: middle; vertical-align: middle;
float: none; float: none;
}
object, iframe { object, iframe, video{
bottom: 0; position: absolute;
height: 100%; width: auto;
left: 0; height: auto;
overflow: hidden; }
position: fixed;
top: 0;
} }
section.video-controls { section.video-controls {
......
(function (requirejs, require, define) {
define(
'video/00_resizer.js',
[],
function () {
var Resizer = function (params) {
var defaults = {
container: window,
element: null,
containerRatio: null,
elementRatio: null
},
mode = null,
config;
var initialize = function (params) {
if (config) {
config = $.extend(true, config, params);
} else {
config = $.extend(true, {}, defaults, params);
}
if (!config.element) {
console.log('Required parameter `element` is not passed.');
}
return this;
};
var getData = function () {
var container = $(config.container),
containerWidth = container.width(),
containerHeight = container.height(),
containerRatio = config.containerRatio,
element = $(config.element),
elementRatio = config.elementRatio;
if (!containerRatio) {
containerRatio = containerWidth/containerHeight;
}
if (!elementRatio) {
elementRatio = element.width()/element.height();
}
return {
containerWidth: containerWidth,
containerHeight: containerHeight,
containerRatio: containerRatio,
element: element,
elementRatio: elementRatio
};
};
var align = function() {
var data = getData();
switch (mode) {
case 'height':
alignByHeightOnly();
break;
case 'width':
alignByWidthOnly();
break;
default:
if (data.containerRatio >= data.elementRatio) {
alignByHeightOnly();
} else {
alignByWidthOnly();
}
break;
}
return this;
};
var alignByWidthOnly = function () {
var data = getData(),
height = data.containerWidth/data.elementRatio;
data.element.css({
'height': height,
'width': data.containerWidth,
'top': 0.5*(data.containerHeight - height),
'left': 0
});
return this;
};
var alignByHeightOnly = function () {
var data = getData(),
width = data.containerHeight*data.elementRatio;
data.element.css({
'height': data.containerHeight,
'width': data.containerHeight*data.elementRatio,
'top': 0,
'left': 0.5*(data.containerWidth - width)
});
return this;
};
var setMode = function (param) {
if (_.isString(param)) {
mode = param;
align();
}
return this;
};
initialize.apply(this, arguments);
return {
align: align,
alignByWidthOnly: alignByWidthOnly,
alignByHeightOnly: alignByHeightOnly,
setParams: initialize,
setMode: setMode
};
};
return Resizer;
});
}(RequireJS.requirejs, RequireJS.require, RequireJS.define));
...@@ -216,10 +216,6 @@ function () { ...@@ -216,10 +216,6 @@ function () {
// currently doing. // currently doing.
this.videoEl = $(this.video); this.videoEl = $(this.video);
this.videoEl.css({
'width': '100%'
});
this.playerState = HTML5Video.PlayerState.UNSTARTED; this.playerState = HTML5Video.PlayerState.UNSTARTED;
// this.callStateChangeCallback(); // this.callStateChangeCallback();
...@@ -318,6 +314,6 @@ function () { ...@@ -318,6 +314,6 @@ function () {
// HTML5Video object - what this module exports. // HTML5Video object - what this module exports.
return HTML5Video; return HTML5Video;
}) });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// VideoPlayer module. // VideoPlayer module.
define( define(
'video/03_video_player.js', 'video/03_video_player.js',
['video/02_html5_video.js'], ['video/02_html5_video.js', 'video/00_resizer.js' ],
function (HTML5Video) { function (HTML5Video, Resizer) {
// VideoPlayer() function - what this module "exports". // VideoPlayer() function - what this module "exports".
return function (state) { return function (state) {
...@@ -343,7 +343,8 @@ function (HTML5Video) { ...@@ -343,7 +343,8 @@ function (HTML5Video) {
} }
function onReady() { function onReady() {
var availablePlaybackRates, baseSpeedSubs, _this; var availablePlaybackRates, baseSpeedSubs, _this,
player, videoWidth, videoHeight;
this.videoPlayer.log('load_video'); this.videoPlayer.log('load_video');
...@@ -420,6 +421,27 @@ function (HTML5Video) { ...@@ -420,6 +421,27 @@ function (HTML5Video) {
this.videoPlayer.player.setPlaybackRate(this.speed); this.videoPlayer.player.setPlaybackRate(this.speed);
} }
if (this.videoType === 'html5') {
player = this.videoEl = this.videoPlayer.player.videoEl;
videoWidth = player[0].videoWidth || player.width();
videoHeight = player[0].videoHeight || player.height();
} else {
player = this.videoEl = this.el.find('iframe');
videoWidth = player.attr('width') || player.width();
videoHeight = player.attr('height') || player.height();
}
this.resizer = new Resizer({
element: this.videoEl,
elementRatio: videoWidth/videoHeight,
container: this.videoEl.parent()
})
.setMode('width');
this.trigger('videoCaption.resize', null);
$(window).bind('resize', _.debounce(this.resizer.align, 100));
/* The following has been commented out to make sure autoplay is /* The following has been commented out to make sure autoplay is
disabled for students. disabled for students.
if ( if (
......
...@@ -170,22 +170,41 @@ function () { ...@@ -170,22 +170,41 @@ function () {
function toggleFullScreen(event) { function toggleFullScreen(event) {
event.preventDefault(); event.preventDefault();
var fullScreenClassNameEl = this.el.add(document.documentElement); var fullScreenClassNameEl = this.el.add(document.documentElement),
win = $(window),
text;
if (this.videoControl.fullScreenState) { if (this.videoControl.fullScreenState) {
this.videoControl.fullScreenState = false; this.videoControl.fullScreenState = this.isFullScreen = false;
fullScreenClassNameEl.removeClass('video-fullscreen'); fullScreenClassNameEl.removeClass('video-fullscreen');
this.isFullScreen = false; text = gettext('Fill browser');
this.videoControl.fullScreenEl.attr('title', gettext('Fill browser'))
.text(gettext('Fill browser')); this.resizer
.setParams({
container: this.videoEl.parent()
})
.setMode('width');
win.scrollTop(this.scrollPos);
} else { } else {
this.videoControl.fullScreenState = true; this.scrollPos = win.scrollTop();
win.scrollTop(0);
this.videoControl.fullScreenState = this.isFullScreen = true;
fullScreenClassNameEl.addClass('video-fullscreen'); fullScreenClassNameEl.addClass('video-fullscreen');
this.isFullScreen = true; text = gettext('Exit full browser');
this.videoControl.fullScreenEl.attr('title', gettext('Exit full browser'))
.text(gettext('Exit full browser')); this.resizer
.setParams({
container: window
})
.setMode('both');
} }
this.videoControl.fullScreenEl
.attr('title', text)
.text(text);
this.trigger('videoCaption.resize', null); this.trigger('videoCaption.resize', null);
} }
......
...@@ -700,7 +700,7 @@ function () { ...@@ -700,7 +700,7 @@ function () {
function hideCaptions(hide_captions, update_cookie) { function hideCaptions(hide_captions, update_cookie) {
var hideSubtitlesEl = this.videoCaption.hideSubtitlesEl, var hideSubtitlesEl = this.videoCaption.hideSubtitlesEl,
type; type, text;
if (typeof update_cookie === 'undefined') { if (typeof update_cookie === 'undefined') {
update_cookie = true; update_cookie = true;
...@@ -710,29 +710,33 @@ function () { ...@@ -710,29 +710,33 @@ function () {
type = 'hide_transcript'; type = 'hide_transcript';
this.captionsHidden = true; this.captionsHidden = true;
hideSubtitlesEl
.attr('title', gettext('Turn on captions'))
.text(gettext('Turn on captions'));
this.el.addClass('closed'); this.el.addClass('closed');
text = gettext('Turn on captions');
} else { } else {
type = 'show_transcript'; type = 'show_transcript';
this.captionsHidden = false; this.captionsHidden = false;
hideSubtitlesEl
.attr('title', gettext('Turn off captions'))
.text(gettext('Turn off captions'));
this.el.removeClass('closed'); this.el.removeClass('closed');
this.videoCaption.scrollCaption(); this.videoCaption.scrollCaption();
text = gettext('Turn off captions');
} }
hideSubtitlesEl
.attr('title', text)
.text(gettext(text));
if (this.videoPlayer) { if (this.videoPlayer) {
this.videoPlayer.log(type, { this.videoPlayer.log(type, {
currentTime: this.videoPlayer.currentTime currentTime: this.videoPlayer.currentTime
}); });
} }
if (this.resizer) {
this.resizer.alignByWidthOnly();
}
this.videoCaption.setSubtitlesHeight(); this.videoCaption.setSubtitlesHeight();
if (update_cookie) { if (update_cookie) {
......
...@@ -135,6 +135,7 @@ class VideoModule(VideoFields, XModule): ...@@ -135,6 +135,7 @@ class VideoModule(VideoFields, XModule):
js = { js = {
'js': [ 'js': [
resource_string(__name__, 'js/src/video/00_resizer.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/025_focus_grabber.js'),
resource_string(__name__, 'js/src/video/02_html5_video.js'), resource_string(__name__, 'js/src/video/02_html5_video.js'),
......
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