diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/.gitignore b/common/lib/xmodule/xmodule/js/src/videoalpha/display/.gitignore deleted file mode 100644 index c7a88ce0925d..000000000000 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!html5_video.js diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js b/common/lib/xmodule/xmodule/js/src/videoalpha/html5_video.js similarity index 86% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/html5_video.js index 5372108aba5c..bf10f6586a43 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/html5_video.js @@ -23,7 +23,7 @@ function () { Player.prototype.callStateChangeCallback = function () { if ($.isFunction(this.config.events.onStateChange)) { this.config.events.onStateChange({ - 'data': this.playerState + data: this.playerState }); } }; @@ -96,61 +96,47 @@ function () { * * config = { * - * 'videoSources': {}, // An object with properties being video sources. The property name is the + * videoSources: {}, // An object with properties being video sources. The property name is the * // video format of the source. Supported video formats are: 'mp4', 'webm', and * // 'ogg'. * - * 'playerVars': { // Object's properties identify player parameters. - * 'start': 0, // Possible values: positive integer. Position from which to start playing the + * playerVars: { // Object's properties identify player parameters. + * start: 0, // Possible values: positive integer. Position from which to start playing the * // video. Measured in seconds. If value is non-numeric, or 'start' property is * // not specified, the video will start playing from the beginning. * - * 'end': null // Possible values: positive integer. Position when to stop playing the + * end: null // Possible values: positive integer. Position when to stop playing the * // video. Measured in seconds. If value is null, or 'end' property is not * // specified, the video will end playing at the end. * * }, * - * 'events': { // Object's properties identify the events that the API fires, and the + * events: { // Object's properties identify the events that the API fires, and the * // functions (event listeners) that the API will call when those events occur. * // If value is null, or property is not specified, then no callback will be * // called for that event. * - * 'onReady': null, - * 'onStateChange': null + * onReady: null, + * onStateChange: null * } * } */ function Player(el, config) { var sourceStr, _this; - // If el is string, we assume it is an ID of a DOM element. Get the element, and check that the ID - // really belongs to an element. If we didn't get a DOM element, return. At this stage, nothing will - // break because other parts of the video player are waiting for 'onReady' callback to be called. - - // REFACTOR: Use .length === 0 - - this.el = $(el); - // REFACTOR: Simplify chck. - if (this.el.length === 0) { - return; - } - - - - - if (typeof el === 'string') { - this.el = $(el); - // REFACTOR: Simplify chck. + // Initially we assume that el is a DOM element. If jQuery selector fails to select something, we + // assume that el is an ID of a DOM element. We try to select by ID. If jQuery fails this time, + // we return. Nothing breaks because the player 'onReady' event will never be fired. + + this.el = $(el); + if (this.el.length === 0) { + this.el = $('#' + el); + if (this.el.length === 0) { return; } - } else if (el instanceof jQuery) { - this.el = el; - } else { - return; } - + // A simple test to see that the 'config' is a normal object. if ($.isPlainObject(config)) { this.config = config; @@ -165,9 +151,9 @@ function () { // From the start, all sources are empty. We will populate this object below. sourceStr = { - 'mp4': ' ', - 'webm': ' ', - 'ogg': ' ' + mp4: ' ', + webm: ' ', + ogg: ' ' }; // Will be used in inner functions to point to the current object. @@ -304,14 +290,16 @@ function () { } }()); - // REFACTOR: Doc. + // The YouTube API presents several constants which describe the player's state at a given moment. + // HTML5Video API will copy these constats so that code which uses both the YouTube API and this API + // doesn't have to change. HTML5Video.PlayerState = { - 'UNSTARTED': -1, - 'ENDED': 0, - 'PLAYING': 1, - 'PAUSED': 2, - 'BUFFERING': 3, - 'CUED': 5 + UNSTARTED: -1, + ENDED: 0, + PLAYING: 1, + PAUSED: 2, + BUFFERING: 3, + CUED: 5 }; // HTML5Video object - what this module exports. diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/initialize.js b/common/lib/xmodule/xmodule/js/src/videoalpha/initialize.js similarity index 85% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/initialize.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/initialize.js index 049746b47e9b..0a43092ff18a 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/initialize.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/initialize.js @@ -25,7 +25,6 @@ function (VideoPlayer) { * @param {DOM element} element Container of the entire Video Alpha DOM element. */ return function (state, element) { - checkForNativeFunctions(); makeFunctionsPublic(state); renderElements(state, element); }; @@ -57,6 +56,9 @@ function (VideoPlayer) { function renderElements(state, element) { var onPlayerReadyFunc; + // This is used in places where we instead would have to check if an element has a CSS class 'fullscreen'. + state.isFullScreen = false; + // The parent element of the video, and the ID. state.el = $(element).find('.videoalpha'); state.id = state.el.attr('id').replace(/video_/, ''); @@ -77,7 +79,11 @@ function (VideoPlayer) { sub: state.el.data('sub'), mp4Source: state.el.data('mp4-source'), webmSource: state.el.data('webm-source'), - oggSource: state.el.data('ogg-source') + oggSource: state.el.data('ogg-source'), + + fadeOutTimeout: 1400, + + availableQualities: ['hd720', 'hd1080', 'highres'] }; // Try to parse YouTube stream ID's. If @@ -95,9 +101,9 @@ function (VideoPlayer) { parseVideoSources( state, { - 'mp4': state.config.mp4Source, - 'webm': state.config.webmSource, - 'ogg': state.config.oggSource + mp4: state.config.mp4Source, + webm: state.config.webmSource, + ogg: state.config.oggSource } ); @@ -136,8 +142,8 @@ function (VideoPlayer) { state.hide_captions = true; $.cookie('hide_captions', state.hide_captions, { - 'expires': 3650, - 'path': '/' + expires: 3650, + path: '/' }); state.el.addClass('closed'); @@ -153,8 +159,8 @@ function (VideoPlayer) { state.currentPlayerMode = currentPlayerMode; } else { $.cookie('current_player_mode', 'html5', { - 'expires': 3650, - 'path': '/' + expires: 3650, + path: '/' }); state.currentPlayerMode = 'html5'; } @@ -219,7 +225,11 @@ function (VideoPlayer) { // Take the HTML5 sources (URLs of videos), and make them available explictly for each type // of video format (mp4, webm, ogg). function parseVideoSources(state, sources) { - state.html5Sources = { 'mp4': null, 'webm': null, 'ogg': null }; + state.html5Sources = { + mp4: null, + webm: null, + ogg: null + }; $.each(sources, function (name, source) { if (source && source.length) { @@ -254,48 +264,6 @@ function (VideoPlayer) { state.setSpeed($.cookie('video_speed')); } - function checkForNativeFunctions() { - // REFACTOR: - // 1.) IE8 doc. - // 2.) Move to separate file. - // 3.) Write about a generic soluction system wide. - - // - // IE browser supports Function.bind() only starting with version 8. - // - // The bind function is a recent addition to ECMA-262, 5th edition; as such it may not be present in all - // browsers. You can partially work around this by inserting the following code at the beginning of your - // scripts, allowing use of much of the functionality of bind() in implementations that do not natively support - // it. - // - // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind - if (!Function.prototype.bind) { - Function.prototype.bind = function (oThis) { - var aArgs, fToBind, fNOP, fBound; - - if (typeof this !== 'function') { - // closest thing possible to the ECMAScript 5 internal IsCallable function - throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); - } - - aArgs = Array.prototype.slice.call(arguments, 1); - fToBind = this; - fNOP = function () {}; - fBound = function () { - return fToBind.apply( - this instanceof fNOP && oThis ? this : oThis, - aArgs.concat(Array.prototype.slice.call(arguments)) - ); - }; - - fNOP.prototype = this.prototype; - fBound.prototype = new fNOP(); - - return fBound; - }; - } - } - // *************************************************************** // Public functions start here. // These are available via the 'state' object. Their context ('this' keyword) is the 'state' object. @@ -311,8 +279,8 @@ function (VideoPlayer) { if (updateCookie) { $.cookie('video_speed', this.speed, { - 'expires': 3650, - 'path': '/' + expires: 3650, + path: '/' }); } } diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_caption.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_caption.js similarity index 78% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_caption.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_caption.js index 095dc784a0cd..0b6c53198e0c 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_caption.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_caption.js @@ -60,14 +60,13 @@ function () { state.el.find('.video-controls .secondary-controls').append(state.videoCaption.hideSubtitlesEl); state.el.find('.subtitles').css({ - 'maxHeight': state.el.find('.video-wrapper').height() - 5 + maxHeight: state.el.find('.video-wrapper').height() - 5 }); fetchCaption(state); - // REFACTOR. Const. if (state.videoType === 'html5') { - state.videoCaption.fadeOutTimeout = 1400; + state.videoCaption.fadeOutTimeout = state.config.fadeOutTimeout; state.videoCaption.subtitlesEl.addClass('html5'); state.captionHideTimeout = setTimeout(state.videoCaption.autoHideCaptions, state.videoCaption.fadeOutTimeout); @@ -80,21 +79,24 @@ function () { function bindHandlers(state) { $(window).bind('resize', state.videoCaption.resize); state.videoCaption.hideSubtitlesEl.click(state.videoCaption.toggle); - - // REFACTOR: Use .on() - state.videoCaption.subtitlesEl.mouseenter( - state.videoCaption.onMouseEnter - ).mouseleave( - state.videoCaption.onMouseLeave - ).mousemove( - state.videoCaption.onMovement - ).bind( - 'mousewheel', - state.videoCaption.onMovement - ).bind( - 'DOMMouseScroll', - state.videoCaption.onMovement - ); + + state.videoCaption.subtitlesEl + .on( + 'mouseenter', + state.videoCaption.onMouseEnter + ).on( + 'mouseleave', + state.videoCaption.onMouseLeave + ).on( + 'mousemove', + state.videoCaption.onMovement + ).on( + 'mousewheel', + state.videoCaption.onMovement + ).on( + 'DOMMouseScroll', + state.videoCaption.onMovement + ); if (state.videoType === 'html5') { state.el.on('mousemove', state.videoCaption.autoShowCaptions) @@ -137,23 +139,18 @@ function () { this.captionsShowLock = true; - // REFACTOR. - if (this.captionState === 'invisible') { this.videoCaption.subtitlesEl.show(); this.captionState = 'visible'; - this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); } else if (this.captionState === 'hiding') { - this.videoCaption.subtitlesEl.stop(true, false); - this.videoCaption.subtitlesEl.css('opacity', 1); - this.videoCaption.subtitlesEl.show(); + this.videoCaption.subtitlesEl.stop(true, false).css('opacity', 1).show(); this.captionState = 'visible'; - this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); } else if (this.captionState === 'visible') { clearTimeout(this.captionHideTimeout); - this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); } + this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout); + this.captionsShowLock = false; } } @@ -171,20 +168,19 @@ function () { _this = this; - // REFACTOR. - this.videoCaption.subtitlesEl.fadeOut(1000, function () { + this.videoCaption.subtitlesEl.fadeOut(this.videoCaption.fadeOutTimeout, function () { _this.captionState = 'invisible'; }); } function resize() { this.videoCaption.subtitlesEl.css({ - 'maxHeight': this.videoCaption.captionHeight() + maxHeight: this.videoCaption.captionHeight() }); - // REFACTOR: Chain. - this.videoCaption.subtitlesEl.find('.spacing:first').height(this.videoCaption.topSpacingHeight()); - this.videoCaption.subtitlesEl.find('.spacing:last').height(this.videoCaption.bottomSpacingHeight()); + this.videoCaption.subtitlesEl + .find('.spacing:first').height(this.videoCaption.topSpacingHeight()) + .find('.spacing:last').height(this.videoCaption.bottomSpacingHeight()); this.videoCaption.scrollCaption(); } @@ -194,7 +190,6 @@ function () { clearTimeout(this.videoCaption.frozen); } - // REFACTOR. this.videoCaption.frozen = setTimeout(this.videoCaption.onMouseLeave, 10000); } @@ -219,37 +214,34 @@ function () { container = $('
    '); $.each(this.videoCaption.captions, function(index, text) { - // REFACTOR: Use .data() - container.append($('
  1. ').html(text).attr({ - 'data-index': index, - 'data-start': _this.videoCaption.start[index] - })); + container.append( + $('
  2. ').html(text) + .data('index', index) + .data('start', _this.videoCaption.start[index]) + ); }); - // REFACTOR: Chain. - this.videoCaption.subtitlesEl.html(container.html()); - this.videoCaption.subtitlesEl.find('li[data-index]').on('click', this.videoCaption.seekPlayer); this.videoCaption.subtitlesEl - .prepend( - $('
  3. ').height(this.videoCaption.topSpacingHeight()) - ) - .append( - $('
  4. ').height(this.videoCaption.bottomSpacingHeight()) - ); + .html(container.html()) + .find('li[data-index]').on('click', this.videoCaption.seekPlayer) + .prepend( + $('
  5. ').height(this.videoCaption.topSpacingHeight()) + ) + .append( + $('
  6. ').height(this.videoCaption.bottomSpacingHeight()) + ); this.videoCaption.rendered = true; } function scrollCaption() { - // REFACTOR: Cache current:first - if ( - !this.videoCaption.frozen && - this.videoCaption.subtitlesEl.find('.current:first').length - ) { + var el = this.videoCaption.subtitlesEl.find('.current:first'); + + if (!this.videoCaption.frozen && el.length) { this.videoCaption.subtitlesEl.scrollTo( - this.videoCaption.subtitlesEl.find('.current:first'), + el, { - 'offset': -this.videoCaption.calculateOffset(this.videoCaption.subtitlesEl.find('.current:first')) + offset: -this.videoCaption.calculateOffset(el) } ); } @@ -361,14 +353,13 @@ function () { } $.cookie('hide_captions', hide_captions, { - 'expires': 3650, - 'path': '/' + expires: 3650, + path: '/' }); } function captionHeight() { - // REFACTOR: Use property instead of class. - if (this.el.hasClass('fullscreen')) { + if (this.isFullScreen) { return $(window).height() - this.el.find('.video-controls').height(); } else { return this.el.find('.video-wrapper').height(); diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_control.js similarity index 81% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_control.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_control.js index cc2a85a80305..d7a7546a395c 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_control.js @@ -57,9 +57,9 @@ function () { state.videoControl.pause(); qTipConfig = { - 'position': { - 'my': 'top right', - 'at': 'top center' + position: { + my: 'top right', + at: 'top center' } }; @@ -70,9 +70,7 @@ function () { } if (state.videoType === 'html5') { - // REFACTOR: constants move to initialize() - - state.videoControl.fadeOutTimeout = 1400; + state.videoControl.fadeOutTimeout = state.config.fadeOutTimeout; state.videoControl.el.addClass('html5'); state.controlHideTimeout = setTimeout(state.videoControl.hideControls, state.videoControl.fadeOutTimeout); @@ -106,25 +104,18 @@ function () { this.controlShowLock = true; - // Refactor: separate UI state in object. No code duplication. - // REFACTOR: - // 1.) Chain jQuery calls. - // 2.) Drop out common code. if (this.controlState === 'invisible') { this.videoControl.el.show(); this.controlState = 'visible'; - this.controlHideTimeout = setTimeout(this.videoControl.hideControls, this.videoControl.fadeOutTimeout); } else if (this.controlState === 'hiding') { - this.videoControl.el.stop(true, false); - this.videoControl.el.css('opacity', 1); - this.videoControl.el.show(); + this.videoControl.el.stop(true, false).css('opacity', 1).show(); this.controlState = 'visible'; - this.controlHideTimeout = setTimeout(this.videoControl.hideControls, this.videoControl.fadeOutTimeout); } else if (this.controlState === 'visible') { clearTimeout(this.controlHideTimeout); - this.controlHideTimeout = setTimeout(this.videoControl.hideControls, this.videoControl.fadeOutTimeout); } + this.controlHideTimeout = setTimeout(this.videoControl.hideControls, this.videoControl.fadeOutTimeout); + this.controlShowLock = false; } } @@ -142,28 +133,27 @@ function () { _this = this; - this.videoControl.el.fadeOut(1000, function () { + this.videoControl.el.fadeOut(this.videoControl.fadeOutTimeout, function () { _this.controlState = 'invisible'; }); } function play() { - // REFACTOR: this.videoControl.playPauseState should be bool. this.videoControl.playPauseEl.removeClass('play').addClass('pause').attr('title', 'Pause'); - this.videoControl.playPauseState = 'playing'; + this.videoControl.isPlaying = true; } function pause() { this.videoControl.playPauseEl.removeClass('pause').addClass('play').attr('title', 'Play'); - this.videoControl.playPauseState = 'paused'; + this.videoControl.isPlaying = false; } function togglePlayback(event) { event.preventDefault(); - if (this.videoControl.playPauseState === 'playing') { + if (this.videoControl.isPlaying) { this.trigger(['videoPlayer', 'pause'], null); - } else { // if (this.videoControl.playPauseState === 'paused') { + } else { this.trigger(['videoPlayer', 'play'], null); } } @@ -174,10 +164,12 @@ function () { if (this.videoControl.fullScreenState) { this.videoControl.fullScreenState = false; this.el.removeClass('fullscreen'); + this.isFullScreen = false; this.videoControl.fullScreenEl.attr('title', 'Fullscreen'); } else { this.videoControl.fullScreenState = true; this.el.addClass('fullscreen'); + this.isFullScreen = true; this.videoControl.fullScreenEl.attr('title', 'Exit fullscreen'); } @@ -185,8 +177,7 @@ function () { } function exitFullScreen(event) { - // REFACTOR: Add variable instead of class. - if ((this.el.hasClass('fullscreen')) && (event.keyCode === 27)) { + if ((this.isFullScreen) && (event.keyCode === 27)) { this.videoControl.toggleFullScreen(event); } } diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_player.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_player.js similarity index 93% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_player.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_player.js index f14769e0b45f..e20878074a15 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_player.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_player.js @@ -62,12 +62,12 @@ function (HTML5Video) { state.videoPlayer.currentTime = 0; state.videoPlayer.playerVars = { - 'controls': 0, - 'wmode': 'transparent', - 'rel': 0, - 'showinfo': 0, - 'enablejsapi': 1, - 'modestbranding': 1 + controls: 0, + wmode: 'transparent', + rel: 0, + showinfo: 0, + enablejsapi: 1, + modestbranding: 1 }; if (state.currentPlayerMode !== 'flash') { @@ -84,11 +84,11 @@ function (HTML5Video) { if (state.videoType === 'html5') { state.videoPlayer.player = new HTML5Video.Player(state.el, { - 'playerVars': state.videoPlayer.playerVars, - 'videoSources': state.html5Sources, - 'events': { - 'onReady': state.videoPlayer.onReady, - 'onStateChange': state.videoPlayer.onStateChange + playerVars: state.videoPlayer.playerVars, + videoSources: state.html5Sources, + events: { + onReady: state.videoPlayer.onReady, + onStateChange: state.videoPlayer.onStateChange } }); } else { // if (state.videoType === 'youtube') { @@ -98,12 +98,12 @@ function (HTML5Video) { youTubeId = state.youtubeId('1.0'); } state.videoPlayer.player = new YT.Player(state.id, { - 'playerVars': state.videoPlayer.playerVars, - 'videoId': youTubeId, - 'events': { - 'onReady': state.videoPlayer.onReady, - 'onStateChange': state.videoPlayer.onStateChange, - 'onPlaybackQualityChange': state.videoPlayer.onPlaybackQualityChange + playerVars: state.videoPlayer.playerVars, + videoId: youTubeId, + events: { + onReady: state.videoPlayer.onReady, + onStateChange: state.videoPlayer.onStateChange, + onPlaybackQualityChange: state.videoPlayer.onPlaybackQualityChange } }); } @@ -249,8 +249,6 @@ function (HTML5Video) { function onReady() { var availablePlaybackRates, baseSpeedSubs, _this; - - // REFACTOR: Check if logic. availablePlaybackRates = this.videoPlayer.player.getAvailablePlaybackRates(); if ((this.currentPlayerMode === 'html5') && (this.videoType === 'youtube')) { diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_progress_slider.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_progress_slider.js similarity index 82% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_progress_slider.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_progress_slider.js index 612beb9abf01..f61f29f27671 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_progress_slider.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_progress_slider.js @@ -61,10 +61,10 @@ function () { function buildSlider(state) { state.videoProgressSlider.slider = state.videoProgressSlider.el.slider({ - 'range': 'min', - 'change': state.videoProgressSlider.onChange, - 'slide': state.videoProgressSlider.onSlide, - 'stop': state.videoProgressSlider.onStop + range: 'min', + change: state.videoProgressSlider.onChange, + slide: state.videoProgressSlider.onSlide, + stop: state.videoProgressSlider.onStop }); } @@ -72,18 +72,18 @@ function () { state.videoProgressSlider.handle = state.videoProgressSlider.el.find('.ui-slider-handle'); state.videoProgressSlider.handle.qtip({ - 'content': '' + Time.format(state.videoProgressSlider.slider.slider('value')), - 'position': { - 'my': 'bottom center', - 'at': 'top center', - 'container': state.videoProgressSlider.handle + content: '' + Time.format(state.videoProgressSlider.slider.slider('value')), + position: { + my: 'bottom center', + at: 'top center', + container: state.videoProgressSlider.handle }, - 'hide': { - 'delay': 700 + hide: { + delay: 700 }, - 'style': { - 'classes': 'ui-tooltip-slider', - 'widget': true + style: { + classes: 'ui-tooltip-slider', + widget: true } }); } @@ -122,9 +122,9 @@ function () { function updatePlayTime(params) { if ((this.videoProgressSlider.slider) && (!this.videoProgressSlider.frozen)) { - // REFACTOR: Check if you can chain. - this.videoProgressSlider.slider.slider('option', 'max', params.duration); - this.videoProgressSlider.slider.slider('value', params.time); + this.videoProgressSlider.slider + .slider('option', 'max', params.duration) + .slider('value', params.time); } } diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_quality_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_quality_control.js similarity index 86% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_quality_control.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_quality_control.js index 1d559e45cd8d..8d5dc0d8b865 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_quality_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_quality_control.js @@ -46,9 +46,9 @@ function () { if (!onTouchBasedDevice()) { // REFACTOR: Move qtip config to state.config state.videoQualityControl.el.qtip({ - 'position': { - 'my': 'top right', - 'at': 'top center' + position: { + my: 'top right', + at: 'top center' } }); } @@ -70,8 +70,7 @@ function () { function onQualityChange(value) { this.videoQualityControl.quality = value; - // refactor: Move constants to state.config. - if ((value === 'hd720') || (value === 'hd1080') || (value === 'highres')) { + if (this.config.availableQualities.indexOf(value) !== -1) { this.videoQualityControl.el.addClass('active'); } else { this.videoQualityControl.el.removeClass('active'); @@ -79,14 +78,12 @@ function () { } function toggleQuality(event) { - var newQuality, _ref; + var newQuality, + value = this.videoQualityControl.quality; event.preventDefault(); - _ref = this.videoQualityControl.quality; - - // refactor: Move constants to state.config. - if ((_ref === 'hd720') || (_ref === 'hd1080') || (_ref === 'highres')) { + if (this.config.availableQualities.indexOf(value) !== -1) { newQuality = 'large'; } else { newQuality = 'hd720'; diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_speed_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_speed_control.js similarity index 77% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_speed_control.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_speed_control.js index 2c8d8ca9b785..adc079dab36e 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_speed_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_speed_control.js @@ -44,13 +44,9 @@ function () { state.videoControl.secondaryControlsEl.prepend(state.videoSpeedControl.el); $.each(state.videoSpeedControl.speeds, function(index, speed) { - // REFACTOR: Move all HTML into one function call. - var link = $('').attr({ - 'href': '#' - }).html('' + speed + 'x'); + var link = $('' + speed + 'x'); - // REFACTOR: Use jQuery .data() - state.videoSpeedControl.videoSpeedsEl.prepend($('
  7. ').attr('data-speed', speed).html(link)); + state.videoSpeedControl.videoSpeedsEl.prepend($('
  8. ' + link + '
  9. ')); }); state.videoSpeedControl.setSpeed(state.speed); @@ -68,19 +64,17 @@ function () { $(this).toggleClass('open'); }); } else { - // REFACTOR: Chain. - state.videoSpeedControl.el.on('mouseenter', function() { - $(this).addClass('open'); - }); - - state.videoSpeedControl.el.on('mouseleave', function() { - $(this).removeClass('open'); - }); - - state.videoSpeedControl.el.on('click', function(event) { - event.preventDefault(); - $(this).removeClass('open'); - }); + state.videoSpeedControl.el + .on('mouseenter', function () { + $(this).addClass('open'); + }) + .on('mouseleave', function () { + $(this).removeClass('open'); + }) + .on('click', function (event) { + event.preventDefault(); + $(this).removeClass('open'); + }); } } @@ -91,18 +85,19 @@ function () { // *************************************************************** function setSpeed(speed) { - // REFACTOR: Use chaining. this.videoSpeedControl.videoSpeedsEl.find('li').removeClass('active'); this.videoSpeedControl.videoSpeedsEl.find("li[data-speed='" + speed + "']").addClass('active'); this.videoSpeedControl.el.find('p.active').html('' + speed + 'x'); } function changeVideoSpeed(event) { + var parentEl = $(event.target).parent(); + event.preventDefault(); // REFACTOR: Cache parent el. - if (!$(event.target).parent().hasClass('active')) { - this.videoSpeedControl.currentSpeed = $(event.target).parent().data('speed'); + if (!parentEl.hasClass('active')) { + this.videoSpeedControl.currentSpeed = parentEl.data('speed'); this.videoSpeedControl.setSpeed( // To meet the API expected format. @@ -113,23 +108,19 @@ function () { } } - // REFACTOR. - function reRender(params /*newSpeeds, currentSpeed*/) { - var _this; + function reRender(params) { + var _this = this; this.videoSpeedControl.videoSpeedsEl.empty(); this.videoSpeedControl.videoSpeedsEl.find('li').removeClass('active'); this.videoSpeedControl.speeds = params.newSpeeds; - _this = this; $.each(this.videoSpeedControl.speeds, function(index, speed) { var link, listItem; - link = $('').attr({ - 'href': '#' - }).html('' + speed + 'x'); + link = $('' + speed + 'x'); - listItem = $('
  10. ').attr('data-speed', speed).html(link); + listItem = $('
  11. ' + link + '
  12. '); if (speed === params.currentSpeed) { listItem.addClass('active'); diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_volume_control.js b/common/lib/xmodule/xmodule/js/src/videoalpha/video_volume_control.js similarity index 82% rename from common/lib/xmodule/xmodule/js/src/videoalpha/display/video_volume_control.js rename to common/lib/xmodule/xmodule/js/src/videoalpha/video_volume_control.js index 3d979a0d1a8c..c3892cbaae59 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/video_volume_control.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/video_volume_control.js @@ -41,28 +41,24 @@ function () { state.videoControl.secondaryControlsEl.prepend(state.videoVolumeControl.el); - // Figure out what the current volume is. Set it up so that muting/unmuting works correctly. - // If no information about volume level could be retrieved, then we will use the default - // 100 level (full volume). - // REFACTOR: Remove unnecessary checks. + // Figure out what the current volume is. If no information about volume level could be retrieved, + // then we will use the default 100 level (full volume). state.videoVolumeControl.currentVolume = parseInt($.cookie('video_player_volume_level'), 10); - state.videoVolumeControl.previousVolume = 100; - if ( - (!isFinite(state.videoVolumeControl.currentVolume)) || - (state.videoVolumeControl.currentVolume < 0) || - (state.videoVolumeControl.currentVolume > 100) - ) { + if (!isFinite(state.videoVolumeControl.currentVolume)) { state.videoVolumeControl.currentVolume = 100; } + // Set it up so that muting/unmuting works correctly. + state.videoVolumeControl.previousVolume = 100; + state.videoVolumeControl.slider = state.videoVolumeControl.volumeSliderEl.slider({ - 'orientation': 'vertical', - 'range': 'min', - 'min': 0, - 'max': 100, - 'value': state.videoVolumeControl.currentVolume, - 'change': state.videoVolumeControl.onChange, - 'slide': state.videoVolumeControl.onChange + orientation: 'vertical', + range: 'min', + min: 0, + max: 100, + value: state.videoVolumeControl.currentVolume, + change: state.videoVolumeControl.onChange, + slide: state.videoVolumeControl.onChange }); state.videoVolumeControl.el.toggleClass('muted', state.videoVolumeControl.currentVolume === 0); @@ -94,8 +90,8 @@ function () { this.videoVolumeControl.el.toggleClass('muted', this.videoVolumeControl.currentVolume === 0); $.cookie('video_player_volume_level', ui.value, { - 'expires': 3650, - 'path': '/' + expires: 3650, + path: '/' }); this.trigger(['videoPlayer', 'onVolumeChange'], ui.value); diff --git a/common/lib/xmodule/xmodule/videoalpha_module.py b/common/lib/xmodule/xmodule/videoalpha_module.py index cb91d99b74a7..7a721b73ca81 100644 --- a/common/lib/xmodule/xmodule/videoalpha_module.py +++ b/common/lib/xmodule/xmodule/videoalpha_module.py @@ -57,15 +57,16 @@ class VideoAlphaModule(VideoAlphaFields, XModule): js = { 'js': [ - resource_string(__name__, 'js/src/videoalpha/display/initialize.js'), - resource_string(__name__, 'js/src/videoalpha/display/html5_video.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_player.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_control.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_quality_control.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_progress_slider.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_volume_control.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_speed_control.js'), - resource_string(__name__, 'js/src/videoalpha/display/video_caption.js'), + resource_string(__name__, 'js/src/videoalpha/helper_utils.js'), + resource_string(__name__, 'js/src/videoalpha/initialize.js'), + resource_string(__name__, 'js/src/videoalpha/html5_video.js'), + resource_string(__name__, 'js/src/videoalpha/video_player.js'), + resource_string(__name__, 'js/src/videoalpha/video_control.js'), + resource_string(__name__, 'js/src/videoalpha/video_quality_control.js'), + resource_string(__name__, 'js/src/videoalpha/video_progress_slider.js'), + resource_string(__name__, 'js/src/videoalpha/video_volume_control.js'), + resource_string(__name__, 'js/src/videoalpha/video_speed_control.js'), + resource_string(__name__, 'js/src/videoalpha/video_caption.js'), resource_string(__name__, 'js/src/videoalpha/main.js') ] } diff --git a/lms/envs/common.py b/lms/envs/common.py index b3599d4da907..edca621ea47a 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -35,7 +35,7 @@ PLATFORM_NAME = "edX" COURSEWARE_ENABLED = True -ENABLE_JASMINE = True +ENABLE_JASMINE = False GENERATE_RANDOM_USER_CREDENTIALS = False PERFSTATS = False