Commit 0f0b2622 by Valera Rozuvan

Merge pull request #2942 from edx/valera/start_introduction_of_jslint

Start introduction of JSLint for JavaScript
parents a795edcf 54d1af16
(function (requirejs, require, define) { (function (require, $) {
'use strict';
// In the case when the Video constructor will be called before
// RequireJS finishes loading all of the Video dependencies, we will have // In the case when the Video constructor will be called before RequireJS finishes loading all of the Video
// a mock function that will collect all the elements that must be // dependencies, we will have a mock function that will collect all the elements that must be initialized as
// initialized as Video elements. // Video elements.
// //
// Once RequireJS will load all of the necessary dependencies, main code // Once RequireJS will load all of the necessary dependencies, main code will invoke the mock function with
// will invoke the mock function with the second parameter set to truthy value. // the second parameter set to truthy value. This will trigger the actual Video constructor on all elements
// This will trigger the actual Video constructor on all elements that // that are stored in a temporary list.
// are stored in a temporary list. window.Video = (function () {
window.Video = (function () { // Temporary storage place for elements that must be initialized as Video elements.
// Temporary storage place for elements that must be initialized as Video
// elements.
var tempCallStack = []; var tempCallStack = [];
return function (element, processTempCallStack) { return function (element, processTempCallStack) {
// If mock function was called with second parameter set to truthy // If mock function was called with second parameter set to truthy value, we invoke the real `window.Video`
// value, we invoke the real `window.Video` on all the stored elements // on all the stored elements so far.
// so far.
if (processTempCallStack) { if (processTempCallStack) {
$.each(tempCallStack, function (index, element) { $.each(tempCallStack, function (index, element) {
// By now, `window.Video` is the real constructor. // By now, `window.Video` is the real constructor.
...@@ -27,19 +24,17 @@ window.Video = (function () { ...@@ -27,19 +24,17 @@ window.Video = (function () {
return; return;
} }
// If normal call to `window.Video` constructor, store the element // If normal call to `window.Video` constructor, store the element for later initializing.
// for later initializing.
tempCallStack.push(element); tempCallStack.push(element);
// Real Video constructor returns the `state` object. The mock // Real Video constructor returns the `state` object. The mock function will return an empty object.
// function will return an empty object.
return {}; return {};
}; };
}()); }());
// Main module. // Main module.
require( require(
[ [
'video/01_initialize.js', 'video/01_initialize.js',
'video/025_focus_grabber.js', 'video/025_focus_grabber.js',
'video/035_video_accessible_menu.js', 'video/035_video_accessible_menu.js',
...@@ -49,9 +44,9 @@ require( ...@@ -49,9 +44,9 @@ require(
'video/07_video_volume_control.js', 'video/07_video_volume_control.js',
'video/08_video_speed_control.js', 'video/08_video_speed_control.js',
'video/09_video_caption.js' 'video/09_video_caption.js'
], ],
function ( function (
Initialize, initialize,
FocusGrabber, FocusGrabber,
VideoAccessibleMenu, VideoAccessibleMenu,
VideoControl, VideoControl,
...@@ -60,25 +55,23 @@ function ( ...@@ -60,25 +55,23 @@ function (
VideoVolumeControl, VideoVolumeControl,
VideoSpeedControl, VideoSpeedControl,
VideoCaption VideoCaption
) { ) {
var previousState, var youtubeXhr = null,
youtubeXhr = null, oldVideo = window.Video,
oldVideo = window.Video;
// Because this constructor can be called multiple times on a single page (when the user switches
// Because this constructor can be called multiple times on a single page (when // verticals, the page doesn't reload, but the content changes), we must will check each time if there
// the user switches verticals, the page doesn't reload, but the content changes), we must // is a previous copy of 'state' object. If there is, we will make sure that copy exists cleanly. We
// will check each time if there is a previous copy of 'state' object. If there is, we // have to do this because when verticals switch, the code does not handle any Xmodule JS code that is
// will make sure that copy exists cleanly. We have to do this because when verticals switch, // running - it simply removes DOM elements from the page. Any functions that were running during this,
// the code does not handle any Xmodule JS code that is running - it simply removes DOM // and that will run afterwards (expecting the DOM elements to be present) must be stopped by hand.
// elements from the page. Any functions that were running during this, and that will run
// afterwards (expecting the DOM elements to be present) must be stopped by hand.
previousState = null; previousState = null;
window.Video = function (element) { window.Video = function (element) {
var state; var state;
// Check for existance of previous state, uninitialize it if necessary, and create a new state. // Check for existance of previous state, uninitialize it if necessary, and create a new state. Store
// Store new state for future invocation of this module consturctor function. // new state for future invocation of this module consturctor function.
if (previousState && previousState.videoPlayer) { if (previousState && previousState.videoPlayer) {
previousState.saveState(true); previousState.saveState(true);
$(window).off('unload', previousState.saveState); $(window).off('unload', previousState.saveState);
...@@ -99,16 +92,15 @@ function ( ...@@ -99,16 +92,15 @@ function (
]; ];
state.youtubeXhr = youtubeXhr; state.youtubeXhr = youtubeXhr;
Initialize(state, element); initialize(state, element);
if (!youtubeXhr) { if (!youtubeXhr) {
youtubeXhr = state.youtubeXhr; youtubeXhr = state.youtubeXhr;
} }
$(element).find('.video').data('video-player-state', state); $(element).find('.video').data('video-player-state', state);
// Because the 'state' object is only available inside this closure, we will also make // Because the 'state' object is only available inside this closure, we will also make it available to
// it available to the caller by returning it. This is necessary so that we can test // the caller by returning it. This is necessary so that we can test Video with Jasmine.
// Video with Jasmine.
return state; return state;
}; };
...@@ -116,9 +108,9 @@ function ( ...@@ -116,9 +108,9 @@ function (
youtubeXhr = null; youtubeXhr = null;
}; };
// Invoke the mock Video constructor so that the elements stored within // Invoke the mock Video constructor so that the elements stored within it can be processed by the real
// it can be processed by the real `window.Video` constructor. // `window.Video` constructor.
oldVideo(null, true); oldVideo(null, true);
}); }
);
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(window.RequireJS.require, window.jQuery));
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