Commit 163ff846 by Brian Jacobel

Run eslint autofixer on /common

parent c7042c48
...@@ -55,3 +55,6 @@ common/lib/xmodule/xmodule/js/src/sequence/display.js ...@@ -55,3 +55,6 @@ common/lib/xmodule/xmodule/js/src/sequence/display.js
common/lib/xmodule/xmodule/js/src/sequence/edit.js common/lib/xmodule/xmodule/js/src/sequence/edit.js
common/lib/xmodule/xmodule/js/src/tabs/tabs-aggregator.js common/lib/xmodule/xmodule/js/src/tabs/tabs-aggregator.js
common/lib/xmodule/xmodule/js/src/vertical/edit.js common/lib/xmodule/xmodule/js/src/vertical/edit.js
# This file is responsible for almost half of the repo's total issues.
common/lib/xmodule/xmodule/js/src/capa/schematic.js
require('coffee-script'); require('coffee-script');
var importAll = function (modulePath) { var importAll = function(modulePath) {
module = require(modulePath); module = require(modulePath);
for(key in module){ for (key in module) {
global[key] = module[key]; global[key] = module[key];
} }
} };
importAll("mersenne-twister-min"); importAll('mersenne-twister-min');
importAll("xproblem"); importAll('xproblem');
generatorModulePath = process.argv[2]; generatorModulePath = process.argv[2];
dependencies = JSON.parse(process.argv[3]); dependencies = JSON.parse(process.argv[3]);
seed = JSON.parse(process.argv[4]); seed = JSON.parse(process.argv[4]);
params = JSON.parse(process.argv[5]); params = JSON.parse(process.argv[5]);
if(seed==null){ if (seed == null) {
seed = 4; seed = 4;
} }
for(var i = 0; i < dependencies.length; i++){ for (var i = 0; i < dependencies.length; i++) {
importAll(dependencies[i]); importAll(dependencies[i]);
} }
generatorModule = require(generatorModulePath); generatorModule = require(generatorModulePath);
generatorClass = generatorModule.generatorClass; generatorClass = generatorModule.generatorClass;
generator = new generatorClass(seed, params); generator = new generatorClass(seed, params);
console.log(JSON.stringify(generator.generate())); console.log(JSON.stringify(generator.generate()));
require('coffee-script'); require('coffee-script');
var importAll = function (modulePath) { var importAll = function(modulePath) {
module = require(modulePath); module = require(modulePath);
for(key in module){ for (key in module) {
global[key] = module[key]; global[key] = module[key];
} }
} };
importAll("xproblem"); importAll('xproblem');
graderModulePath = process.argv[2]; graderModulePath = process.argv[2];
dependencies = JSON.parse(process.argv[3]); dependencies = JSON.parse(process.argv[3]);
submission = JSON.parse(process.argv[4]); submission = JSON.parse(process.argv[4]);
problemState = JSON.parse(process.argv[5]); problemState = JSON.parse(process.argv[5]);
params = JSON.parse(process.argv[6]); params = JSON.parse(process.argv[6]);
for(var i = 0; i < dependencies.length; i++){ for (var i = 0; i < dependencies.length; i++) {
importAll(dependencies[i]); importAll(dependencies[i]);
} }
graderModule = require(graderModulePath); graderModule = require(graderModulePath);
graderClass = graderModule.graderClass; graderClass = graderModule.graderClass;
grader = new graderClass(submission, problemState, params); grader = new graderClass(submission, problemState, params);
console.log(JSON.stringify(grader.grade())); console.log(JSON.stringify(grader.grade()));
console.log(JSON.stringify(grader.evaluation)); console.log(JSON.stringify(grader.evaluation));
......
/* JavaScript for special editing operations that can be done on LibraryContentXBlock */ /* JavaScript for special editing operations that can be done on LibraryContentXBlock */
window.LibraryContentAuthorView = function (runtime, element) { window.LibraryContentAuthorView = function(runtime, element) {
"use strict"; 'use strict';
var $element = $(element); var $element = $(element);
var usage_id = $element.data('usage-id'); var usage_id = $element.data('usage-id');
// The "Update Now" button is not a child of 'element', as it is in the validation message area // The "Update Now" button is not a child of 'element', as it is in the validation message area
// But it is still inside this xblock's wrapper element, which we can easily find: // But it is still inside this xblock's wrapper element, which we can easily find:
var $wrapper = $element.parents('*[data-locator="'+usage_id+'"]'); var $wrapper = $element.parents('*[data-locator="' + usage_id + '"]');
// We can't bind to the button itself because in the bok choy test environment, // We can't bind to the button itself because in the bok choy test environment,
// it may not yet exist at this point in time... not sure why. // it may not yet exist at this point in time... not sure why.
......
/* JavaScript for editing operations that can be done on the split test author view. */ /* JavaScript for editing operations that can be done on the split test author view. */
window.SplitTestAuthorView = function (runtime, element) { window.SplitTestAuthorView = function(runtime, element) {
"use strict"; 'use strict';
var $element = $(element); var $element = $(element);
var splitTestLocator = $element.closest('.studio-xblock-wrapper').data('locator'); var splitTestLocator = $element.closest('.studio-xblock-wrapper').data('locator');
runtime.listenTo("add-missing-groups", function (parentLocator) { runtime.listenTo('add-missing-groups', function(parentLocator) {
if (splitTestLocator === parentLocator) { if (splitTestLocator === parentLocator) {
runtime.notify('save', { runtime.notify('save', {
state: 'start', state: 'start',
......
/* Creates a new selector for managing toggling which child to show. */ /* Creates a new selector for managing toggling which child to show. */
window.ABTestSelector = function (runtime, elem) { window.ABTestSelector = function(runtime, elem) {
"use strict"; 'use strict';
var _this = {}; var _this = {};
_this.elem = $(elem); _this.elem = $(elem);
_this.children = _this.elem.find('.split-test-child'); _this.children = _this.elem.find('.split-test-child');
...@@ -12,7 +12,7 @@ window.ABTestSelector = function (runtime, elem) { ...@@ -12,7 +12,7 @@ window.ABTestSelector = function (runtime, elem) {
_this.children.each(function() { _this.children.each(function() {
// force this id to remain a string, even if it looks like something else // force this id to remain a string, even if it looks like something else
var child_group_id = $(this).data('group-id').toString(); var child_group_id = $(this).data('group-id').toString();
if(child_group_id === group_id) { if (child_group_id === group_id) {
_this.content_container.html($(this).text()); _this.content_container.html($(this).text());
XBlock.initializeBlocks(_this.content_container, $(elem).data('request-token')); XBlock.initializeBlocks(_this.content_container, $(elem).data('request-token'));
} }
......
/* Javascript for the Split Test XBlock. */ /* Javascript for the Split Test XBlock. */
window.SplitTestStudentView = function (runtime, element) { window.SplitTestStudentView = function(runtime, element) {
"use strict"; 'use strict';
$.post(runtime.handlerUrl(element, 'log_child_render')); $.post(runtime.handlerUrl(element, 'log_child_render'));
return {}; return {};
}; };
/* JavaScript for Vertical Student View. */ /* JavaScript for Vertical Student View. */
window.VerticalStudentView = function (runtime, element) { window.VerticalStudentView = function(runtime, element) {
"use strict"; 'use strict';
RequireJS.require(['js/bookmarks/views/bookmark_button'], function (BookmarkButton) { RequireJS.require(['js/bookmarks/views/bookmark_button'], function(BookmarkButton) {
var $element = $(element); var $element = $(element);
var $bookmarkButtonElement = $element.find('.bookmark-button'); var $bookmarkButtonElement = $element.find('.bookmark-button');
...@@ -10,7 +10,7 @@ window.VerticalStudentView = function (runtime, element) { ...@@ -10,7 +10,7 @@ window.VerticalStudentView = function (runtime, element) {
bookmarkId: $bookmarkButtonElement.data('bookmarkId'), bookmarkId: $bookmarkButtonElement.data('bookmarkId'),
usageId: $element.data('usageId'), usageId: $element.data('usageId'),
bookmarked: $element.parent('#seq_content').data('bookmarked'), bookmarked: $element.parent('#seq_content').data('bookmarked'),
apiUrl: $(".courseware-bookmarks-button").data('bookmarksApiUrl') apiUrl: $('.courseware-bookmarks-button').data('bookmarksApiUrl')
}); });
}); });
}; };
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
// Somehow the code initialized in jQuery's onready doesn't get called before karma auto starts // Somehow the code initialized in jQuery's onready doesn't get called before karma auto starts
'use strict'; 'use strict';
window.__karma__.loaded = function () { window.__karma__.loaded = function() {
setTimeout(function () { setTimeout(function() {
window.__karma__.start(); window.__karma__.start();
}, 1000); }, 1000);
}; };
...@@ -49,7 +49,7 @@ var options = { ...@@ -49,7 +49,7 @@ var options = {
{pattern: 'common_static/common/js/spec_helpers/jasmine-extensions.js', included: true}, {pattern: 'common_static/common/js/spec_helpers/jasmine-extensions.js', included: true},
{pattern: 'common_static/js/vendor/sinon-1.17.0.js', included: true}, {pattern: 'common_static/js/vendor/sinon-1.17.0.js', included: true},
{pattern: 'spec/main_requirejs.js', included: true}, {pattern: 'spec/main_requirejs.js', included: true}
], ],
libraryFiles: [ libraryFiles: [
...@@ -78,6 +78,6 @@ var options = { ...@@ -78,6 +78,6 @@ var options = {
] ]
}; };
module.exports = function (config) { module.exports = function(config) {
configModule.configure(config, options); configModule.configure(config, options);
}; };
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
* ~ Donald Knuth * ~ Donald Knuth
*/ */
(function ($, ImageInput, undefined) { (function($, ImageInput, undefined) {
describe('ImageInput', function () { describe('ImageInput', function() {
var state; var state;
beforeEach(function () { beforeEach(function() {
var el; var el;
loadFixtures('imageinput.html'); loadFixtures('imageinput.html');
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
state = new ImageInput('12345'); state = new ImageInput('12345');
}); });
it('initialization', function () { it('initialization', function() {
// Check that object's properties are present, and that the DOM // Check that object's properties are present, and that the DOM
// elements they reference exist. // elements they reference exist.
expect(state.el).toBeDefined(); expect(state.el).toBeDefined();
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
expect(state.el).toHandle('click'); expect(state.el).toHandle('click');
}); });
it('cross becomes visible after first click', function () { it('cross becomes visible after first click', function() {
expect(state.crossEl.css('visibility')).toBe('hidden'); expect(state.crossEl.css('visibility')).toBe('hidden');
state.el.click(); state.el.click();
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
expect(state.crossEl.css('visibility')).toBe('visible'); expect(state.crossEl.css('visibility')).toBe('visible');
}); });
it('coordinates are updated [offsetX is set]', function () { it('coordinates are updated [offsetX is set]', function() {
var event, posX, posY, cssLeft, cssTop; var event, posX, posY, cssLeft, cssTop;
// Set up of 'click' event. // Set up of 'click' event.
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
); );
}); });
it('coordinates are updated [offsetX is NOT set]', function () { it('coordinates are updated [offsetX is NOT set]', function() {
var offset = state.el.offset(), var offset = state.el.offset(),
event, posX, posY, cssLeft, cssTop; event, posX, posY, cssLeft, cssTop;
......
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
describe('Collapsible', function () { describe('Collapsible', function() {
var el, html, html_custom, var el, html, html_custom,
initialize = function (template) { initialize = function(template) {
setFixtures(template); setFixtures(template);
el = $('.collapsible'); el = $('.collapsible');
Collapsible.setCollapsibles(el); Collapsible.setCollapsibles(el);
}, },
disableFx = function () { disableFx = function() {
$.fx.off = true; $.fx.off = true;
}, },
enableFx = function () { enableFx = function() {
$.fx.off = false; $.fx.off = false;
}; };
beforeEach(function () { beforeEach(function() {
html = '' + html = '' +
'<section class="collapsible">' + '<section class="collapsible">' +
'<div class="shortform">shortform message</div>' + '<div class="shortform">shortform message</div>' +
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
'</section>'; '</section>';
}); });
describe('setCollapsibles', function () { describe('setCollapsibles', function() {
it('Default container initialized correctly', function () { it('Default container initialized correctly', function() {
initialize(html); initialize(html);
expect(el.find('.shortform')).toContainElement('.full-top'); expect(el.find('.shortform')).toContainElement('.full-top');
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
expect(el.find('.full')).toHandle('click'); expect(el.find('.full')).toHandle('click');
}); });
it('Custom container initialized correctly', function () { it('Custom container initialized correctly', function() {
initialize(html_custom); initialize(html_custom);
expect(el.find('.shortform-custom')).toContainElement('.full-custom'); expect(el.find('.shortform-custom')).toContainElement('.full-custom');
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
}); });
}); });
describe('toggleFull', function () { describe('toggleFull', function() {
var assertChanges = function (state, anchorsElClass, showText, hideText) { var assertChanges = function(state, anchorsElClass, showText, hideText) {
var anchors, text; var anchors, text;
if (state == null) { if (state == null) {
...@@ -76,20 +76,20 @@ ...@@ -76,20 +76,20 @@
text = hideText; text = hideText;
} }
$.each(anchors, function (index, el) { $.each(anchors, function(index, el) {
expect(el).toHaveText(text); expect(el).toHaveText(text);
}); });
}; };
beforeEach(function () { beforeEach(function() {
disableFx(); disableFx();
}); });
afterEach(function () { afterEach(function() {
enableFx(); enableFx();
}); });
it('Default container', function () { it('Default container', function() {
var event; var event;
initialize(html); initialize(html);
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
assertChanges('closed', 'full', 'See full output', 'Hide output'); assertChanges('closed', 'full', 'See full output', 'Hide output');
}); });
it('Custom container', function () { it('Custom container', function() {
var event; var event;
initialize(html_custom); initialize(html_custom);
......
(function () { (function() {
'use strict'; 'use strict';
var origAjax = $.ajax; var origAjax = $.ajax;
var stubbedYT = { var stubbedYT = {
Player: function () { Player: function() {
var Player = jasmine.createSpyObj( var Player = jasmine.createSpyObj(
'YT.Player', 'YT.Player',
[ [
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
BUFFERING: 3, BUFFERING: 3,
CUED: 5 CUED: 5
}, },
ready: function (f) { ready: function(f) {
return f(); return f();
} }
}; };
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
window.STATUS = window.YT.PlayerState; window.STATUS = window.YT.PlayerState;
window.onTouchBasedDevice = function () { window.onTouchBasedDevice = function() {
return navigator.userAgent.match(/iPhone|iPod|iPad/i); return navigator.userAgent.match(/iPhone|iPod|iPad/i);
}; };
...@@ -77,31 +77,31 @@ ...@@ -77,31 +77,31 @@
jasmine.stubbedMetadata = { jasmine.stubbedMetadata = {
'7tqY6eQzVhE': { '7tqY6eQzVhE': {
contentDetails : { contentDetails: {
id: '7tqY6eQzVhE', id: '7tqY6eQzVhE',
duration: 'PT5M0S' duration: 'PT5M0S'
} }
}, },
'cogebirgzzM': { 'cogebirgzzM': {
contentDetails : { contentDetails: {
id: 'cogebirgzzM', id: 'cogebirgzzM',
duration: 'PT3M20S' duration: 'PT3M20S'
} }
}, },
'abcdefghijkl': { 'abcdefghijkl': {
contentDetails : { contentDetails: {
id: 'abcdefghijkl', id: 'abcdefghijkl',
duration: 'PT6M40S' duration: 'PT6M40S'
} }
}, },
bogus: { bogus: {
contentDetails : { contentDetails: {
duration: 'PT1M40S' duration: 'PT1M40S'
} }
} }
}; };
jasmine.fireEvent = function (el, eventName) { jasmine.fireEvent = function(el, eventName) {
var event; var event;
if (document.createEvent) { if (document.createEvent) {
...@@ -123,20 +123,20 @@ ...@@ -123,20 +123,20 @@
jasmine.stubbedHtml5Speeds = ['0.75', '1.0', '1.25', '1.50']; jasmine.stubbedHtml5Speeds = ['0.75', '1.0', '1.25', '1.50'];
jasmine.stubRequests = function () { jasmine.stubRequests = function() {
var spy = $.ajax; var spy = $.ajax;
if (!jasmine.isSpy($.ajax)) { if (!jasmine.isSpy($.ajax)) {
spy = spyOn($, 'ajax'); spy = spyOn($, 'ajax');
} }
return spy.and.callFake(function (settings) { return spy.and.callFake(function(settings) {
var match = settings.url var match = settings.url
.match(/googleapis\.com\/.+\/videos\/\?id=(.+)&part=contentDetails/), .match(/googleapis\.com\/.+\/videos\/\?id=(.+)&part=contentDetails/),
status, callCallback; status, callCallback;
if (match) { if (match) {
status = match[1].split('_'); status = match[1].split('_');
if (status && status[0] === 'status') { if (status && status[0] === 'status') {
callCallback = function (callback) { callCallback = function(callback) {
callback.call(window, {}, status[1]); callback.call(window, {}, status[1]);
}; };
...@@ -151,10 +151,10 @@ ...@@ -151,10 +151,10 @@
}); });
} else { } else {
return { return {
always: function (callback) { always: function(callback) {
return callback.call(window, {}, 'success'); return callback.call(window, {}, 'success');
}, },
done: function (callback) { done: function(callback) {
return callback.call(window, {}, 'success'); return callback.call(window, {}, 'success');
} }
}; };
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
return; return;
} else if (settings.url === '/save_user_state') { } else if (settings.url === '/save_user_state') {
return {success: true}; return {success: true};
} else if(settings.url.match(new RegExp(jasmine.getFixtures().fixturesPath + ".+", 'g'))) { } else if (settings.url.match(new RegExp(jasmine.getFixtures().fixturesPath + '.+', 'g'))) {
return origAjax(settings); return origAjax(settings);
} else { } else {
$.ajax.and.callThrough(); $.ajax.and.callThrough();
...@@ -196,9 +196,9 @@ ...@@ -196,9 +196,9 @@
// Stub window.Video.loadYouTubeIFrameAPI() // Stub window.Video.loadYouTubeIFrameAPI()
window.Video.loadYouTubeIFrameAPI = jasmine.createSpy('window.Video.loadYouTubeIFrameAPI').and.returnValue( window.Video.loadYouTubeIFrameAPI = jasmine.createSpy('window.Video.loadYouTubeIFrameAPI').and.returnValue(
function (scriptTag) { function(scriptTag) {
var event = document.createEvent('Event'); var event = document.createEvent('Event');
if (fixture === "video.html") { if (fixture === 'video.html') {
event.initEvent('load', false, false); event.initEvent('load', false, false);
} else { } else {
event.initEvent('error', false, false); event.initEvent('error', false, false);
...@@ -207,7 +207,7 @@ ...@@ -207,7 +207,7 @@
} }
); );
jasmine.initializePlayer = function (fixture, params) { jasmine.initializePlayer = function(fixture, params) {
var state; var state;
if (_.isString(fixture)) { if (_.isString(fixture)) {
...@@ -235,7 +235,7 @@ ...@@ -235,7 +235,7 @@
jasmine.stubRequests(); jasmine.stubRequests();
state = new window.Video('#example'); state = new window.Video('#example');
state.resizer = (function () { state.resizer = (function() {
var methods = [ var methods = [
'align', 'align',
'alignByWidthOnly', 'alignByWidthOnly',
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
reset: jasmine.createSpy().and.returnValue(obj) reset: jasmine.createSpy().and.returnValue(obj)
}; };
$.each(methods, function (index, method) { $.each(methods, function(index, method) {
obj[method] = jasmine.createSpy(method).and.returnValue(obj); obj[method] = jasmine.createSpy(method).and.returnValue(obj);
}); });
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
return state; return state;
}; };
jasmine.initializePlayerYouTube = function (params) { jasmine.initializePlayerYouTube = function(params) {
// "video.html" contains HTML template for a YouTube video. // "video.html" contains HTML template for a YouTube video.
return jasmine.initializePlayer('video.html', params); return jasmine.initializePlayer('video.html', params);
}; };
......
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
// into the optimized files. Therefore load these libraries through script tags and explicitly define them. // into the optimized files. Therefore load these libraries through script tags and explicitly define them.
// Note that when the optimizer executes this code, window will not be defined. // Note that when the optimizer executes this code, window will not be defined.
if (window) { if (window) {
var defineDependency = function (globalName, name, noShim) { var defineDependency = function(globalName, name, noShim) {
var getGlobalValue = function(name) { var getGlobalValue = function(name) {
var globalNamePath = name.split('.'), var globalNamePath = name.split('.'),
result = window, result = window,
i; i;
for (i = 0; i < globalNamePath.length; i++) { for (i = 0; i < globalNamePath.length; i++) {
result = result[globalNamePath[i]]; result = result[globalNamePath[i]];
} }
return result; return result;
}, },
globalValue = getGlobalValue(globalName); globalValue = getGlobalValue(globalName);
if (globalValue) { if (globalValue) {
if (noShim) { if (noShim) {
...@@ -24,22 +24,22 @@ ...@@ -24,22 +24,22 @@
} }
} }
else { else {
console.error("Expected library to be included on page, but not found on window object: " + name); console.error('Expected library to be included on page, but not found on window object: ' + name);
} }
}; };
defineDependency("jQuery", "jquery"); defineDependency('jQuery', 'jquery');
defineDependency("jQuery", "jquery-migrate"); defineDependency('jQuery', 'jquery-migrate');
defineDependency("_", "underscore"); defineDependency('_', 'underscore');
} }
requirejs.config({ requirejs.config({
baseUrl: '/base/', baseUrl: '/base/',
paths: { paths: {
"moment": "common_static/js/vendor/moment.min", 'moment': 'common_static/js/vendor/moment.min',
"draggabilly": "common_static/js/vendor/draggabilly", 'draggabilly': 'common_static/js/vendor/draggabilly',
'edx-ui-toolkit': 'common_static/edx-ui-toolkit' 'edx-ui-toolkit': 'common_static/edx-ui-toolkit'
}, },
"moment": { 'moment': {
exports: "moment" exports: 'moment'
} }
}); });
}).call(this, RequireJS.requirejs, RequireJS.define); }).call(this, RequireJS.requirejs, RequireJS.define);
...@@ -13,7 +13,7 @@ describe('Tests for split_test staff view switching', function() { ...@@ -13,7 +13,7 @@ describe('Tests for split_test staff view switching', function() {
delete window.XBlock; delete window.XBlock;
}); });
it("test that we have only one visible condition", function() { it('test that we have only one visible condition', function() {
var containers = elem.find('.split-test-child-container').length; var containers = elem.find('.split-test-child-container').length;
var conditions_shown = elem.find('.split-test-child-container .condition-text').length; var conditions_shown = elem.find('.split-test-child-container .condition-text').length;
expect(containers).toEqual(1); expect(containers).toEqual(1);
...@@ -21,17 +21,15 @@ describe('Tests for split_test staff view switching', function() { ...@@ -21,17 +21,15 @@ describe('Tests for split_test staff view switching', function() {
expect(XBlock.initializeBlocks).toHaveBeenCalled(); expect(XBlock.initializeBlocks).toHaveBeenCalled();
}); });
it("test that the right child is visible when selected", function() { it('test that the right child is visible when selected', function() {
var groups = ['0', '1', '2']; var groups = ['0', '1', '2'];
for(var i = 0; i < groups.length; i++) { for (var i = 0; i < groups.length; i++) {
var to_select = groups[i]; var to_select = groups[i];
elem.find('.split-test-select').val(to_select).change(); elem.find('.split-test-select').val(to_select).change();
var child_text = elem.find('.split-test-child-container .condition-text').text(); var child_text = elem.find('.split-test-child-container .condition-text').text();
expect(child_text).toContain(to_select); expect(child_text).toContain(to_select);
expect(XBlock.initializeBlocks).toHaveBeenCalled(); expect(XBlock.initializeBlocks).toHaveBeenCalled();
} }
}); });
}); });
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
describe('Time', function () { describe('Time', function() {
describe('format', function () { describe('format', function() {
describe('with NAN', function () { describe('with NAN', function() {
it('return a correct time format', function () { it('return a correct time format', function() {
expect(Time.format('string')).toEqual('0:00'); expect(Time.format('string')).toEqual('0:00');
expect(Time.format(void(0))).toEqual('0:00'); expect(Time.format(void(0))).toEqual('0:00');
}); });
}); });
describe('with duration more than or equal to 1 hour', function () { describe('with duration more than or equal to 1 hour', function() {
it('return a correct time format', function () { it('return a correct time format', function() {
expect(Time.format(3600)).toEqual('1:00:00'); expect(Time.format(3600)).toEqual('1:00:00');
expect(Time.format(7272)).toEqual('2:01:12'); expect(Time.format(7272)).toEqual('2:01:12');
}); });
}); });
describe('with duration less than 1 hour', function () { describe('with duration less than 1 hour', function() {
it('return a correct time format', function () { it('return a correct time format', function() {
expect(Time.format(1)).toEqual('0:01'); expect(Time.format(1)).toEqual('0:01');
expect(Time.format(61)).toEqual('1:01'); expect(Time.format(61)).toEqual('1:01');
expect(Time.format(3599)).toEqual('59:59'); expect(Time.format(3599)).toEqual('59:59');
...@@ -26,17 +26,17 @@ ...@@ -26,17 +26,17 @@
}); });
}); });
describe('formatFull', function () { describe('formatFull', function() {
it('gives correct string for times', function () { it('gives correct string for times', function() {
var testTimes = [ var testTimes = [
[0, '00:00:00'], [60, '00:01:00'], [0, '00:00:00'], [60, '00:01:00'],
[488, '00:08:08'], [2452, '00:40:52'], [488, '00:08:08'], [2452, '00:40:52'],
[3600, '01:00:00'], [28800, '08:00:00'], [3600, '01:00:00'], [28800, '08:00:00'],
[144532, '40:08:52'], [190360, '52:52:40'], [144532, '40:08:52'], [190360, '52:52:40'],
[294008, '81:40:08'], [-5, '00:00:00'] [294008, '81:40:08'], [-5, '00:00:00']
]; ];
$.each(testTimes, function (index, times) { $.each(testTimes, function(index, times) {
var timeInt = times[0], var timeInt = times[0],
timeStr = times[1]; timeStr = times[1];
...@@ -45,13 +45,12 @@ ...@@ -45,13 +45,12 @@
}); });
}); });
describe('convert', function () { describe('convert', function() {
it('return a correct time based on speed modifier', function () { it('return a correct time based on speed modifier', function() {
expect(Time.convert(0, 1, 1.5)).toEqual('0.000'); expect(Time.convert(0, 1, 1.5)).toEqual('0.000');
expect(Time.convert(100, 1, 1.5)).toEqual('66.667'); expect(Time.convert(100, 1, 1.5)).toEqual('66.667');
expect(Time.convert(100, 1.5, 1)).toEqual('150.000'); expect(Time.convert(100, 1.5, 1)).toEqual('150.000');
}); });
}); });
}); });
}).call(this); }).call(this);
(function (require) { (function(require) {
require( require(
['video/00_async_process.js'], ['video/00_async_process.js'],
function (AsyncProcess) { function(AsyncProcess) {
var getArrayNthLength = function (n, multiplier) { var getArrayNthLength = function(n, multiplier) {
var result = [], var result = [],
mul = multiplier || 1; mul = multiplier || 1;
...@@ -14,65 +14,65 @@ function (AsyncProcess) { ...@@ -14,65 +14,65 @@ function (AsyncProcess) {
}, },
items = getArrayNthLength(1000); items = getArrayNthLength(1000);
describe('AsyncProcess', function () { describe('AsyncProcess', function() {
it ('Array is processed successfully', function (done) { it('Array is processed successfully', function(done) {
var processedArray, var processedArray,
expectedArray = getArrayNthLength(1000, 2), expectedArray = getArrayNthLength(1000, 2),
process = function (item) { process = function(item) {
return 2 * item; return 2 * item;
}; };
AsyncProcess.array(items, process).done(function (result) { AsyncProcess.array(items, process).done(function(result) {
processedArray = result; processedArray = result;
}); });
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return processedArray; return processedArray;
}).then(function () { }).then(function() {
expect(processedArray).toEqual(expectedArray); expect(processedArray).toEqual(expectedArray);
}).always(done); }).always(done);
}); });
it ('If non-array is passed, error callback is called', function (done) { it('If non-array is passed, error callback is called', function(done) {
var isError, var isError,
process = function () {}; process = function() {};
AsyncProcess.array('string', process).fail(function () { AsyncProcess.array('string', process).fail(function() {
isError = true; isError = true;
}); });
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return isError; return isError;
}).then(function () { }).then(function() {
expect(isError).toBeTruthy(); expect(isError).toBeTruthy();
}).always(done); }).always(done);
}); });
it ('If an empty array is passed, returns initial array', function (done) { it('If an empty array is passed, returns initial array', function(done) {
var processedArray, var processedArray,
process = function () {}; process = function() {};
AsyncProcess.array([], process).done(function (result) { AsyncProcess.array([], process).done(function(result) {
processedArray = result; processedArray = result;
}); });
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return processedArray; return processedArray;
}).then(function () { }).then(function() {
expect(processedArray).toEqual([]); expect(processedArray).toEqual([]);
}).always(done); }).always(done);
}); });
it ('If no process function passed, returns initial array', function (done) { it('If no process function passed, returns initial array', function(done) {
var processedArray; var processedArray;
AsyncProcess.array(items).done(function (result) { AsyncProcess.array(items).done(function(result) {
processedArray = result; processedArray = result;
}); });
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return processedArray; return processedArray;
}).then(function () { }).then(function() {
expect(processedArray).toEqual(items); expect(processedArray).toEqual(items);
}).always(done); }).always(done);
}); });
......
(function (undefined) { (function(undefined) {
describe('VideoPlayer Events', function () { describe('VideoPlayer Events', function() {
var state, oldOTBD; var state, oldOTBD;
describe('HTML5', function () { describe('HTML5', function() {
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice') .createSpy('onTouchBasedDevice')
...@@ -14,53 +14,53 @@ ...@@ -14,53 +14,53 @@
state.videoEl = $('video, iframe'); state.videoEl = $('video, iframe');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
it('initialize', function (done) { it('initialize', function(done) {
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return state.el.hasClass('is-initialized'); return state.el.hasClass('is-initialized');
}).then(function () { }).then(function() {
expect('initialize').not.toHaveBeenTriggeredOn('.video'); expect('initialize').not.toHaveBeenTriggeredOn('.video');
}).always(done); }).always(done);
}); });
it('ready', function (done) { it('ready', function(done) {
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return state.el.hasClass('is-initialized'); return state.el.hasClass('is-initialized');
}).then(function () { }).then(function() {
expect('ready').not.toHaveBeenTriggeredOn('.video'); expect('ready').not.toHaveBeenTriggeredOn('.video');
}).always(done); }).always(done);
}); });
it('play', function () { it('play', function() {
state.videoPlayer.play(); state.videoPlayer.play();
expect('play').not.toHaveBeenTriggeredOn('.video'); expect('play').not.toHaveBeenTriggeredOn('.video');
}); });
it('pause', function () { it('pause', function() {
state.videoPlayer.play(); state.videoPlayer.play();
state.videoPlayer.pause(); state.videoPlayer.pause();
expect('pause').not.toHaveBeenTriggeredOn('.video'); expect('pause').not.toHaveBeenTriggeredOn('.video');
}); });
it('volumechange', function () { it('volumechange', function() {
state.videoPlayer.onVolumeChange(60); state.videoPlayer.onVolumeChange(60);
expect('volumechange').not.toHaveBeenTriggeredOn('.video'); expect('volumechange').not.toHaveBeenTriggeredOn('.video');
}); });
it('speedchange', function () { it('speedchange', function() {
state.videoPlayer.onSpeedChange('2.0'); state.videoPlayer.onSpeedChange('2.0');
expect('speedchange').not.toHaveBeenTriggeredOn('.video'); expect('speedchange').not.toHaveBeenTriggeredOn('.video');
}); });
it('seek', function () { it('seek', function() {
state.videoPlayer.onCaptionSeek({ state.videoPlayer.onCaptionSeek({
time: 1, time: 1,
type: 'any' type: 'any'
...@@ -69,15 +69,15 @@ ...@@ -69,15 +69,15 @@
expect('seek').not.toHaveBeenTriggeredOn('.video'); expect('seek').not.toHaveBeenTriggeredOn('.video');
}); });
it('ended', function () { it('ended', function() {
state.videoPlayer.onEnded(); state.videoPlayer.onEnded();
expect('ended').not.toHaveBeenTriggeredOn('.video'); expect('ended').not.toHaveBeenTriggeredOn('.video');
}); });
}); });
describe('YouTube', function () { describe('YouTube', function() {
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice') .createSpy('onTouchBasedDevice')
...@@ -86,19 +86,18 @@ ...@@ -86,19 +86,18 @@
state = jasmine.initializePlayerYouTube(); state = jasmine.initializePlayerYouTube();
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
it('qualitychange', function () { it('qualitychange', function() {
state.videoPlayer.onPlaybackQualityChange(); state.videoPlayer.onPlaybackQualityChange();
expect('qualitychange').not.toHaveBeenTriggeredOn('.video'); expect('qualitychange').not.toHaveBeenTriggeredOn('.video');
}); });
}); });
}); });
}).call(this); }).call(this);
(function (undefined) { (function(undefined) {
describe('Video', function () { describe('Video', function() {
var oldOTBD, state; var oldOTBD, state;
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.VideoState = {}; window.VideoState = {};
window.VideoState.id = {}; window.VideoState.id = {};
window.YT = jasmine.YT; window.YT = jasmine.YT;
}); });
describe('constructor', function () { describe('constructor', function() {
describe('YT', function () { describe('YT', function() {
beforeEach(function () { beforeEach(function() {
loadFixtures('video.html'); loadFixtures('video.html');
$.cookie.and.returnValue('0.50'); $.cookie.and.returnValue('0.50');
}); });
describe('by default', function () { describe('by default', function() {
beforeEach(function () { beforeEach(function() {
this.state = jasmine.initializePlayerYouTube('video_html5.html'); this.state = jasmine.initializePlayerYouTube('video_html5.html');
}); });
afterEach(function () { afterEach(function() {
this.state.storage.clear(); this.state.storage.clear();
this.state.videoPlayer.destroy(); this.state.videoPlayer.destroy();
}); });
it('check videoType', function () { it('check videoType', function() {
expect(this.state.videoType).toEqual('youtube'); expect(this.state.videoType).toEqual('youtube');
}); });
it('set the elements', function () { it('set the elements', function() {
expect(this.state.el).toEqual($('#video_id')); expect(this.state.el).toEqual($('#video_id'));
}); });
it('parse the videos', function () { it('parse the videos', function() {
expect(this.state.videos).toEqual({ expect(this.state.videos).toEqual({
'0.50': '7tqY6eQzVhE', '0.50': '7tqY6eQzVhE',
'1.0': 'cogebirgzzM', '1.0': 'cogebirgzzM',
...@@ -42,49 +42,49 @@ ...@@ -42,49 +42,49 @@
}); });
}); });
it('parse available video speeds', function () { it('parse available video speeds', function() {
expect(this.state.speeds).toEqual(['0.50', '1.0', '1.50']); expect(this.state.speeds).toEqual(['0.50', '1.0', '1.50']);
}); });
it('set current video speed via cookie', function () { it('set current video speed via cookie', function() {
expect(this.state.speed).toEqual('1.50'); expect(this.state.speed).toEqual('1.50');
}); });
}); });
}); });
describe('HTML5', function () { describe('HTML5', function() {
var state; var state;
beforeEach(function () { beforeEach(function() {
$.cookie.and.returnValue('0.75'); $.cookie.and.returnValue('0.75');
state = jasmine.initializePlayer('video_html5.html'); state = jasmine.initializePlayer('video_html5.html');
}); });
afterEach(function () { afterEach(function() {
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
describe('by default', function () { describe('by default', function() {
it('check videoType', function () { it('check videoType', function() {
expect(state.videoType).toEqual('html5'); expect(state.videoType).toEqual('html5');
}); });
it('set the elements', function () { it('set the elements', function() {
expect(state.el).toEqual($('#video_id')); expect(state.el).toEqual($('#video_id'));
}); });
it('doesn\'t have `videos` dictionary', function () { it('doesn\'t have `videos` dictionary', function() {
expect(state.videos).toBeUndefined(); expect(state.videos).toBeUndefined();
}); });
it('parse available video speeds', function () { it('parse available video speeds', function() {
var speeds = jasmine.stubbedHtml5Speeds; var speeds = jasmine.stubbedHtml5Speeds;
expect(state.speeds).toEqual(speeds); expect(state.speeds).toEqual(speeds);
}); });
it('set current video speed via cookie', function () { it('set current video speed via cookie', function() {
expect(state.speed).toEqual('1.50'); expect(state.speed).toEqual('1.50');
}); });
}); });
...@@ -93,34 +93,34 @@ ...@@ -93,34 +93,34 @@
// handled by Require JS. When state.videoPlayer is created, // handled by Require JS. When state.videoPlayer is created,
// the stand alone HTML5 player object is already loaded, so no // the stand alone HTML5 player object is already loaded, so no
// further testing in that case is required. // further testing in that case is required.
describe('HTML5 API is available', function () { describe('HTML5 API is available', function() {
it('create the Video Player', function () { it('create the Video Player', function() {
expect(state.videoPlayer.player).not.toBeUndefined(); expect(state.videoPlayer.player).not.toBeUndefined();
}); });
}); });
}); });
}); });
describe('YouTube API is not loaded', function () { describe('YouTube API is not loaded', function() {
var state; var state;
beforeEach(function () { beforeEach(function() {
window.YT = undefined; window.YT = undefined;
state = jasmine.initializePlayerYouTube(); state = jasmine.initializePlayerYouTube();
}); });
afterEach(function () { afterEach(function() {
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
it('callback, to be called after YouTube API loads, exists and is called', function (done) { it('callback, to be called after YouTube API loads, exists and is called', function(done) {
window.YT = jasmine.YT; window.YT = jasmine.YT;
// Call the callback that must be called when YouTube API is // Call the callback that must be called when YouTube API is
// loaded. By specification. // loaded. By specification.
window.onYouTubeIframeAPIReady(); window.onYouTubeIframeAPIReady();
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return state.youtubeApiAvailable === true; return state.youtubeApiAvailable === true;
}).done(function(){ }).done(function() {
// If YouTube API is not loaded, then the code will should create // If YouTube API is not loaded, then the code will should create
// a global callback that will be called by API once it is loaded. // a global callback that will be called by API once it is loaded.
expect(window.onYouTubeIframeAPIReady).not.toBeUndefined(); expect(window.onYouTubeIframeAPIReady).not.toBeUndefined();
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
}); });
}); });
describe('checking start and end times', function () { describe('checking start and end times', function() {
var state; var state;
var miniTestSuite = [ var miniTestSuite = [
{ {
...@@ -158,19 +158,19 @@ ...@@ -158,19 +158,19 @@
} }
]; ];
afterEach(function () { afterEach(function() {
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
$.each(miniTestSuite, function (index, test) { $.each(miniTestSuite, function(index, test) {
itFabrique(test.itDescription, test.data, test.expectData); itFabrique(test.itDescription, test.data, test.expectData);
}); });
return; return;
function itFabrique(itDescription, data, expectData) { function itFabrique(itDescription, data, expectData) {
it(itDescription, function () { it(itDescription, function() {
state = jasmine.initializePlayer('video.html', { state = jasmine.initializePlayer('video.html', {
'start': data.start, 'start': data.start,
'end': data.end 'end': data.end
...@@ -183,10 +183,10 @@ ...@@ -183,10 +183,10 @@
}); });
// Disabled 11/25/13 due to flakiness in master // Disabled 11/25/13 due to flakiness in master
xdescribe('multiple YT on page', function () { xdescribe('multiple YT on page', function() {
var state1, state2, state3; var state1, state2, state3;
beforeEach(function () { beforeEach(function() {
loadFixtures('video_yt_multiple.html'); loadFixtures('video_yt_multiple.html');
spyOn($, 'ajaxWithPrefix'); spyOn($, 'ajaxWithPrefix');
...@@ -207,32 +207,32 @@ ...@@ -207,32 +207,32 @@
it( it(
'check for YT availability is performed only once', 'check for YT availability is performed only once',
function () function()
{ {
var numAjaxCalls = 0; var numAjaxCalls = 0;
// Total ajax calls made. // Total ajax calls made.
numAjaxCalls = $.ajax.calls.length; numAjaxCalls = $.ajax.calls.length;
// Subtract ajax calls to get captions via // Subtract ajax calls to get captions via
// state.videoCaption.fetchCaption() function. // state.videoCaption.fetchCaption() function.
numAjaxCalls -= $.ajaxWithPrefix.calls.length; numAjaxCalls -= $.ajaxWithPrefix.calls.length;
// Subtract ajax calls to get metadata for each video via // Subtract ajax calls to get metadata for each video via
// state.getVideoMetadata() function. // state.getVideoMetadata() function.
numAjaxCalls -= 3; numAjaxCalls -= 3;
// Subtract ajax calls to log event 'pause_video' via // Subtract ajax calls to log event 'pause_video' via
// state.videoPlayer.log() function. // state.videoPlayer.log() function.
numAjaxCalls -= 3; numAjaxCalls -= 3;
// This should leave just one call. It was made to check // This should leave just one call. It was made to check
// for YT availability. This is done in state.initialize() // for YT availability. This is done in state.initialize()
// function. SPecifically, with the statement // function. SPecifically, with the statement
// //
// this.youtubeXhr = this.getVideoMetadata(); // this.youtubeXhr = this.getVideoMetadata();
expect(numAjaxCalls).toBe(1); expect(numAjaxCalls).toBe(1);
}); });
}); });
}); });
}).call(this); }).call(this);
(function (require) { (function(require) {
require( require(
['video/00_iterator.js'], ['video/00_iterator.js'],
function (Iterator) { function(Iterator) {
describe('Iterator', function () { describe('Iterator', function() {
var list = ['a', 'b', 'c', 'd', 'e'], var list = ['a', 'b', 'c', 'd', 'e'],
iterator; iterator;
...@@ -10,36 +10,36 @@ function (Iterator) { ...@@ -10,36 +10,36 @@ function (Iterator) {
iterator = new Iterator(list); iterator = new Iterator(list);
}); });
it('size contains correct list length', function () { it('size contains correct list length', function() {
expect(iterator.size).toBe(list.length); expect(iterator.size).toBe(list.length);
expect(iterator.lastIndex).toBe(list.length - 1); expect(iterator.lastIndex).toBe(list.length - 1);
}); });
describe('next', function () { describe('next', function() {
describe('with passed `index`', function () { describe('with passed `index`', function() {
it('returns next item in the list', function () { it('returns next item in the list', function() {
expect(iterator.next(2)).toBe('d'); expect(iterator.next(2)).toBe('d');
expect(iterator.next(0)).toBe('b'); expect(iterator.next(0)).toBe('b');
}); });
it('returns first item if index equal last item', function () { it('returns first item if index equal last item', function() {
expect(iterator.next(4)).toBe('a'); expect(iterator.next(4)).toBe('a');
}); });
it('returns next item if index is not valid', function () { it('returns next item if index is not valid', function() {
expect(iterator.next(-4)).toBe('b'); // index < 0 expect(iterator.next(-4)).toBe('b'); // index < 0
expect(iterator.next(100)).toBe('c'); // index > size expect(iterator.next(100)).toBe('c'); // index > size
expect(iterator.next('99')).toBe('d'); // incorrect Type expect(iterator.next('99')).toBe('d'); // incorrect Type
}); });
}); });
describe('without passed `index`', function () { describe('without passed `index`', function() {
it('returns next item in the list', function () { it('returns next item in the list', function() {
expect(iterator.next()).toBe('b'); expect(iterator.next()).toBe('b');
expect(iterator.next()).toBe('c'); expect(iterator.next()).toBe('c');
}); });
it('returns first item if index equal last item', function () { it('returns first item if index equal last item', function() {
expect(iterator.next()).toBe('b'); expect(iterator.next()).toBe('b');
expect(iterator.next()).toBe('c'); expect(iterator.next()).toBe('c');
expect(iterator.next()).toBe('d'); expect(iterator.next()).toBe('d');
...@@ -49,45 +49,45 @@ function (Iterator) { ...@@ -49,45 +49,45 @@ function (Iterator) {
}); });
}); });
describe('prev', function () { describe('prev', function() {
describe('with passed `index`', function () { describe('with passed `index`', function() {
it('returns previous item in the list', function () { it('returns previous item in the list', function() {
expect(iterator.prev(3)).toBe('c'); expect(iterator.prev(3)).toBe('c');
expect(iterator.prev(1)).toBe('a'); expect(iterator.prev(1)).toBe('a');
}); });
it('returns last item if index equal first item', function () { it('returns last item if index equal first item', function() {
expect(iterator.prev(0)).toBe('e'); expect(iterator.prev(0)).toBe('e');
}); });
it('returns previous item if index is not valid', function () { it('returns previous item if index is not valid', function() {
expect(iterator.prev(-4)).toBe('e'); // index < 0 expect(iterator.prev(-4)).toBe('e'); // index < 0
expect(iterator.prev(100)).toBe('d'); // index > size expect(iterator.prev(100)).toBe('d'); // index > size
expect(iterator.prev('99')).toBe('c'); // incorrect Type expect(iterator.prev('99')).toBe('c'); // incorrect Type
}); });
}); });
describe('without passed `index`', function () { describe('without passed `index`', function() {
it('returns previous item in the list', function () { it('returns previous item in the list', function() {
expect(iterator.prev()).toBe('e'); expect(iterator.prev()).toBe('e');
expect(iterator.prev()).toBe('d'); expect(iterator.prev()).toBe('d');
}); });
it('returns last item if index equal first item', function () { it('returns last item if index equal first item', function() {
expect(iterator.prev()).toBe('e'); expect(iterator.prev()).toBe('e');
}); });
}); });
}); });
it('returns last item in the list', function () { it('returns last item in the list', function() {
expect(iterator.last()).toBe('e'); expect(iterator.last()).toBe('e');
}); });
it('returns first item in the list', function () { it('returns first item in the list', function() {
expect(iterator.first()).toBe('a'); expect(iterator.first()).toBe('a');
}); });
it('isEnd works correctly', function () { it('isEnd works correctly', function() {
expect(iterator.isEnd()).toBeFalsy(); expect(iterator.isEnd()).toBeFalsy();
iterator.next(); // => index 1 iterator.next(); // => index 1
expect(iterator.isEnd()).toBeFalsy(); expect(iterator.isEnd()).toBeFalsy();
......
(function (requirejs, require, define, undefined) { (function(requirejs, require, define, undefined) {
require(
require(
['video/00_resizer.js'], ['video/00_resizer.js'],
function (Resizer) { function(Resizer) {
describe('Resizer', function() {
describe('Resizer', function () {
var html = [ var html = [
'<div ' + '<div ' +
'class="rszr-wrapper" ' + 'class="rszr-wrapper" ' +
'style="width:200px; height: 200px;"' + 'style="width:200px; height: 200px;"' +
'>', '>',
'<div ' + '<div ' +
'class="rszr-el" ' + 'class="rszr-el" ' +
'style="width:100px; height: 150px;"' + 'style="width:100px; height: 150px;"' +
'>', '>',
'Content', 'Content',
'</div>', '</div>',
'</div>' '</div>'
].join(''), ].join(''),
config, container, element; config, container, element;
beforeEach(function () { beforeEach(function() {
setFixtures(html); setFixtures(html);
container = $('.rszr-wrapper'); container = $('.rszr-wrapper');
...@@ -34,13 +32,13 @@ function (Resizer) { ...@@ -34,13 +32,13 @@ function (Resizer) {
}); });
it('When Initialize without required parameters, log message is shown', it('When Initialize without required parameters, log message is shown',
function () { function() {
new Resizer({ }); new Resizer({ });
expect(console.log).toHaveBeenCalled(); expect(console.log).toHaveBeenCalled();
} }
); );
it('`alignByWidthOnly` works correctly', function () { it('`alignByWidthOnly` works correctly', function() {
var resizer = new Resizer(config).alignByWidthOnly(), var resizer = new Resizer(config).alignByWidthOnly(),
expectedWidth = container.width(), expectedWidth = container.width(),
realWidth = element.width(); realWidth = element.width();
...@@ -48,7 +46,7 @@ function (Resizer) { ...@@ -48,7 +46,7 @@ function (Resizer) {
expect(realWidth).toBe(expectedWidth); expect(realWidth).toBe(expectedWidth);
}); });
it('`alignByHeightOnly` works correctly', function () { it('`alignByHeightOnly` works correctly', function() {
var resizer = new Resizer(config).alignByHeightOnly(), var resizer = new Resizer(config).alignByHeightOnly(),
expectedHeight = container.height(), expectedHeight = container.height(),
realHeight = element.height(); realHeight = element.height();
...@@ -56,7 +54,7 @@ function (Resizer) { ...@@ -56,7 +54,7 @@ function (Resizer) {
expect(realHeight).toBe(expectedHeight); expect(realHeight).toBe(expectedHeight);
}); });
it('`align` works correctly', function () { it('`align` works correctly', function() {
var resizer = new Resizer(config).align(), var resizer = new Resizer(config).align(),
expectedHeight = container.height(), expectedHeight = container.height(),
realHeight = element.height(), realHeight = element.height(),
...@@ -71,10 +69,9 @@ function (Resizer) { ...@@ -71,10 +69,9 @@ function (Resizer) {
realWidth = element.width(); realWidth = element.width();
expect(realWidth).toBe(expectedWidth); expect(realWidth).toBe(expectedWidth);
}); });
it('`setMode` works correctly', function () { it('`setMode` works correctly', function() {
var resizer = new Resizer(config).setMode('height'), var resizer = new Resizer(config).setMode('height'),
expectedHeight = container.height(), expectedHeight = container.height(),
realHeight = element.height(), realHeight = element.height(),
...@@ -91,7 +88,7 @@ function (Resizer) { ...@@ -91,7 +88,7 @@ function (Resizer) {
expect(realWidth).toBe(expectedWidth); expect(realWidth).toBe(expectedWidth);
}); });
it('`setElement` works correctly', function () { it('`setElement` works correctly', function() {
container.append('<div ' + container.append('<div ' +
'id="Another-el" ' + 'id="Another-el" ' +
'style="width:100px; height: 150px;"' + 'style="width:100px; height: 150px;"' +
...@@ -105,14 +102,14 @@ function (Resizer) { ...@@ -105,14 +102,14 @@ function (Resizer) {
expect(newElement.height()).toBe(expectedHeight); expect(newElement.height()).toBe(expectedHeight);
}); });
describe('Callbacks', function () { describe('Callbacks', function() {
var resizer, var resizer,
spiesList = []; spiesList = [];
beforeEach(function () { beforeEach(function() {
var spiesCount = _.range(3); var spiesCount = _.range(3);
spiesList = $.map(spiesCount, function () { spiesList = $.map(spiesCount, function() {
return jasmine.createSpy(); return jasmine.createSpy();
}); });
...@@ -120,19 +117,19 @@ function (Resizer) { ...@@ -120,19 +117,19 @@ function (Resizer) {
}); });
it('callbacks are called', function () { it('callbacks are called', function() {
$.each(spiesList, function (index, spy) { $.each(spiesList, function(index, spy) {
resizer.callbacks.add(spy); resizer.callbacks.add(spy);
}); });
resizer.align(); resizer.align();
$.each(spiesList, function (index, spy) { $.each(spiesList, function(index, spy) {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
}); });
it('callback called just once', function () { it('callback called just once', function() {
resizer.callbacks.once(spiesList[0]); resizer.callbacks.once(spiesList[0]);
resizer resizer
...@@ -142,21 +139,21 @@ function (Resizer) { ...@@ -142,21 +139,21 @@ function (Resizer) {
expect(spiesList[0].calls.count()).toEqual(1); expect(spiesList[0].calls.count()).toEqual(1);
}); });
it('all callbacks are removed', function () { it('all callbacks are removed', function() {
$.each(spiesList, function (index, spy) { $.each(spiesList, function(index, spy) {
resizer.callbacks.add(spy); resizer.callbacks.add(spy);
}); });
resizer.callbacks.removeAll(); resizer.callbacks.removeAll();
resizer.align(); resizer.align();
$.each(spiesList, function (index, spy) { $.each(spiesList, function(index, spy) {
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
}); });
}); });
it('specific callback is removed', function () { it('specific callback is removed', function() {
$.each(spiesList, function (index, spy) { $.each(spiesList, function(index, spy) {
resizer.callbacks.add(spy); resizer.callbacks.add(spy);
}); });
...@@ -168,32 +165,31 @@ function (Resizer) { ...@@ -168,32 +165,31 @@ function (Resizer) {
it( it(
'Error message is shown when wrong argument type is passed', 'Error message is shown when wrong argument type is passed',
function () function()
{ {
var methods = ['add', 'once'], var methods = ['add', 'once'],
errorMessage = '[Video info]: TypeError: Argument is not a function.', errorMessage = '[Video info]: TypeError: Argument is not a function.',
arg = {}; arg = {};
spyOn(console, 'error'); spyOn(console, 'error');
$.each(methods, function (index, methodName) { $.each(methods, function(index, methodName) {
resizer.callbacks[methodName](arg); resizer.callbacks[methodName](arg);
expect(console.error).toHaveBeenCalledWith(errorMessage); expect(console.error).toHaveBeenCalledWith(errorMessage);
//reset spy // reset spy
console.log.calls.reset(); console.log.calls.reset();
});
}); });
});
}); });
describe('Delta', function () { describe('Delta', function() {
var resizer; var resizer;
beforeEach(function () { beforeEach(function() {
resizer = new Resizer(config); resizer = new Resizer(config);
}); });
it('adding delta align correctly by height', function () { it('adding delta align correctly by height', function() {
var delta = 100, var delta = 100,
expectedHeight = container.height() + delta, expectedHeight = container.height() + delta,
realHeight; realHeight;
...@@ -207,7 +203,7 @@ function (Resizer) { ...@@ -207,7 +203,7 @@ function (Resizer) {
expect(realHeight).toBe(expectedHeight); expect(realHeight).toBe(expectedHeight);
}); });
it('adding delta align correctly by width', function () { it('adding delta align correctly by width', function() {
var delta = 100, var delta = 100,
expectedWidth = container.width() + delta, expectedWidth = container.width() + delta,
realWidth; realWidth;
...@@ -221,7 +217,7 @@ function (Resizer) { ...@@ -221,7 +217,7 @@ function (Resizer) {
expect(realWidth).toBe(expectedWidth); expect(realWidth).toBe(expectedWidth);
}); });
it('substract delta align correctly by height', function () { it('substract delta align correctly by height', function() {
var delta = 100, var delta = 100,
expectedHeight = container.height() - delta, expectedHeight = container.height() - delta,
realHeight; realHeight;
...@@ -235,7 +231,7 @@ function (Resizer) { ...@@ -235,7 +231,7 @@ function (Resizer) {
expect(realHeight).toBe(expectedHeight); expect(realHeight).toBe(expectedHeight);
}); });
it('substract delta align correctly by width', function () { it('substract delta align correctly by width', function() {
var delta = 100, var delta = 100,
expectedWidth = container.width() - delta, expectedWidth = container.width() - delta,
realWidth; realWidth;
...@@ -249,7 +245,7 @@ function (Resizer) { ...@@ -249,7 +245,7 @@ function (Resizer) {
expect(realWidth).toBe(expectedWidth); expect(realWidth).toBe(expectedWidth);
}); });
it('reset delta', function () { it('reset delta', function() {
var delta = 100, var delta = 100,
expectedWidth = container.width(), expectedWidth = container.width(),
realWidth; realWidth;
...@@ -266,6 +262,4 @@ function (Resizer) { ...@@ -266,6 +262,4 @@ function (Resizer) {
}); });
}); });
}); });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
(function (require) { (function(require) {
require( require(
['video/00_sjson.js'], ['video/00_sjson.js'],
function (Sjson) { function(Sjson) {
describe('Sjson', function () { describe('Sjson', function() {
var data = jasmine.stubbedCaption, var data = jasmine.stubbedCaption,
sjson; sjson;
var videoStops = [0, 3120, 6270, 8490, 21620, 24920]; var videoStops = [0, 3120, 6270, 8490, 21620, 24920];
...@@ -12,19 +12,19 @@ function (Sjson) { ...@@ -12,19 +12,19 @@ function (Sjson) {
sjson = new Sjson(data); sjson = new Sjson(data);
}); });
it ('returns captions', function () { it('returns captions', function() {
expect(sjson.getCaptions()).toEqual(data.text); expect(sjson.getCaptions()).toEqual(data.text);
}); });
it ('returns start times', function () { it('returns start times', function() {
expect(sjson.getStartTimes()).toEqual(data.start); expect(sjson.getStartTimes()).toEqual(data.start);
}); });
it ('returns correct length', function () { it('returns correct length', function() {
expect(sjson.getSize()).toEqual(data.text.length); expect(sjson.getSize()).toEqual(data.text.length);
}); });
it('search returns a correct caption index', function () { it('search returns a correct caption index', function() {
expect(sjson.search(videoStops[0])).toEqual(0); expect(sjson.search(videoStops[0])).toEqual(0);
expect(sjson.search(videoStops[1])).toEqual(1); expect(sjson.search(videoStops[1])).toEqual(1);
expect(sjson.search(videoStops[2])).toEqual(2); expect(sjson.search(videoStops[2])).toEqual(2);
...@@ -41,7 +41,7 @@ function (Sjson) { ...@@ -41,7 +41,7 @@ function (Sjson) {
expect(sjson.search(-1)).toEqual(0); expect(sjson.search(-1)).toEqual(0);
}); });
it('search only searches through a subrange of times if start / end times are specified', function () { it('search only searches through a subrange of times if start / end times are specified', function() {
var start = videoStops[2] - 100; var start = videoStops[2] - 100;
var end = videoStops[5] - 100; var end = videoStops[5] - 100;
var results = sjson.filter(start, end); var results = sjson.filter(start, end);
...@@ -54,7 +54,7 @@ function (Sjson) { ...@@ -54,7 +54,7 @@ function (Sjson) {
expect(sjson.search(OUT_OF_BOUNDS_STOP, start, end)).toEqual(expectedLength); expect(sjson.search(OUT_OF_BOUNDS_STOP, start, end)).toEqual(expectedLength);
}); });
it('filters results correctly given a start and end time', function () { it('filters results correctly given a start and end time', function() {
var start = videoStops[1] - 100; var start = videoStops[1] - 100;
var end = videoStops[4] - 100; var end = videoStops[4] - 100;
var results = sjson.filter(start, end); var results = sjson.filter(start, end);
......
(function (WAIT_TIMEOUT) { (function(WAIT_TIMEOUT) {
'use strict'; 'use strict';
describe('VideoBumper', function () { describe('VideoBumper', function() {
var state, oldOTBD, waitForPlaying; var state, oldOTBD, waitForPlaying;
waitForPlaying = function (state, done) { waitForPlaying = function(state, done) {
jasmine.waitUntil(function () { jasmine.waitUntil(function() {
return state.el.hasClass('is-playing'); return state.el.hasClass('is-playing');
}).done(done); }).done(done);
}; };
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
jasmine.clock().install(); jasmine.clock().install();
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
if (state.bumperState && state.bumperState.videoPlayer) { if (state.bumperState && state.bumperState.videoPlayer) {
...@@ -31,39 +31,39 @@ ...@@ -31,39 +31,39 @@
jasmine.clock().uninstall(); jasmine.clock().uninstall();
}); });
it('can render the bumper video', function () { it('can render the bumper video', function() {
expect($('.is-bumper')).toExist(); expect($('.is-bumper')).toExist();
}); });
it('can show the main video on error', function (done) { it('can show the main video on error', function(done) {
state.el.triggerHandler('error'); state.el.triggerHandler('error');
jasmine.clock().tick(20); jasmine.clock().tick(20);
expect($('.is-bumper')).not.toExist(); expect($('.is-bumper')).not.toExist();
waitForPlaying(state, done); waitForPlaying(state, done);
}); });
it('can show the main video once bumper ends', function (done) { it('can show the main video once bumper ends', function(done) {
state.el.trigger('ended'); state.el.trigger('ended');
jasmine.clock().tick(20); jasmine.clock().tick(20);
expect($('.is-bumper')).not.toExist(); expect($('.is-bumper')).not.toExist();
waitForPlaying(state, done); waitForPlaying(state, done);
}); });
it('can show the main video on skip', function (done) { it('can show the main video on skip', function(done) {
state.bumperState.videoBumper.skip(); state.bumperState.videoBumper.skip();
jasmine.clock().tick(20); jasmine.clock().tick(20);
expect($('.is-bumper')).not.toExist(); expect($('.is-bumper')).not.toExist();
waitForPlaying(state, done); waitForPlaying(state, done);
}); });
it('can stop the bumper video playing if it is too long', function (done) { it('can stop the bumper video playing if it is too long', function(done) {
state.el.trigger('timeupdate', [state.bumperState.videoBumper.maxBumperDuration + 1]); state.el.trigger('timeupdate', [state.bumperState.videoBumper.maxBumperDuration + 1]);
jasmine.clock().tick(20); jasmine.clock().tick(20);
expect($('.is-bumper')).not.toExist(); expect($('.is-bumper')).not.toExist();
waitForPlaying(state, done); waitForPlaying(state, done);
}); });
it('can save appropriate states correctly on ended', function () { it('can save appropriate states correctly on ended', function() {
var saveState = jasmine.createSpy('saveState'); var saveState = jasmine.createSpy('saveState');
state.bumperState.videoSaveStatePlugin.saveState = saveState; state.bumperState.videoSaveStatePlugin.saveState = saveState;
state.el.trigger('ended'); state.el.trigger('ended');
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
bumper_last_view_date: true}); bumper_last_view_date: true});
}); });
it('can save appropriate states correctly on skip', function () { it('can save appropriate states correctly on skip', function() {
var saveState = jasmine.createSpy('saveState'); var saveState = jasmine.createSpy('saveState');
state.bumperState.videoSaveStatePlugin.saveState = saveState; state.bumperState.videoSaveStatePlugin.saveState = saveState;
state.bumperState.videoBumper.skip(); state.bumperState.videoBumper.skip();
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
bumper_last_view_date: true}); bumper_last_view_date: true});
}); });
it('can save appropriate states correctly on error', function () { it('can save appropriate states correctly on error', function() {
var saveState = jasmine.createSpy('saveState'); var saveState = jasmine.createSpy('saveState');
state.bumperState.videoSaveStatePlugin.saveState = saveState; state.bumperState.videoSaveStatePlugin.saveState = saveState;
state.el.triggerHandler('error'); state.el.triggerHandler('error');
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
bumper_last_view_date: true}); bumper_last_view_date: true});
}); });
it('can save appropriate states correctly on skip and do not show again', function () { it('can save appropriate states correctly on skip and do not show again', function() {
var saveState = jasmine.createSpy('saveState'); var saveState = jasmine.createSpy('saveState');
state.bumperState.videoSaveStatePlugin.saveState = saveState; state.bumperState.videoSaveStatePlugin.saveState = saveState;
state.bumperState.videoBumper.skipAndDoNotShowAgain(); state.bumperState.videoBumper.skipAndDoNotShowAgain();
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
bumper_last_view_date: true, bumper_do_not_show_again: true}); bumper_last_view_date: true, bumper_do_not_show_again: true});
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.bumperState.videoBumper.destroy(); state.bumperState.videoBumper.destroy();
expect(state.videoBumper).toBeUndefined(); expect(state.videoBumper).toBeUndefined();
}); });
......
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
describe('VideoPlayer Events Bumper plugin', function () { describe('VideoPlayer Events Bumper plugin', function() {
var Logger = window.Logger; var Logger = window.Logger;
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice') .createSpy('onTouchBasedDevice')
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
spyOn(state.bumperState.videoEventsBumperPlugin, 'getDuration').and.returnValue(20); spyOn(state.bumperState.videoEventsBumperPlugin, 'getDuration').and.returnValue(20);
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
state.storage.clear(); state.storage.clear();
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
} }
}); });
it('can emit "edx.video.bumper.loaded" event', function () { it('can emit "edx.video.bumper.loaded" event', function() {
state.el.trigger('ready'); state.el.trigger('ready');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.loaded', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.loaded', {
host_component_id: 'id', host_component_id: 'id',
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
}); });
}); });
it('can emit "edx.video.bumper.played" event', function () { it('can emit "edx.video.bumper.played" event', function() {
state.el.trigger('play'); state.el.trigger('play');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.played', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.played', {
host_component_id: 'id', host_component_id: 'id',
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
}); });
}); });
it('can emit "edx.video.bumper.stopped" event', function () { it('can emit "edx.video.bumper.stopped" event', function() {
state.el.trigger('ended'); state.el.trigger('ended');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.stopped', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.stopped', {
host_component_id: 'id', host_component_id: 'id',
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
}); });
}); });
it('can emit "edx.video.bumper.skipped" event', function () { it('can emit "edx.video.bumper.skipped" event', function() {
state.el.trigger('skip', [false]); state.el.trigger('skip', [false]);
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.skipped', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.skipped', {
host_component_id: 'id', host_component_id: 'id',
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
}); });
}); });
it('can emit "edx.video.bumper.dismissed" event', function () { it('can emit "edx.video.bumper.dismissed" event', function() {
state.el.trigger('skip', [true]); state.el.trigger('skip', [true]);
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.dismissed', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.dismissed', {
host_component_id: 'id', host_component_id: 'id',
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
}); });
}); });
it('can emit "edx.video.bumper.transcript.menu.shown" event', function () { it('can emit "edx.video.bumper.transcript.menu.shown" event', function() {
state.el.trigger('language_menu:show'); state.el.trigger('language_menu:show');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.shown', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.shown', {
host_component_id: 'id', host_component_id: 'id',
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
}); });
}); });
it('can emit "edx.video.bumper.transcript.menu.hidden" event', function () { it('can emit "edx.video.bumper.transcript.menu.hidden" event', function() {
state.el.trigger('language_menu:hide'); state.el.trigger('language_menu:hide');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.hidden', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.menu.hidden', {
host_component_id: 'id', host_component_id: 'id',
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
}); });
}); });
it('can emit "edx.video.bumper.transcript.shown" event', function () { it('can emit "edx.video.bumper.transcript.shown" event', function() {
state.el.trigger('captions:show'); state.el.trigger('captions:show');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.shown', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.shown', {
host_component_id: 'id', host_component_id: 'id',
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
}); });
}); });
it('can emit "edx.video.bumper.transcript.hidden" event', function () { it('can emit "edx.video.bumper.transcript.hidden" event', function() {
state.el.trigger('captions:hide'); state.el.trigger('captions:hide');
expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.hidden', { expect(Logger.log).toHaveBeenCalledWith('edx.video.bumper.transcript.hidden', {
host_component_id: 'id', host_component_id: 'id',
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
}); });
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
var plugin = state.bumperState.videoEventsBumperPlugin; var plugin = state.bumperState.videoEventsBumperPlugin;
spyOn($.fn, 'off').and.callThrough(); spyOn($.fn, 'off').and.callThrough();
plugin.destroy(); plugin.destroy();
...@@ -153,5 +153,4 @@ ...@@ -153,5 +153,4 @@
}); });
}); });
}); });
}).call(this); }).call(this);
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
describe('VideoPlayer Events plugin', function () { describe('VideoPlayer Events plugin', function() {
var state, oldOTBD, Logger = window.Logger; var state, oldOTBD, Logger = window.Logger;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice') .createSpy('onTouchBasedDevice')
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10); spyOn(state.videoEventsPlugin, 'getCurrentTime').and.returnValue(10);
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
state.storage.clear(); state.storage.clear();
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
} }
}); });
it('can emit "load_video" event', function () { it('can emit "load_video" event', function() {
state.el.trigger('ready'); state.el.trigger('ready');
expect(Logger.log).toHaveBeenCalledWith('load_video', { expect(Logger.log).toHaveBeenCalledWith('load_video', {
id: 'id', id: 'id',
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
}); });
}); });
it('can emit "play_video" event when emitPlayVideoEvent is true', function () { it('can emit "play_video" event when emitPlayVideoEvent is true', function() {
state.videoEventsPlugin.emitPlayVideoEvent = true; state.videoEventsPlugin.emitPlayVideoEvent = true;
state.el.trigger('play'); state.el.trigger('play');
expect(Logger.log).toHaveBeenCalledWith('play_video', { expect(Logger.log).toHaveBeenCalledWith('play_video', {
...@@ -42,13 +42,13 @@ ...@@ -42,13 +42,13 @@
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeFalsy(); expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeFalsy();
}); });
it('can not emit "play_video" event when emitPlayVideoEvent is false', function () { it('can not emit "play_video" event when emitPlayVideoEvent is false', function() {
state.videoEventsPlugin.emitPlayVideoEvent = false; state.videoEventsPlugin.emitPlayVideoEvent = false;
state.el.trigger('play'); state.el.trigger('play');
expect(Logger.log).not.toHaveBeenCalled(); expect(Logger.log).not.toHaveBeenCalled();
}); });
it('can emit "pause_video" event', function () { it('can emit "pause_video" event', function() {
state.el.trigger('pause'); state.el.trigger('pause');
expect(Logger.log).toHaveBeenCalledWith('pause_video', { expect(Logger.log).toHaveBeenCalledWith('pause_video', {
id: 'id', id: 'id',
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy(); expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
}); });
it('can emit "speed_change_video" event', function () { it('can emit "speed_change_video" event', function() {
state.el.trigger('speedchange', ['2.0', '1.0']); state.el.trigger('speedchange', ['2.0', '1.0']);
expect(Logger.log).toHaveBeenCalledWith('speed_change_video', { expect(Logger.log).toHaveBeenCalledWith('speed_change_video', {
id: 'id', id: 'id',
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
}); });
}); });
it('can emit "seek_video" event', function () { it('can emit "seek_video" event', function() {
state.el.trigger('seek', [1, 0, 'any']); state.el.trigger('seek', [1, 0, 'any']);
expect(Logger.log).toHaveBeenCalledWith('seek_video', { expect(Logger.log).toHaveBeenCalledWith('seek_video', {
id: 'id', id: 'id',
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
}); });
}); });
it('can emit "stop_video" event', function () { it('can emit "stop_video" event', function() {
state.el.trigger('ended'); state.el.trigger('ended');
expect(Logger.log).toHaveBeenCalledWith('stop_video', { expect(Logger.log).toHaveBeenCalledWith('stop_video', {
id: 'id', id: 'id',
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy(); expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
}); });
it('can emit "skip_video" event', function () { it('can emit "skip_video" event', function() {
state.el.trigger('skip', [false]); state.el.trigger('skip', [false]);
expect(Logger.log).toHaveBeenCalledWith('skip_video', { expect(Logger.log).toHaveBeenCalledWith('skip_video', {
id: 'id', id: 'id',
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
}); });
}); });
it('can emit "do_not_show_again_video" event', function () { it('can emit "do_not_show_again_video" event', function() {
state.el.trigger('skip', [true]); state.el.trigger('skip', [true]);
expect(Logger.log).toHaveBeenCalledWith('do_not_show_again_video', { expect(Logger.log).toHaveBeenCalledWith('do_not_show_again_video', {
id: 'id', id: 'id',
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
}); });
}); });
it('can emit "edx.video.language_menu.shown" event', function () { it('can emit "edx.video.language_menu.shown" event', function() {
state.el.trigger('language_menu:show'); state.el.trigger('language_menu:show');
expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.shown', { expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.shown', {
id: 'id', id: 'id',
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
}); });
}); });
it('can emit "edx.video.language_menu.hidden" event', function () { it('can emit "edx.video.language_menu.hidden" event', function() {
state.el.trigger('language_menu:hide'); state.el.trigger('language_menu:hide');
expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.hidden', { expect(Logger.log).toHaveBeenCalledWith('edx.video.language_menu.hidden', {
id: 'id', id: 'id',
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
}); });
}); });
it('can emit "show_transcript" event', function () { it('can emit "show_transcript" event', function() {
state.el.trigger('transcript:show'); state.el.trigger('transcript:show');
expect(Logger.log).toHaveBeenCalledWith('show_transcript', { expect(Logger.log).toHaveBeenCalledWith('show_transcript', {
id: 'id', id: 'id',
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
}); });
}); });
it('can emit "hide_transcript" event', function () { it('can emit "hide_transcript" event', function() {
state.el.trigger('transcript:hide'); state.el.trigger('transcript:hide');
expect(Logger.log).toHaveBeenCalledWith('hide_transcript', { expect(Logger.log).toHaveBeenCalledWith('hide_transcript', {
id: 'id', id: 'id',
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
}); });
}); });
it('can emit "edx.video.closed_captions.shown" event', function () { it('can emit "edx.video.closed_captions.shown" event', function() {
state.el.trigger('captions:show'); state.el.trigger('captions:show');
expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.shown', { expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.shown', {
id: 'id', id: 'id',
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
}); });
}); });
it('can emit "edx.video.closed_captions.hidden" event', function () { it('can emit "edx.video.closed_captions.hidden" event', function() {
state.el.trigger('captions:hide'); state.el.trigger('captions:hide');
expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.hidden', { expect(Logger.log).toHaveBeenCalledWith('edx.video.closed_captions.hidden', {
id: 'id', id: 'id',
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
}); });
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
var plugin = state.videoEventsPlugin; var plugin = state.videoEventsPlugin;
spyOn($.fn, 'off').and.callThrough(); spyOn($.fn, 'off').and.callThrough();
state.videoEventsPlugin.destroy(); state.videoEventsPlugin.destroy();
...@@ -193,5 +193,4 @@ ...@@ -193,5 +193,4 @@
}); });
}); });
}); });
}).call(this); }).call(this);
(function (undefined) { (function(undefined) {
describe('Video FocusGrabber', function () { describe('Video FocusGrabber', function() {
var state; var state;
beforeEach(function () { beforeEach(function() {
// https://github.com/pivotal/jasmine/issues/184 // https://github.com/pivotal/jasmine/issues/184
// //
// This is a known issue. jQuery animations depend on setTimeout // This is a known issue. jQuery animations depend on setTimeout
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
spyOn(state.focusGrabber, 'enableFocusGrabber').and.callThrough(); spyOn(state.focusGrabber, 'enableFocusGrabber').and.callThrough();
}); });
afterEach(function () { afterEach(function() {
// Turn jQuery animations back on. // Turn jQuery animations back on.
jQuery.fx.off = true; jQuery.fx.off = true;
state.storage.clear(); state.storage.clear();
...@@ -33,22 +33,21 @@ ...@@ -33,22 +33,21 @@
it( it(
'check existence of focus grabber elements and their position', 'check existence of focus grabber elements and their position',
function () { function() {
var firstFGEl = state.el.find('.focus_grabber.first'),
var firstFGEl = state.el.find('.focus_grabber.first'), lastFGEl = state.el.find('.focus_grabber.last'),
lastFGEl = state.el.find('.focus_grabber.last'), tcWrapperEl = state.el.find('.tc-wrapper');
tcWrapperEl = state.el.find('.tc-wrapper');
// Existence check. // Existence check.
expect(firstFGEl.length).toBe(1); expect(firstFGEl.length).toBe(1);
expect(lastFGEl.length).toBe(1); expect(lastFGEl.length).toBe(1);
// Position check. // Position check.
expect(firstFGEl.index() + 1).toBe(tcWrapperEl.index()); expect(firstFGEl.index() + 1).toBe(tcWrapperEl.index());
expect(lastFGEl.index() - 1).toBe(tcWrapperEl.index()); expect(lastFGEl.index() - 1).toBe(tcWrapperEl.index());
}); });
it('from the start, focus grabbers are disabled', function () { it('from the start, focus grabbers are disabled', function() {
expect(state.focusGrabber.elFirst.attr('tabindex')).toBe('-1'); expect(state.focusGrabber.elFirst.attr('tabindex')).toBe('-1');
expect(state.focusGrabber.elLast.attr('tabindex')).toBe('-1'); expect(state.focusGrabber.elLast.attr('tabindex')).toBe('-1');
}); });
...@@ -56,24 +55,22 @@ ...@@ -56,24 +55,22 @@
it( it(
'when first focus grabber is focused "mousemove" event is ' + 'when first focus grabber is focused "mousemove" event is ' +
'triggered, grabbers are disabled', 'triggered, grabbers are disabled',
function () { function() {
state.focusGrabber.elFirst.triggerHandler('focus');
state.focusGrabber.elFirst.triggerHandler('focus'); expect('mousemove').toHaveBeenTriggeredOn(state.el);
expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled();
expect('mousemove').toHaveBeenTriggeredOn(state.el); });
expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled();
});
it( it(
'when last focus grabber is focused "mousemove" event is ' + 'when last focus grabber is focused "mousemove" event is ' +
'triggered, grabbers are disabled', 'triggered, grabbers are disabled',
function () { function() {
state.focusGrabber.elLast.triggerHandler('focus');
state.focusGrabber.elLast.triggerHandler('focus');
expect('mousemove').toHaveBeenTriggeredOn(state.el); expect('mousemove').toHaveBeenTriggeredOn(state.el);
expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled(); expect(state.focusGrabber.disableFocusGrabber).toHaveBeenCalled();
}); });
// Disabled on 18.11.2013 due to flakiness on local dev machine. // Disabled on 18.11.2013 due to flakiness on local dev machine.
// //
...@@ -85,8 +82,8 @@ ...@@ -85,8 +82,8 @@
// //
// TODO: Most likely, focusGrabber will be disabled in the future. This // TODO: Most likely, focusGrabber will be disabled in the future. This
// test could become unneeded in the future. // test could become unneeded in the future.
xit('after controls hide focus grabbers are enabled', function () { xit('after controls hide focus grabbers are enabled', function() {
runs(function () { runs(function() {
// Captions should not be "sticky" for the autohide mechanism // Captions should not be "sticky" for the autohide mechanism
// to work. // to work.
state.videoCaption.hideCaptions(true); state.videoCaption.hideCaptions(true);
...@@ -100,7 +97,7 @@ ...@@ -100,7 +97,7 @@
// that there is clearly no race conditions for our expect below. // that there is clearly no race conditions for our expect below.
waits(state.videoControl.fadeOutTimeout + 100); waits(state.videoControl.fadeOutTimeout + 100);
runs(function () { runs(function() {
expect( expect(
state.focusGrabber.enableFocusGrabber state.focusGrabber.enableFocusGrabber
).toHaveBeenCalled(); ).toHaveBeenCalled();
......
(function () { (function() {
'use strict'; 'use strict';
describe('VideoFullScreen', function () { describe('VideoFullScreen', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
}); });
describe('constructor', function () { describe('constructor', function() {
beforeEach(function () { beforeEach(function() {
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
}); });
it('renders the fullscreen control', function () { it('renders the fullscreen control', function() {
expect($('.add-fullscreen')).toExist(); expect($('.add-fullscreen')).toExist();
expect(state.videoFullScreen.fullScreenState).toBe(false); expect(state.videoFullScreen.fullScreenState).toBe(false);
}); });
it('correctly adds ARIA attributes to fullscreen control', function () { it('correctly adds ARIA attributes to fullscreen control', function() {
var fullScreenControl = $('.add-fullscreen'); var fullScreenControl = $('.add-fullscreen');
expect(fullScreenControl).toHaveAttrs({ expect(fullScreenControl).toHaveAttrs({
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
}); });
}); });
it('correctly triggers the event handler to toggle fullscreen mode', function () { it('correctly triggers the event handler to toggle fullscreen mode', function() {
spyOn(state.videoFullScreen, 'exit'); spyOn(state.videoFullScreen, 'exit');
spyOn(state.videoFullScreen, 'enter'); spyOn(state.videoFullScreen, 'enter');
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
expect(state.videoFullScreen.exit).toHaveBeenCalled(); expect(state.videoFullScreen.exit).toHaveBeenCalled();
}); });
it('correctly updates ARIA on state change', function () { it('correctly updates ARIA on state change', function() {
var fullScreenControl = $('.add-fullscreen'); var fullScreenControl = $('.add-fullscreen');
fullScreenControl.click(); fullScreenControl.click();
expect(fullScreenControl).toHaveAttrs({ expect(fullScreenControl).toHaveAttrs({
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
}); });
}); });
it('correctly can out of fullscreen by pressing esc', function () { it('correctly can out of fullscreen by pressing esc', function() {
spyOn(state.videoCommands, 'execute'); spyOn(state.videoCommands, 'execute');
var esc = $.Event('keyup'); var esc = $.Event('keyup');
esc.keyCode = 27; esc.keyCode = 27;
...@@ -68,23 +68,23 @@ ...@@ -68,23 +68,23 @@
expect(state.videoCommands.execute).toHaveBeenCalledWith('toggleFullScreen'); expect(state.videoCommands.execute).toHaveBeenCalledWith('toggleFullScreen');
}); });
it('can update video dimensions on state change', function () { it('can update video dimensions on state change', function() {
state.el.trigger('fullscreen', [true]); state.el.trigger('fullscreen', [true]);
expect(state.resizer.setMode).toHaveBeenCalledWith('both'); expect(state.resizer.setMode).toHaveBeenCalledWith('both');
state.el.trigger('fullscreen', [false]); state.el.trigger('fullscreen', [false]);
expect(state.resizer.setMode).toHaveBeenCalledWith('width'); expect(state.resizer.setMode).toHaveBeenCalledWith('width');
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.videoFullScreen.destroy(); state.videoFullScreen.destroy();
expect($('.add-fullscreen')).not.toExist(); expect($('.add-fullscreen')).not.toExist();
expect(state.videoFullScreen).toBeUndefined(); expect(state.videoFullScreen).toBeUndefined();
}); });
}); });
it('Controls height is actual on switch to fullscreen', function () { it('Controls height is actual on switch to fullscreen', function() {
spyOn($.fn, 'height').and.callFake(function (val) { spyOn($.fn, 'height').and.callFake(function(val) {
return _.isUndefined(val) ? 100: this; return _.isUndefined(val) ? 100 : this;
}); });
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
......
(function () { (function() {
'use strict'; 'use strict';
describe('VideoPlayPauseControl', function () { describe('VideoPlayPauseControl', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
...@@ -12,31 +12,31 @@ ...@@ -12,31 +12,31 @@
spyOn(state.videoSaveStatePlugin, 'saveState'); spyOn(state.videoSaveStatePlugin, 'saveState');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
}); });
it('can render the control', function () { it('can render the control', function() {
expect($('.video_control.play')).toExist(); expect($('.video_control.play')).toExist();
}); });
it('add ARIA attributes to play control', function () { it('add ARIA attributes to play control', function() {
expect($('.video_control.play')).toHaveAttrs({ expect($('.video_control.play')).toHaveAttrs({
'aria-disabled': 'false' 'aria-disabled': 'false'
}); });
}); });
it('can update ARIA state on play', function () { it('can update ARIA state on play', function() {
state.el.trigger('play'); state.el.trigger('play');
expect($('.video_control.pause')).toHaveAttrs({ expect($('.video_control.pause')).toHaveAttrs({
'aria-disabled': 'false' 'aria-disabled': 'false'
}); });
}); });
it('can update ARIA state on video ends', function () { it('can update ARIA state on video ends', function() {
state.el.trigger('play'); state.el.trigger('play');
state.el.trigger('ended'); state.el.trigger('ended');
expect($('.video_control.play')).toHaveAttrs({ expect($('.video_control.play')).toHaveAttrs({
...@@ -44,17 +44,17 @@ ...@@ -44,17 +44,17 @@
}); });
}); });
it('can update state on pause', function () { it('can update state on pause', function() {
state.el.trigger('pause'); state.el.trigger('pause');
expect(state.videoSaveStatePlugin.saveState).toHaveBeenCalledWith(true); expect(state.videoSaveStatePlugin.saveState).toHaveBeenCalledWith(true);
}); });
it('can start video playing on click', function () { it('can start video playing on click', function() {
$('.video_control.play').click(); $('.video_control.play').click();
expect(state.videoCommands.execute).toHaveBeenCalledWith('togglePlayback'); expect(state.videoCommands.execute).toHaveBeenCalledWith('togglePlayback');
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.videoPlayPauseControl.destroy(); state.videoPlayPauseControl.destroy();
expect(state.videoPlayPauseControl).toBeUndefined(); expect(state.videoPlayPauseControl).toBeUndefined();
}); });
......
(function () { (function() {
'use strict'; 'use strict';
describe('VideoPlayPlaceholder', function () { describe('VideoPlayPlaceholder', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(['iPad']); .createSpy('onTouchBasedDevice').and.returnValue(['iPad']);
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
spyOn(state.videoCommands, 'execute'); spyOn(state.videoCommands, 'execute');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
state.videoPlayer.destroy(); state.videoPlayer.destroy();
...@@ -39,12 +39,12 @@ ...@@ -39,12 +39,12 @@
} }
]; ];
beforeEach(function () { beforeEach(function() {
jasmine.stubRequests(); jasmine.stubRequests();
spyOn(window.YT, 'Player').and.callThrough(); spyOn(window.YT, 'Player').and.callThrough();
}); });
it ('works correctly on calling proper methods', function () { it('works correctly on calling proper methods', function() {
var btnPlay; var btnPlay;
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
...@@ -67,14 +67,14 @@ ...@@ -67,14 +67,14 @@
}); });
}); });
$.each(cases, function (index, data) { $.each(cases, function(index, data) {
var message = [ var message = [
(data.isShown) ? 'is' : 'is not', (data.isShown) ? 'is' : 'is not',
' shown on', ' shown on',
data.name data.name
].join(''); ].join('');
it(message, function () { it(message, function() {
var btnPlay; var btnPlay;
window.onTouchBasedDevice.and.returnValue(data.isTouch); window.onTouchBasedDevice.and.returnValue(data.isTouch);
...@@ -89,61 +89,61 @@ ...@@ -89,61 +89,61 @@
}); });
}); });
$.each(['iPad', 'Android'], function (index, device) { $.each(['iPad', 'Android'], function(index, device) {
it( it(
'is shown on paused video on ' + device + 'is shown on paused video on ' + device +
' in HTML5 player', ' in HTML5 player',
function () function()
{ {
var btnPlay; var btnPlay;
window.onTouchBasedDevice.and.returnValue([device]); window.onTouchBasedDevice.and.returnValue([device]);
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
btnPlay = state.el.find('.btn-play'); btnPlay = state.el.find('.btn-play');
state.el.trigger('play'); state.el.trigger('play');
state.el.trigger('pause'); state.el.trigger('pause');
expect(btnPlay).not.toHaveClass('is-hidden'); expect(btnPlay).not.toHaveClass('is-hidden');
}); });
it( it(
'is hidden on playing video on ' + device + 'is hidden on playing video on ' + device +
' in HTML5 player', ' in HTML5 player',
function () function()
{ {
var btnPlay; var btnPlay;
window.onTouchBasedDevice.and.returnValue([device]); window.onTouchBasedDevice.and.returnValue([device]);
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
btnPlay = state.el.find('.btn-play'); btnPlay = state.el.find('.btn-play');
state.el.trigger('play'); state.el.trigger('play');
expect(btnPlay).toHaveClass('is-hidden'); expect(btnPlay).toHaveClass('is-hidden');
}); });
it( it(
'is hidden on paused video on ' + device + 'is hidden on paused video on ' + device +
' in YouTube player', ' in YouTube player',
function () function()
{ {
var btnPlay; var btnPlay;
window.onTouchBasedDevice.and.returnValue([device]); window.onTouchBasedDevice.and.returnValue([device]);
state = jasmine.initializePlayerYouTube(); state = jasmine.initializePlayerYouTube();
btnPlay = state.el.find('.btn-play'); btnPlay = state.el.find('.btn-play');
state.el.trigger('play'); state.el.trigger('play');
state.el.trigger('pause'); state.el.trigger('pause');
expect(btnPlay).toHaveClass('is-hidden'); expect(btnPlay).toHaveClass('is-hidden');
}); });
}); });
it('starts play the video on click', function () { it('starts play the video on click', function() {
$('.btn-play').click(); $('.btn-play').click();
expect(state.videoCommands.execute).toHaveBeenCalledWith('play'); expect(state.videoCommands.execute).toHaveBeenCalledWith('play');
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.videoPlayPlaceholder.destroy(); state.videoPlayPlaceholder.destroy();
expect(state.videoPlayPlaceholder).toBeUndefined(); expect(state.videoPlayPlaceholder).toBeUndefined();
}); });
......
(function () { (function() {
'use strict'; 'use strict';
describe('VideoPlaySkipControl', function () { describe('VideoPlaySkipControl', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
spyOn(state.bumperState.videoCommands, 'execute'); spyOn(state.bumperState.videoCommands, 'execute');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
if (state.bumperState && state.bumperState.videoPlayer) { if (state.bumperState && state.bumperState.videoPlayer) {
...@@ -24,29 +24,29 @@ ...@@ -24,29 +24,29 @@
} }
}); });
it('can render the control', function () { it('can render the control', function() {
expect($('.video_control.play')).toBeInDOM(); expect($('.video_control.play')).toBeInDOM();
}); });
it('can update state on play', function () { it('can update state on play', function() {
state.el.trigger('play'); state.el.trigger('play');
expect($('.video_control.play')).not.toBeInDOM(); expect($('.video_control.play')).not.toBeInDOM();
expect($('.video_control.skip')).toBeInDOM(); expect($('.video_control.skip')).toBeInDOM();
}); });
it('can start video playing on click', function () { it('can start video playing on click', function() {
$('.video_control.play').click(); $('.video_control.play').click();
expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('play'); expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('play');
}); });
it('can skip the video on click', function () { it('can skip the video on click', function() {
state.el.trigger('play'); state.el.trigger('play');
spyOn(state.bumperState.videoPlayer, 'isPlaying').and.returnValue(true); spyOn(state.bumperState.videoPlayer, 'isPlaying').and.returnValue(true);
$('.video_control.skip').first().click(); $('.video_control.skip').first().click();
expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('skip'); expect(state.bumperState.videoCommands.execute).toHaveBeenCalledWith('skip');
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
var plugin = state.bumperState.videoPlaySkipControl, var plugin = state.bumperState.videoPlaySkipControl,
el = plugin.el; el = plugin.el;
spyOn($.fn, 'off').and.callThrough(); spyOn($.fn, 'off').and.callThrough();
......
(function (WAIT_TIMEOUT) { (function(WAIT_TIMEOUT) {
'use strict'; 'use strict';
describe('VideoPoster', function () { describe('VideoPoster', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
state = jasmine.initializePlayer('video_with_bumper.html'); state = jasmine.initializePlayer('video_with_bumper.html');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
if (state.bumperState && state.bumperState.videoPlayer) { if (state.bumperState && state.bumperState.videoPlayer) {
...@@ -22,19 +22,19 @@ ...@@ -22,19 +22,19 @@
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
}); });
it('can render the poster', function () { it('can render the poster', function() {
expect($('.poster')).toExist(); expect($('.poster')).toExist();
expect($('.btn-play')).toExist(); expect($('.btn-play')).toExist();
}); });
it('can start playing the video on click', function (done) { it('can start playing the video on click', function(done) {
$('.btn-play').click(); $('.btn-play').click();
jasmine.waitUntil(function() { jasmine.waitUntil(function() {
return state.el.hasClass('is-playing'); return state.el.hasClass('is-playing');
}).done(done); }).done(done);
}); });
it('destroy itself on "play" event', function () { it('destroy itself on "play" event', function() {
$('.btn-play').click(); $('.btn-play').click();
expect($('.poster')).not.toExist(); expect($('.poster')).not.toExist();
}); });
......
(function (undefined) { (function(undefined) {
describe('VideoQualityControl', function () { describe('VideoQualityControl', function() {
var state, qualityControl, videoPlayer, player; var state, qualityControl, videoPlayer, player;
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
if (state.storage) { if (state.storage) {
state.storage.clear(); state.storage.clear();
...@@ -10,34 +10,34 @@ ...@@ -10,34 +10,34 @@
state.videoPlayer.destroy(); state.videoPlayer.destroy();
}); });
describe('constructor, YouTube mode', function () { describe('constructor, YouTube mode', function() {
beforeEach(function () { beforeEach(function() {
state = jasmine.initializePlayerYouTube(); state = jasmine.initializePlayerYouTube();
qualityControl = state.videoQualityControl; qualityControl = state.videoQualityControl;
videoPlayer = state.videoPlayer; videoPlayer = state.videoPlayer;
player = videoPlayer.player; player = videoPlayer.player;
// Define empty methods in YouTube stub // Define empty methods in YouTube stub
player.quality = 'large'; player.quality = 'large';
player.setPlaybackQuality.and.callFake(function (quality){ player.setPlaybackQuality.and.callFake(function(quality) {
player.quality = quality; player.quality = quality;
}); });
}); });
it('contains the quality control and is initially hidden', it('contains the quality control and is initially hidden',
function () { function() {
expect(qualityControl.el).toHaveClass( expect(qualityControl.el).toHaveClass(
'quality-control is-hidden' 'quality-control is-hidden'
); );
}); });
it('add ARIA attributes to quality control', function () { it('add ARIA attributes to quality control', function() {
expect(qualityControl.el).toHaveAttrs({ expect(qualityControl.el).toHaveAttrs({
'aria-disabled': 'false' 'aria-disabled': 'false'
}); });
}); });
it('bind the quality control', function () { it('bind the quality control', function() {
expect(qualityControl.el).toHandleWith('click', expect(qualityControl.el).toHandleWith('click',
qualityControl.toggleQuality qualityControl.toggleQuality
); );
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
expect(state.el).toHandle('play'); expect(state.el).toHandle('play');
}); });
it('calls fetchAvailableQualities only once', function () { it('calls fetchAvailableQualities only once', function() {
expect(player.getAvailableQualityLevels.calls.count()) expect(player.getAvailableQualityLevels.calls.count())
.toEqual(0); .toEqual(0);
...@@ -56,30 +56,30 @@ ...@@ -56,30 +56,30 @@
.toEqual(1); .toEqual(1);
}); });
it('initializes with a quality equal to large', function () { it('initializes with a quality equal to large', function() {
videoPlayer.onPlay(); videoPlayer.onPlay();
expect(player.setPlaybackQuality).toHaveBeenCalledWith('large'); expect(player.setPlaybackQuality).toHaveBeenCalledWith('large');
}); });
it('shows the quality control on play if HD is available', it('shows the quality control on play if HD is available',
function () { function() {
videoPlayer.onPlay(); videoPlayer.onPlay();
expect(qualityControl.el).not.toHaveClass('is-hidden'); expect(qualityControl.el).not.toHaveClass('is-hidden');
}); });
it('leaves quality control hidden on play if HD is not available', it('leaves quality control hidden on play if HD is not available',
function () { function() {
player.getAvailableQualityLevels.and.returnValue( player.getAvailableQualityLevels.and.returnValue(
['large', 'medium', 'small'] ['large', 'medium', 'small']
); );
videoPlayer.onPlay(); videoPlayer.onPlay();
expect(qualityControl.el).toHaveClass('is-hidden'); expect(qualityControl.el).toHaveClass('is-hidden');
}); });
it('switch to HD if it is available', function () { it('switch to HD if it is available', function() {
videoPlayer.onPlay(); videoPlayer.onPlay();
qualityControl.quality = 'large'; qualityControl.quality = 'large';
...@@ -93,27 +93,27 @@ ...@@ -93,27 +93,27 @@
}); });
it('quality control is active if HD is available', it('quality control is active if HD is available',
function () { function() {
player.getAvailableQualityLevels.and.returnValue( player.getAvailableQualityLevels.and.returnValue(
['highres', 'hd1080', 'hd720'] ['highres', 'hd1080', 'hd720']
); );
qualityControl.quality = 'highres'; qualityControl.quality = 'highres';
videoPlayer.onPlay(); videoPlayer.onPlay();
expect(qualityControl.el).toHaveClass('active'); expect(qualityControl.el).toHaveClass('active');
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.videoQualityControl.destroy(); state.videoQualityControl.destroy();
expect(state.videoQualityControl).toBeUndefined(); expect(state.videoQualityControl).toBeUndefined();
expect($('.quality-control')).not.toExist(); expect($('.quality-control')).not.toExist();
}); });
}); });
describe('constructor, HTML5 mode', function () { describe('constructor, HTML5 mode', function() {
it('does not contain the quality control', function () { it('does not contain the quality control', function() {
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
expect(state.el.find('.quality-control').length).toBe(0); expect(state.el.find('.quality-control').length).toBe(0);
}); });
......
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
describe('VideoPlayer Save State plugin', function () { describe('VideoPlayer Save State plugin', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice') .createSpy('onTouchBasedDevice')
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
spyOn(state.storage, 'setItem'); spyOn(state.storage, 'setItem');
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
state.storage.clear(); state.storage.clear();
...@@ -25,7 +24,7 @@ ...@@ -25,7 +24,7 @@
} }
}); });
describe('saveState function', function () { describe('saveState function', function() {
var videoPlayerCurrentTime, newCurrentTime, speed; var videoPlayerCurrentTime, newCurrentTime, speed;
// We make sure that `currentTime` is a float. We need to test // We make sure that `currentTime` is a float. We need to test
...@@ -41,12 +40,12 @@ ...@@ -41,12 +40,12 @@
newCurrentTime = 5.4; newCurrentTime = 5.4;
speed = '0.75'; speed = '0.75';
beforeEach(function () { beforeEach(function() {
state.videoPlayer.currentTime = videoPlayerCurrentTime; state.videoPlayer.currentTime = videoPlayerCurrentTime;
spyOn(window.Time, 'formatFull').and.callThrough(); spyOn(window.Time, 'formatFull').and.callThrough();
}); });
it('data is not an object, async is true', function () { it('data is not an object, async is true', function() {
itSpec({ itSpec({
asyncVal: true, asyncVal: true,
speedVal: undefined, speedVal: undefined,
...@@ -58,7 +57,7 @@ ...@@ -58,7 +57,7 @@
}); });
}); });
it('data contains speed, async is false', function () { it('data contains speed, async is false', function() {
itSpec({ itSpec({
asyncVal: false, asyncVal: false,
speedVal: speed, speedVal: speed,
...@@ -72,7 +71,7 @@ ...@@ -72,7 +71,7 @@
}); });
}); });
it('data contains float position, async is true', function () { it('data contains float position, async is true', function() {
itSpec({ itSpec({
asyncVal: true, asyncVal: true,
speedVal: undefined, speedVal: undefined,
...@@ -86,7 +85,7 @@ ...@@ -86,7 +85,7 @@
}); });
}); });
it('data contains speed and rounded position, async is false', function () { it('data contains speed and rounded position, async is false', function() {
itSpec({ itSpec({
asyncVal: false, asyncVal: false,
speedVal: speed, speedVal: speed,
...@@ -102,7 +101,7 @@ ...@@ -102,7 +101,7 @@
}); });
}); });
it('data contains empty object, async is true', function () { it('data contains empty object, async is true', function() {
itSpec({ itSpec({
asyncVal: true, asyncVal: true,
speedVal: undefined, speedVal: undefined,
...@@ -112,7 +111,7 @@ ...@@ -112,7 +111,7 @@
}); });
}); });
it('data contains position 0, async is true', function () { it('data contains position 0, async is true', function() {
itSpec({ itSpec({
asyncVal: true, asyncVal: true,
speedVal: undefined, speedVal: undefined,
...@@ -127,11 +126,11 @@ ...@@ -127,11 +126,11 @@
}); });
function itSpec(value) { function itSpec(value) {
var asyncVal = value.asyncVal, var asyncVal = value.asyncVal,
speedVal = value.speedVal, speedVal = value.speedVal,
positionVal = value.positionVal, positionVal = value.positionVal,
data = value.data, data = value.data,
ajaxData = value.ajaxData; ajaxData = value.ajaxData;
state.videoSaveStatePlugin.saveState(asyncVal, data); state.videoSaveStatePlugin.saveState(asyncVal, data);
...@@ -162,7 +161,7 @@ ...@@ -162,7 +161,7 @@
} }
}); });
it('can save state on speed change', function () { it('can save state on speed change', function() {
state.el.trigger('speedchange', ['2.0']); state.el.trigger('speedchange', ['2.0']);
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: state.config.saveStateUrl, url: state.config.saveStateUrl,
...@@ -173,7 +172,7 @@ ...@@ -173,7 +172,7 @@
}); });
}); });
it('can save state on page unload', function () { it('can save state on page unload', function() {
$.ajax.calls.reset(); $.ajax.calls.reset();
state.videoSaveStatePlugin.onUnload(); state.videoSaveStatePlugin.onUnload();
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
...@@ -185,7 +184,7 @@ ...@@ -185,7 +184,7 @@
}); });
}); });
it('can save state on pause', function () { it('can save state on pause', function() {
state.el.trigger('pause'); state.el.trigger('pause');
expect($.ajax).toHaveBeenCalledWith({ expect($.ajax).toHaveBeenCalledWith({
url: state.config.saveStateUrl, url: state.config.saveStateUrl,
...@@ -196,12 +195,12 @@ ...@@ -196,12 +195,12 @@
}); });
}); });
it('can save state on language change', function () { it('can save state on language change', function() {
state.el.trigger('language_menu:change', ['ua']); state.el.trigger('language_menu:change', ['ua']);
expect(state.storage.setItem).toHaveBeenCalledWith('language', 'ua'); expect(state.storage.setItem).toHaveBeenCalledWith('language', 'ua');
}); });
it('can save youtube availability', function () { it('can save youtube availability', function() {
$.ajax.calls.reset(); $.ajax.calls.reset();
// Test the cases where we shouldn't send anything at all -- client // Test the cases where we shouldn't send anything at all -- client
...@@ -236,7 +235,7 @@ ...@@ -236,7 +235,7 @@
}); });
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
var plugin = state.videoSaveStatePlugin; var plugin = state.videoSaveStatePlugin;
spyOn($.fn, 'off').and.callThrough(); spyOn($.fn, 'off').and.callThrough();
state.videoSaveStatePlugin.destroy(); state.videoSaveStatePlugin.destroy();
...@@ -252,5 +251,4 @@ ...@@ -252,5 +251,4 @@
expect($.fn.off).toHaveBeenCalledWith('unload', plugin.onUnload); expect($.fn.off).toHaveBeenCalledWith('unload', plugin.onUnload);
}); });
}); });
}).call(this); }).call(this);
(function () { (function() {
'use strict'; 'use strict';
describe('VideoSkipControl', function () { describe('VideoSkipControl', function() {
var state, oldOTBD; var state, oldOTBD;
beforeEach(function () { beforeEach(function() {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
window.onTouchBasedDevice = jasmine window.onTouchBasedDevice = jasmine
.createSpy('onTouchBasedDevice').and.returnValue(null); .createSpy('onTouchBasedDevice').and.returnValue(null);
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
spyOn(state.bumperState.videoCommands, 'execute').and.callThrough(); spyOn(state.bumperState.videoCommands, 'execute').and.callThrough();
}); });
afterEach(function () { afterEach(function() {
$('source').remove(); $('source').remove();
state.storage.clear(); state.storage.clear();
if (state.bumperState && state.bumperState.videoPlayer) { if (state.bumperState && state.bumperState.videoPlayer) {
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
window.onTouchBasedDevice = oldOTBD; window.onTouchBasedDevice = oldOTBD;
}); });
it('can render the control when video starts playing', function () { it('can render the control when video starts playing', function() {
expect($('.skip-control')).not.toExist(); expect($('.skip-control')).not.toExist();
state.el.trigger('play'); state.el.trigger('play');
expect($('.skip-control')).toExist(); expect($('.skip-control')).toExist();
}); });
it('can skip the video on click', function () { it('can skip the video on click', function() {
spyOn(state.bumperState.videoBumper, 'skipAndDoNotShowAgain'); spyOn(state.bumperState.videoBumper, 'skipAndDoNotShowAgain');
state.el.trigger('play'); state.el.trigger('play');
$('.skip-control').click(); $('.skip-control').click();
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
expect(state.bumperState.videoBumper.skipAndDoNotShowAgain).toHaveBeenCalled(); expect(state.bumperState.videoBumper.skipAndDoNotShowAgain).toHaveBeenCalled();
}); });
it('can destroy itself', function () { it('can destroy itself', function() {
state.bumperState.videoPlaySkipControl.destroy(); state.bumperState.videoPlaySkipControl.destroy();
expect(state.bumperState.videoPlaySkipControl).toBeUndefined(); expect(state.bumperState.videoPlaySkipControl).toBeUndefined();
}); });
......
(function (requirejs, require, define, undefined) { (function(requirejs, require, define, undefined) {
require( require(
['video/00_video_storage.js'], ['video/00_video_storage.js'],
function (VideoStorage) { function(VideoStorage) {
describe('VideoStorage', function () { describe('VideoStorage', function() {
var namespace = 'test_storage', var namespace = 'test_storage',
id = 'video_id'; id = 'video_id';
afterEach(function () { afterEach(function() {
VideoStorage(namespace, id).clear(); VideoStorage(namespace, id).clear();
}); });
describe('initialize', function () { describe('initialize', function() {
it('with namespace and id', function () { it('with namespace and id', function() {
var storage = VideoStorage(namespace, id); var storage = VideoStorage(namespace, id);
expect(window[namespace]).toBeDefined(); expect(window[namespace]).toBeDefined();
expect(window[namespace][id]).toBeDefined(); expect(window[namespace][id]).toBeDefined();
}); });
it('without namespace and id', function () { it('without namespace and id', function() {
spyOn(Number.prototype, 'toString').and.returnValue('0.abcdedg'); spyOn(Number.prototype, 'toString').and.returnValue('0.abcdedg');
var storage = VideoStorage(); var storage = VideoStorage();
...@@ -27,10 +27,10 @@ function (VideoStorage) { ...@@ -27,10 +27,10 @@ function (VideoStorage) {
}); });
}); });
describe('methods: ', function () { describe('methods: ', function() {
var data, storage; var data, storage;
beforeEach(function () { beforeEach(function() {
data = { data = {
item_2: 'value_2' item_2: 'value_2'
}; };
...@@ -42,7 +42,7 @@ function (VideoStorage) { ...@@ -42,7 +42,7 @@ function (VideoStorage) {
storage = VideoStorage(namespace, id); storage = VideoStorage(namespace, id);
}); });
it('setItem', function () { it('setItem', function() {
var expected = $.extend(true, {}, data, {item_4: 'value_4'}); var expected = $.extend(true, {}, data, {item_4: 'value_4'});
expected[id]['item_3'] = 'value_3'; expected[id]['item_3'] = 'value_3';
...@@ -51,7 +51,7 @@ function (VideoStorage) { ...@@ -51,7 +51,7 @@ function (VideoStorage) {
expect(window[namespace]).toEqual(expected); expect(window[namespace]).toEqual(expected);
}); });
it('getItem', function () { it('getItem', function() {
var data = window[namespace], var data = window[namespace],
getItem = storage.getItem; getItem = storage.getItem;
...@@ -60,7 +60,7 @@ function (VideoStorage) { ...@@ -60,7 +60,7 @@ function (VideoStorage) {
expect(getItem('item_3')).toBeUndefined(); expect(getItem('item_3')).toBeUndefined();
}); });
it('removeItem', function () { it('removeItem', function() {
var data = window[namespace], var data = window[namespace],
removeItem = storage.removeItem; removeItem = storage.removeItem;
...@@ -70,7 +70,7 @@ function (VideoStorage) { ...@@ -70,7 +70,7 @@ function (VideoStorage) {
expect(data['item_2']).toBeUndefined(); expect(data['item_2']).toBeUndefined();
}); });
it('clear', function () { it('clear', function() {
var expected = {}; var expected = {};
expected[id] = {}; expected[id] = {};
......
(function () { (function() {
'use strict'; 'use strict';
describe('XBlockToXModuleShim', function () { describe('XBlockToXModuleShim', function() {
describe('definition', function () { describe('definition', function() {
it('XBlockToXModuleShim is defined, and is a function', function () { it('XBlockToXModuleShim is defined, and is a function', function() {
expect($.isFunction(XBlockToXModuleShim)).toBe(true); expect($.isFunction(XBlockToXModuleShim)).toBe(true);
}); });
}); });
describe('implementation', function () { describe('implementation', function() {
var el, var el,
videoModule = { videoModule = {
'module': 'video_module' 'module': 'video_module'
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
removeNone, removeNone,
removeVideo; removeVideo;
beforeEach(function () { beforeEach(function() {
el = $('<div />'); el = $('<div />');
if (window.None) { if (window.None) {
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
spyOnEvent($(document), 'XModule.loaded.display'); spyOnEvent($(document), 'XModule.loaded.display');
}); });
afterEach(function () { afterEach(function() {
el = null; el = null;
if (removeNone) { if (removeNone) {
...@@ -58,14 +58,14 @@ ...@@ -58,14 +58,14 @@
} }
}); });
it('if element module is of type None, nothing happens', function () { it('if element module is of type None, nothing happens', function() {
el.data('type', 'None'); el.data('type', 'None');
expect(XBlockToXModuleShim(null, el)).toBeUndefined(); expect(XBlockToXModuleShim(null, el)).toBeUndefined();
expect(window.None).not.toHaveBeenCalled(); expect(window.None).not.toHaveBeenCalled();
}); });
it('if element module is of type Video, Video module constructor is called', function () { it('if element module is of type Video, Video module constructor is called', function() {
el.data('type', 'Video'); el.data('type', 'Video');
expect(XBlockToXModuleShim(null, el)).toEqual(videoModule); expect(XBlockToXModuleShim(null, el)).toEqual(videoModule);
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
expect('XModule.loaded.display').not.toHaveBeenTriggeredOn(document); expect('XModule.loaded.display').not.toHaveBeenTriggeredOn(document);
}); });
it('if element has class "xmodule_edit"', function () { it('if element has class "xmodule_edit"', function() {
el.data('type', 'Video') el.data('type', 'Video')
.addClass('xmodule_edit'); .addClass('xmodule_edit');
XBlockToXModuleShim(null, el); XBlockToXModuleShim(null, el);
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
expect('XModule.loaded.display').not.toHaveBeenTriggeredOn($(document)); expect('XModule.loaded.display').not.toHaveBeenTriggeredOn($(document));
}); });
it('if element has class "xmodule_display"', function () { it('if element has class "xmodule_display"', function() {
el.data('type', 'Video') el.data('type', 'Video')
.addClass('xmodule_display'); .addClass('xmodule_display');
XBlockToXModuleShim(null, el); XBlockToXModuleShim(null, el);
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
expect(displayCallback).toHaveBeenCalledWith(jasmine.any($.Event), el, videoModule); expect(displayCallback).toHaveBeenCalledWith(jasmine.any($.Event), el, videoModule);
}); });
it('if element has classes "xmodule_edit", and "xmodule_display"', function () { it('if element has classes "xmodule_edit", and "xmodule_display"', function() {
el.data('type', 'Video') el.data('type', 'Video')
.addClass('xmodule_edit') .addClass('xmodule_edit')
.addClass('xmodule_display'); .addClass('xmodule_display');
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
expect('XModule.loaded.display').toHaveBeenTriggeredOn($(document)); expect('XModule.loaded.display').toHaveBeenTriggeredOn($(document));
}); });
it('element is of an unknown Module type, console.error() is called if it is defined', function () { it('element is of an unknown Module type, console.error() is called if it is defined', function() {
var oldConsole = window.console; var oldConsole = window.console;
if (window.console && window.console.error) { if (window.console && window.console.error) {
...@@ -121,9 +121,9 @@ ...@@ -121,9 +121,9 @@
window.console = oldConsole; window.console = oldConsole;
}); });
it('element is of an unknown Module type, JavaScript throws if console.error() is not defined', function () { it('element is of an unknown Module type, JavaScript throws if console.error() is not defined', function() {
var oldConsole = window.console, var oldConsole = window.console,
testFunction = function () { testFunction = function() {
return XBlockToXModuleShim(null, el); return XBlockToXModuleShim(null, el);
}; };
...@@ -140,55 +140,55 @@ ...@@ -140,55 +140,55 @@
}); });
}); });
describe('XModule.Descriptor', function () { describe('XModule.Descriptor', function() {
describe('definition', function () { describe('definition', function() {
it('XModule is defined, and is a plain object', function () { it('XModule is defined, and is a plain object', function() {
expect($.isPlainObject(XModule)).toBe(true); expect($.isPlainObject(XModule)).toBe(true);
}); });
it('XModule.Descriptor is defined, and is a function', function () { it('XModule.Descriptor is defined, and is a function', function() {
expect($.isFunction(XModule.Descriptor)).toBe(true); expect($.isFunction(XModule.Descriptor)).toBe(true);
}); });
it('XModule.Descriptor has a complete prototype', function () { it('XModule.Descriptor has a complete prototype', function() {
expect($.isFunction(XModule.Descriptor.prototype.onUpdate)).toBe(true); expect($.isFunction(XModule.Descriptor.prototype.onUpdate)).toBe(true);
expect($.isFunction(XModule.Descriptor.prototype.update)).toBe(true); expect($.isFunction(XModule.Descriptor.prototype.update)).toBe(true);
expect($.isFunction(XModule.Descriptor.prototype.save)).toBe(true); expect($.isFunction(XModule.Descriptor.prototype.save)).toBe(true);
}); });
}); });
describe('implementation', function () { describe('implementation', function() {
var el, obj, callback, length; var el, obj, callback, length;
// This is a dummy callback. // This is a dummy callback.
callback = function () { callback = function() {
var x = 1; var x = 1;
return x + 1; return x + 1;
}; };
beforeEach(function () { beforeEach(function() {
el = 'dummy object'; el = 'dummy object';
obj = new XModule.Descriptor(el); obj = new XModule.Descriptor(el);
spyOn(obj, 'save').and.callThrough(); spyOn(obj, 'save').and.callThrough();
}); });
afterEach(function () { afterEach(function() {
el = null; el = null;
obj = null; obj = null;
length = undefined; length = undefined;
}); });
it('Descriptor is a proper constructor function', function () { it('Descriptor is a proper constructor function', function() {
expect(obj.hasOwnProperty('element')).toBe(true); expect(obj.hasOwnProperty('element')).toBe(true);
expect(obj.element).toBe(el); expect(obj.element).toBe(el);
expect(obj.hasOwnProperty('update')).toBe(true); expect(obj.hasOwnProperty('update')).toBe(true);
}); });
it('Descriptor.onUpdate called for the first time', function () { it('Descriptor.onUpdate called for the first time', function() {
expect(obj.hasOwnProperty('callbacks')).toBe(false); expect(obj.hasOwnProperty('callbacks')).toBe(false);
obj.onUpdate(callback); obj.onUpdate(callback);
expect(obj.hasOwnProperty('callbacks')).toBe(true); expect(obj.hasOwnProperty('callbacks')).toBe(true);
...@@ -199,7 +199,7 @@ ...@@ -199,7 +199,7 @@
expect(obj.callbacks[length - 1]).toBe(callback); expect(obj.callbacks[length - 1]).toBe(callback);
}); });
it('Descriptor.onUpdate called for Nth time', function () { it('Descriptor.onUpdate called for Nth time', function() {
// In this test it doesn't matter what obj.callbacks // In this test it doesn't matter what obj.callbacks
// consists of. // consists of.
obj.callbacks = ['test1', 'test2', 'test3']; obj.callbacks = ['test1', 'test2', 'test3'];
...@@ -211,13 +211,13 @@ ...@@ -211,13 +211,13 @@
expect(obj.callbacks[length - 1]).toBe(callback); expect(obj.callbacks[length - 1]).toBe(callback);
}); });
it('Descriptor.save returns a blank object', function () { it('Descriptor.save returns a blank object', function() {
// NOTE: In the future the implementation of .save() // NOTE: In the future the implementation of .save()
// method may change! // method may change!
expect(obj.save()).toEqual({}); expect(obj.save()).toEqual({});
}); });
it('Descriptor.update triggers all callbacks with whatever .save() returns', function () { it('Descriptor.update triggers all callbacks with whatever .save() returns', function() {
var callback1 = jasmine.createSpy('callback1'), var callback1 = jasmine.createSpy('callback1'),
callback2 = jasmine.createSpy('callback2'), callback2 = jasmine.createSpy('callback2'),
testValue = 'test 123'; testValue = 'test 123';
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* ~ Chinese Proverb * ~ Chinese Proverb
*/ */
window.ImageInput = (function ($, undefined) { window.ImageInput = (function($, undefined) {
var ImageInput = ImageInputConstructor; var ImageInput = ImageInputConstructor;
ImageInput.prototype = { ImageInput.prototype = {
......
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
// [module Collapsible] // [module Collapsible]
...@@ -35,14 +35,14 @@ ...@@ -35,14 +35,14 @@
short_custom = el.find('.shortform-custom'); short_custom = el.find('.shortform-custom');
// Set up each one individually. // Set up each one individually.
short_custom.each(function (index, elt) { short_custom.each(function(index, elt) {
var close_text, open_text; var close_text, open_text;
open_text = $(elt).data('open-text'); open_text = $(elt).data('open-text');
close_text = $(elt).data('close-text'); close_text = $(elt).data('close-text');
$(elt).append("<a href='#' class='full-custom'>" + open_text + "</a>"); $(elt).append("<a href='#' class='full-custom'>" + open_text + '</a>');
$(elt).find('.full-custom').click(function (event) { $(elt).find('.full-custom').click(function(event) {
Collapsible.toggleFull(event, open_text, close_text); Collapsible.toggleFull(event, open_text, close_text);
}); });
}); });
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
el.find('.collapsible header + section').hide(); el.find('.collapsible header + section').hide();
// Set up triggers. // Set up triggers.
el.find('.full').click(function (event) { el.find('.full').click(function(event) {
Collapsible.toggleFull(event, "See full output", "Hide output"); Collapsible.toggleFull(event, 'See full output', 'Hide output');
}); });
el.find('.collapsible header a').click(Collapsible.toggleHint); el.find('.collapsible header a').click(Collapsible.toggleHint);
} }
......
var setupFullScreenModal = function() { var setupFullScreenModal = function() {
// Setup full screen image modal. // Setup full screen image modal.
// Executed from HTMLModule in display.js. // Executed from HTMLModule in display.js.
$("a.modal-content").each(function() { $('a.modal-content').each(function() {
var smallImageObject = $(this).children(); var smallImageObject = $(this).children();
var largeImageSRC = $(this).attr('href'); var largeImageSRC = $(this).attr('href');
// if contents of zoomable link is image and large image link exists: setup modal // if contents of zoomable link is image and large image link exists: setup modal
if (smallImageObject.is('img') && largeImageSRC) { if (smallImageObject.is('img') && largeImageSRC) {
var data = { var data = {
"smallHTML": $(this).html(), 'smallHTML': $(this).html(),
"largeALT": smallImageObject.attr('alt'), 'largeALT': smallImageObject.attr('alt'),
"largeSRC": largeImageSRC 'largeSRC': largeImageSRC
}; };
var html = _.template($("#image-modal-tpl").text())(data); var html = _.template($('#image-modal-tpl').text())(data);
$(this).replaceWith(html); $(this).replaceWith(html);
} }
}); });
$('.wrapper-modal-image .image-wrapper img').each(function() { $('.wrapper-modal-image .image-wrapper img').each(function() {
var draggie = new Draggabilly(this, {containment: true}); var draggie = new Draggabilly(this, {containment: true});
draggie.disable(); draggie.disable();
$(this).closest('.image-modal').data("draggie", draggie); $(this).closest('.image-modal').data('draggie', draggie);
}); });
// Opening and closing image modal on clicks // Opening and closing image modal on clicks
$(".wrapper-modal-image .image-link").click(function() { $('.wrapper-modal-image .image-link').click(function() {
$(this).siblings(".image-modal").addClass('image-is-fit-to-screen'); $(this).siblings('.image-modal').addClass('image-is-fit-to-screen');
$('body').css('overflow', 'hidden'); $('body').css('overflow', 'hidden');
}); });
// variable to detect when modal is being "hovered". // variable to detect when modal is being "hovered".
// Done this way as jquery doesn't support the :hover psudo-selector as expected. // Done this way as jquery doesn't support the :hover psudo-selector as expected.
var imageModalImageHover = false; var imageModalImageHover = false;
$(".wrapper-modal-image .image-content img, .wrapper-modal-image .image-content .image-controls").hover(function() { $('.wrapper-modal-image .image-content img, .wrapper-modal-image .image-content .image-controls').hover(function() {
imageModalImageHover = true; imageModalImageHover = true;
}, function() { }, function() {
imageModalImageHover = false; imageModalImageHover = false;
}); });
// prevent image control button links from scrolling // prevent image control button links from scrolling
$(".modal-ui-icon").click(function(event) { $('.modal-ui-icon').click(function(event) {
event.preventDefault(); event.preventDefault();
}); });
//Define function to close modal // Define function to close modal
function closeModal(imageModal) { function closeModal(imageModal) {
imageModal.removeClass('image-is-fit-to-screen').removeClass('image-is-zoomed'); imageModal.removeClass('image-is-fit-to-screen').removeClass('image-is-zoomed');
$(".wrapper-modal-image .image-content .image-controls .modal-ui-icon.action-zoom-in").removeClass('is-disabled').attr('aria-disabled', false); $('.wrapper-modal-image .image-content .image-controls .modal-ui-icon.action-zoom-in').removeClass('is-disabled').attr('aria-disabled', false);
$(".wrapper-modal-image .image-content .image-controls .modal-ui-icon.action-zoom-out").addClass('is-disabled').attr('aria-disabled', true); $('.wrapper-modal-image .image-content .image-controls .modal-ui-icon.action-zoom-out').addClass('is-disabled').attr('aria-disabled', true);
var currentDraggie = imageModal.data("draggie"); var currentDraggie = imageModal.data('draggie');
currentDraggie.disable(); currentDraggie.disable();
$('body').css('overflow', 'auto'); $('body').css('overflow', 'auto');
}
// Click outside of modal to close it.
$(".wrapper-modal-image .image-modal").click(function() {
if (!imageModalImageHover){
closeModal($(this));
} }
});
// Click outside of modal to close it.
$('.wrapper-modal-image .image-modal').click(function() {
if (!imageModalImageHover) {
closeModal($(this));
}
});
// Click close icon to close modal. // Click close icon to close modal.
$(".wrapper-modal-image .image-content .action-remove").click(function() { $('.wrapper-modal-image .image-content .action-remove').click(function() {
closeModal($(this).closest(".image-modal")); closeModal($(this).closest('.image-modal'));
}); });
// zooming image in modal and allow it to be dragged // zooming image in modal and allow it to be dragged
// Make sure it always starts zero position for below calcs to work // Make sure it always starts zero position for below calcs to work
$(".wrapper-modal-image .image-content .image-controls .modal-ui-icon").click(function() { $('.wrapper-modal-image .image-content .image-controls .modal-ui-icon').click(function() {
if (!$(this).hasClass('is-disabled')) { if (!$(this).hasClass('is-disabled')) {
var mask = $(this).closest(".image-content"); var mask = $(this).closest('.image-content');
var imageModal = $(this).closest(".image-modal"); var imageModal = $(this).closest('.image-modal');
var img = imageModal.find("img"); var img = imageModal.find('img');
var currentDraggie = imageModal.data("draggie"); var currentDraggie = imageModal.data('draggie');
if ($(this).hasClass('action-zoom-in')) { if ($(this).hasClass('action-zoom-in')) {
imageModal.removeClass('image-is-fit-to-screen').addClass('image-is-zoomed'); imageModal.removeClass('image-is-fit-to-screen').addClass('image-is-zoomed');
var imgWidth = img.width(); var imgWidth = img.width();
var imgHeight = img.height(); var imgHeight = img.height();
var imgContainerOffsetLeft = imgWidth - mask.width(); var imgContainerOffsetLeft = imgWidth - mask.width();
var imgContainerOffsetTop = imgHeight - mask.height(); var imgContainerOffsetTop = imgHeight - mask.height();
var imgContainerWidth = imgWidth + imgContainerOffsetLeft; var imgContainerWidth = imgWidth + imgContainerOffsetLeft;
var imgContainerHeight = imgHeight + imgContainerOffsetTop; var imgContainerHeight = imgHeight + imgContainerOffsetTop;
// Set the width and height of the image's container so that the dimensions are equal to the image dimensions + view area dimensions to limit dragging // Set the width and height of the image's container so that the dimensions are equal to the image dimensions + view area dimensions to limit dragging
// Set image container top and left to center image at load. // Set image container top and left to center image at load.
img.parent().css({ img.parent().css({
left: -imgContainerOffsetLeft, left: -imgContainerOffsetLeft,
top: -imgContainerOffsetTop, top: -imgContainerOffsetTop,
width: imgContainerWidth, width: imgContainerWidth,
height: imgContainerHeight height: imgContainerHeight
}); });
img.css({top: imgContainerOffsetTop / 2, left: imgContainerOffsetLeft / 2}); img.css({top: imgContainerOffsetTop / 2, left: imgContainerOffsetLeft / 2});
currentDraggie.enable(); currentDraggie.enable();
} else if ($(this).hasClass('action-zoom-out')) {
} else if ($(this).hasClass('action-zoom-out')) { imageModal.removeClass('image-is-zoomed').addClass('image-is-fit-to-screen');
imageModal.removeClass('image-is-zoomed').addClass('image-is-fit-to-screen');
currentDraggie.disable();
currentDraggie.disable(); }
}
$('.wrapper-modal-image .image-content .image-controls .modal-ui-icon').toggleClass('is-disabled').attr('aria-disabled', $(this).hasClass('is-disabled'));
$(".wrapper-modal-image .image-content .image-controls .modal-ui-icon").toggleClass('is-disabled').attr('aria-disabled', $(this).hasClass('is-disabled')); }
} });
});
}; };
(function () { (function() {
'use strict'; 'use strict';
/** /**
* This function will process all the attributes from the DOM element passed, taking all of * This function will process all the attributes from the DOM element passed, taking all of
...@@ -8,25 +8,23 @@ ...@@ -8,25 +8,23 @@
* @constructor * @constructor
* @param {jQuery} element DOM element with the lti container. * @param {jQuery} element DOM element with the lti container.
*/ */
this.LTI = function (element) { this.LTI = function(element) {
var dataAttrs = $(element).find('.lti').data(), var dataAttrs = $(element).find('.lti').data(),
askToSendUsername = (dataAttrs.askToSendUsername === 'True'), askToSendUsername = (dataAttrs.askToSendUsername === 'True'),
askToSendEmail = (dataAttrs.askToSendEmail === 'True'); askToSendEmail = (dataAttrs.askToSendEmail === 'True');
// When the lti button is clicked, provide users the option to // When the lti button is clicked, provide users the option to
// accept or reject sending their information to a third party // accept or reject sending their information to a third party
$(element).on('click', '.link_lti_new_window', function () { $(element).on('click', '.link_lti_new_window', function() {
if(askToSendUsername && askToSendEmail) { if (askToSendUsername && askToSendEmail) {
return confirm(gettext("Click OK to have your username and e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.")); return confirm(gettext('Click OK to have your username and e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else if (askToSendUsername) { } else if (askToSendUsername) {
return confirm(gettext("Click OK to have your username sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.")); return confirm(gettext('Click OK to have your username sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else if (askToSendEmail) { } else if (askToSendEmail) {
return confirm(gettext("Click OK to have your e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.")); return confirm(gettext('Click OK to have your e-mail address sent to a 3rd party application.\n\nClick Cancel to return to this page without sending your information.'));
} else { } else {
return true; return true;
} }
}); });
}; };
}).call(this); }).call(this);
window.Poll = function (el) { window.Poll = function(el) {
RequireJS.require(['PollMain'], function (PollMain) { RequireJS.require(['PollMain'], function(PollMain) {
new PollMain(el); new PollMain(el);
}); });
}; };
(function (undefined) { (function(undefined) {
'use strict'; 'use strict';
this.Time = { this.Time = {
......
(function (define) { (function(define) {
define( define(
'video/00_async_process.js', 'video/00_async_process.js',
[], [],
function() { function() {
"use strict"; 'use strict';
/** /**
* Provides convenient way to process big amount of data without UI blocking. * Provides convenient way to process big amount of data without UI blocking.
* *
...@@ -13,7 +13,7 @@ function() { ...@@ -13,7 +13,7 @@ function() {
* certain type bound to the collection, queued or not, have finished. * certain type bound to the collection, queued or not, have finished.
*/ */
var AsyncProcess = { var AsyncProcess = {
array: function (list, process) { array: function(list, process) {
if (!_.isArray(list)) { if (!_.isArray(list)) {
return $.Deferred().reject().promise(); return $.Deferred().reject().promise();
} }
...@@ -28,11 +28,11 @@ function() { ...@@ -28,11 +28,11 @@ function() {
index = 0, index = 0,
len = list.length; len = list.length;
var getCurrentTime = function () { var getCurrentTime = function() {
return (new Date()).getTime(); return (new Date()).getTime();
}; };
var handler = function () { var handler = function() {
var start = getCurrentTime(); var start = getCurrentTime();
do { do {
......
(function (define) { (function(define) {
'use strict'; 'use strict';
define('video/00_component.js', [], define('video/00_component.js', [],
function () { function() {
/** /**
* Creates a new object with the specified prototype object and properties. * Creates a new object with the specified prototype object and properties.
* @param {Object} o The object which should be the prototype of the * @param {Object} o The object which should be the prototype of the
...@@ -10,10 +10,10 @@ function () { ...@@ -10,10 +10,10 @@ function () {
* @throws {TypeError, Error} * @throws {TypeError, Error}
* @return {Object} * @return {Object}
*/ */
var inherit = Object.create || (function () { var inherit = Object.create || (function() {
var F = function () {}; var F = function() {};
return function (o) { return function(o) {
if (arguments.length > 1) { if (arguments.length > 1) {
throw Error('Second argument not supported'); throw Error('Second argument not supported');
} }
...@@ -36,7 +36,7 @@ function () { ...@@ -36,7 +36,7 @@ function () {
* @constructor * @constructor
* @return {jquery Promise} * @return {jquery Promise}
*/ */
var Component = function () { var Component = function() {
if ($.isFunction(this.initialize)) { if ($.isFunction(this.initialize)) {
return this.initialize.apply(this, arguments); return this.initialize.apply(this, arguments);
} }
...@@ -49,9 +49,9 @@ function () { ...@@ -49,9 +49,9 @@ function () {
* the prototype. * the prototype.
* @return {Object} * @return {Object}
*/ */
Component.extend = function (protoProps, staticProps) { Component.extend = function(protoProps, staticProps) {
var Parent = this, var Parent = this,
Child = function () { Child = function() {
if ($.isFunction(this.initialize)) { if ($.isFunction(this.initialize)) {
return this.initialize.apply(this, arguments); return this.initialize.apply(this, arguments);
} }
......
(function (define) { (function(define) {
'use strict'; 'use strict';
define( define(
'video/00_i18n.js', 'video/00_i18n.js',
[], [],
function() { function() {
......
(function (define) { (function(define) {
define( define(
'video/00_iterator.js', 'video/00_iterator.js',
[], [],
function() { function() {
"use strict"; 'use strict';
/** /**
* Provides convenient way to work with iterable data. * Provides convenient way to work with iterable data.
* @exports video/00_iterator.js * @exports video/00_iterator.js
* @constructor * @constructor
* @param {array} list Array to be iterated. * @param {array} list Array to be iterated.
*/ */
var Iterator = function (list) { var Iterator = function(list) {
this.list = list; this.list = list;
this.index = 0; this.index = 0;
this.size = this.list.length; this.size = this.list.length;
this.lastIndex = this.list.length - 1; this.lastIndex = this.list.length - 1;
}; };
Iterator.prototype = { Iterator.prototype = {
...@@ -25,7 +25,7 @@ function() { ...@@ -25,7 +25,7 @@ function() {
* @param {numebr} index * @param {numebr} index
* @return {boolean} * @return {boolean}
*/ */
_isValid: function (index) { _isValid: function(index) {
return _.isNumber(index) && index < this.size && index >= 0; return _.isNumber(index) && index < this.size && index >= 0;
}, },
...@@ -34,12 +34,12 @@ function() { ...@@ -34,12 +34,12 @@ function() {
* @param {number} [index] Updates current position. * @param {number} [index] Updates current position.
* @return {any} * @return {any}
*/ */
next: function (index) { next: function(index) {
if (!(this._isValid(index))) { if (!(this._isValid(index))) {
index = this.index; index = this.index;
} }
this.index = (index >= this.lastIndex) ? 0: index + 1; this.index = (index >= this.lastIndex) ? 0 : index + 1;
return this.list[this.index]; return this.list[this.index];
}, },
...@@ -49,12 +49,12 @@ function() { ...@@ -49,12 +49,12 @@ function() {
* @param {number} [index] Updates current position. * @param {number} [index] Updates current position.
* @return {any} * @return {any}
*/ */
prev: function (index) { prev: function(index) {
if (!(this._isValid(index))) { if (!(this._isValid(index))) {
index = this.index; index = this.index;
} }
this.index = (index < 1) ? this.lastIndex: index - 1; this.index = (index < 1) ? this.lastIndex : index - 1;
return this.list[this.index]; return this.list[this.index];
}, },
...@@ -63,7 +63,7 @@ function() { ...@@ -63,7 +63,7 @@ function() {
* Returns last element in the list. * Returns last element in the list.
* @return {any} * @return {any}
*/ */
last: function () { last: function() {
return this.list[this.lastIndex]; return this.list[this.lastIndex];
}, },
...@@ -71,7 +71,7 @@ function() { ...@@ -71,7 +71,7 @@ function() {
* Returns first element in the list. * Returns first element in the list.
* @return {any} * @return {any}
*/ */
first: function () { first: function() {
return this.list[0]; return this.list[0];
}, },
...@@ -79,7 +79,7 @@ function() { ...@@ -79,7 +79,7 @@ function() {
* Returns `true` if current position is last for the iterator. * Returns `true` if current position is last for the iterator.
* @return {boolean} * @return {boolean}
*/ */
isEnd: function () { isEnd: function() {
return this.index === this.lastIndex; return this.index === this.lastIndex;
} }
}; };
......
(function (requirejs, require, define) { (function(requirejs, require, define) {
define(
define(
'video/00_resizer.js', 'video/00_resizer.js',
[], [],
function () { function() {
var Resizer = function(params) {
var Resizer = function (params) {
var defaults = { var defaults = {
container: window, container: window,
element: null, element: null,
...@@ -21,7 +19,7 @@ function () { ...@@ -21,7 +19,7 @@ function () {
mode = null, mode = null,
config; config;
var initialize = function (params) { var initialize = function(params) {
if (!config) { if (!config) {
config = defaults; config = defaults;
} }
...@@ -37,7 +35,7 @@ function () { ...@@ -37,7 +35,7 @@ function () {
return module; return module;
}; };
var getData = function () { var getData = function() {
var container = $(config.container), var container = $(config.container),
containerWidth = container.width() + delta.width, containerWidth = container.width() + delta.width,
containerHeight = container.height() + delta.height, containerHeight = container.height() + delta.height,
...@@ -47,11 +45,11 @@ function () { ...@@ -47,11 +45,11 @@ function () {
elementRatio = config.elementRatio; elementRatio = config.elementRatio;
if (!containerRatio) { if (!containerRatio) {
containerRatio = containerWidth/containerHeight; containerRatio = containerWidth / containerHeight;
} }
if (!elementRatio) { if (!elementRatio) {
elementRatio = element.width()/element.height(); elementRatio = element.width() / element.height();
} }
return { return {
...@@ -63,25 +61,25 @@ function () { ...@@ -63,25 +61,25 @@ function () {
}; };
}; };
var align = function () { var align = function() {
var data = getData(); var data = getData();
switch (mode) { switch (mode) {
case 'height': case 'height':
alignByHeightOnly(); alignByHeightOnly();
break; break;
case 'width': case 'width':
alignByWidthOnly();
break;
default:
if (data.containerRatio >= data.elementRatio) {
alignByHeightOnly();
} else {
alignByWidthOnly(); alignByWidthOnly();
break; }
break;
default:
if (data.containerRatio >= data.elementRatio) {
alignByHeightOnly();
} else {
alignByWidthOnly();
}
break;
} }
fireCallbacks(); fireCallbacks();
...@@ -89,35 +87,35 @@ function () { ...@@ -89,35 +87,35 @@ function () {
return module; return module;
}; };
var alignByWidthOnly = function () { var alignByWidthOnly = function() {
var data = getData(), var data = getData(),
height = data.containerWidth/data.elementRatio; height = data.containerWidth / data.elementRatio;
data.element.css({ data.element.css({
'height': height, 'height': height,
'width': data.containerWidth, 'width': data.containerWidth,
'top': 0.5*(data.containerHeight - height), 'top': 0.5 * (data.containerHeight - height),
'left': 0 'left': 0
}); });
return module; return module;
}; };
var alignByHeightOnly = function () { var alignByHeightOnly = function() {
var data = getData(), var data = getData(),
width = data.containerHeight*data.elementRatio; width = data.containerHeight * data.elementRatio;
data.element.css({ data.element.css({
'height': data.containerHeight, 'height': data.containerHeight,
'width': data.containerHeight*data.elementRatio, 'width': data.containerHeight * data.elementRatio,
'top': 0, 'top': 0,
'left': 0.5*(data.containerWidth - width) 'left': 0.5 * (data.containerWidth - width)
}); });
return module; return module;
}; };
var setMode = function (param) { var setMode = function(param) {
if (_.isString(param)) { if (_.isString(param)) {
mode = param; mode = param;
align(); align();
...@@ -126,13 +124,13 @@ function () { ...@@ -126,13 +124,13 @@ function () {
return module; return module;
}; };
var setElement = function (element) { var setElement = function(element) {
config.element = element; config.element = element;
return module; return module;
}; };
var addCallback = function (func) { var addCallback = function(func) {
if ($.isFunction(func)) { if ($.isFunction(func)) {
callbacksList.push(func); callbacksList.push(func);
} else { } else {
...@@ -142,9 +140,9 @@ function () { ...@@ -142,9 +140,9 @@ function () {
return module; return module;
}; };
var addOnceCallback = function (func) { var addOnceCallback = function(func) {
if ($.isFunction(func)) { if ($.isFunction(func)) {
var decorator = function () { var decorator = function() {
func(); func();
removeCallback(func); removeCallback(func);
}; };
...@@ -157,19 +155,19 @@ function () { ...@@ -157,19 +155,19 @@ function () {
return module; return module;
}; };
var fireCallbacks = function () { var fireCallbacks = function() {
$.each(callbacksList, function(index, callback) { $.each(callbacksList, function(index, callback) {
callback(); callback();
}); });
}; };
var removeCallbacks = function () { var removeCallbacks = function() {
callbacksList.length = 0; callbacksList.length = 0;
return module; return module;
}; };
var removeCallback = function (func) { var removeCallback = function(func) {
var index = $.inArray(func, callbacksList); var index = $.inArray(func, callbacksList);
if (index !== -1) { if (index !== -1) {
...@@ -177,13 +175,13 @@ function () { ...@@ -177,13 +175,13 @@ function () {
} }
}; };
var resetDelta = function () { var resetDelta = function() {
delta['height'] = delta['width'] = 0; delta['height'] = delta['width'] = 0;
return module; return module;
}; };
var addDelta = function (value, side) { var addDelta = function(value, side) {
if (_.isNumber(value) && _.isNumber(delta[side])) { if (_.isNumber(value) && _.isNumber(delta[side])) {
delta[side] += value; delta[side] += value;
} }
...@@ -191,7 +189,7 @@ function () { ...@@ -191,7 +189,7 @@ function () {
return module; return module;
}; };
var substractDelta = function (value, side) { var substractDelta = function(value, side) {
if (_.isNumber(value) && _.isNumber(delta[side])) { if (_.isNumber(value) && _.isNumber(delta[side])) {
delta[side] -= value; delta[side] -= value;
} }
...@@ -199,7 +197,7 @@ function () { ...@@ -199,7 +197,7 @@ function () {
return module; return module;
}; };
var destroy = function () { var destroy = function() {
var data = getData(); var data = getData();
data.element.css({ data.element.css({
'height': '', 'width': '', 'top': '', 'left': '' 'height': '', 'width': '', 'top': '', 'left': ''
...@@ -235,5 +233,4 @@ function () { ...@@ -235,5 +233,4 @@ function () {
return Resizer; return Resizer;
}); });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
(function (define) { (function(define) {
define(
define(
'video/00_sjson.js', 'video/00_sjson.js',
[], [],
function() { function() {
"use strict"; 'use strict';
var Sjson = function (data) { var Sjson = function(data) {
var sjson = { var sjson = {
start: data.start.concat(), start: data.start.concat(),
text: data.text.concat() text: data.text.concat()
}, },
module = {}; module = {};
var getter = function (propertyName) { var getter = function(propertyName) {
return function () { return function() {
return sjson[propertyName]; return sjson[propertyName];
}; };
}; };
...@@ -23,7 +22,7 @@ function() { ...@@ -23,7 +22,7 @@ function() {
var getCaptions = getter('text'); var getCaptions = getter('text');
var size = function () { var size = function() {
return sjson.text.length; return sjson.text.length;
}; };
...@@ -40,11 +39,11 @@ function() { ...@@ -40,11 +39,11 @@ function() {
// Else, search the unfiltered list. // Else, search the unfiltered list.
if (typeof startTime !== 'undefined' && if (typeof startTime !== 'undefined' &&
typeof endTime !== 'undefined') { typeof endTime !== 'undefined') {
results = filter(startTime, endTime); results = filter(startTime, endTime);
start = results.start; start = results.start;
max = results.captions.length - 1; max = results.captions.length - 1;
} else { } else {
start = getStartTimes(); start = getStartTimes();
} }
while (min < max) { while (min < max) {
index = Math.ceil((max + min) / 2); index = Math.ceil((max + min) / 2);
...@@ -59,7 +58,7 @@ function() { ...@@ -59,7 +58,7 @@ function() {
} }
return min; return min;
}; }
function filter(start, end) { function filter(start, end) {
/* filters captions that occur between inputs /* filters captions that occur between inputs
...@@ -79,7 +78,7 @@ function() { ...@@ -79,7 +78,7 @@ function() {
var captions = getCaptions(); var captions = getCaptions();
if (startTimes.length !== captions.length) { if (startTimes.length !== captions.length) {
console.warn("video caption and start time arrays do not match in length"); console.warn('video caption and start time arrays do not match in length');
} }
// if end is null, then it's been set to // if end is null, then it's been set to
......
(function (requirejs, require, define) { (function(requirejs, require, define) {
define(
define(
'video/00_video_storage.js', 'video/00_video_storage.js',
[], [],
function() { function() {
"use strict"; 'use strict';
/** /**
* Provides convenient way to store key value pairs. * Provides convenient way to store key value pairs.
* *
* @param {string} namespace Namespace that is used to store data. * @param {string} namespace Namespace that is used to store data.
* @return {object} VideoStorage API. * @return {object} VideoStorage API.
*/ */
var VideoStorage = function (namespace, id) { var VideoStorage = function(namespace, id) {
/** /**
* Adds new value to the storage or rewrites existent. * Adds new value to the storage or rewrites existent.
* *
...@@ -20,7 +19,7 @@ function() { ...@@ -20,7 +19,7 @@ function() {
* @param {boolean} instanceSpecific Data with this flag will be added * @param {boolean} instanceSpecific Data with this flag will be added
* to instance specific storage. * to instance specific storage.
*/ */
var setItem = function (name, value, instanceSpecific) { var setItem = function(name, value, instanceSpecific) {
if (name) { if (name) {
if (instanceSpecific) { if (instanceSpecific) {
window[namespace][id][name] = value; window[namespace][id][name] = value;
...@@ -40,7 +39,7 @@ function() { ...@@ -40,7 +39,7 @@ function() {
* If the given key does not exist in the list * If the given key does not exist in the list
* associated with the object then this method must return null. * associated with the object then this method must return null.
*/ */
var getItem = function (name, instanceSpecific) { var getItem = function(name, instanceSpecific) {
if (instanceSpecific) { if (instanceSpecific) {
return window[namespace][id][name]; return window[namespace][id][name];
} else { } else {
...@@ -55,7 +54,7 @@ function() { ...@@ -55,7 +54,7 @@ function() {
* @param {boolean} instanceSpecific Data with this flag will be added * @param {boolean} instanceSpecific Data with this flag will be added
* to instance specific storage. * to instance specific storage.
*/ */
var removeItem = function (name, instanceSpecific) { var removeItem = function(name, instanceSpecific) {
if (instanceSpecific) { if (instanceSpecific) {
delete window[namespace][id][name]; delete window[namespace][id][name];
} else { } else {
...@@ -67,7 +66,7 @@ function() { ...@@ -67,7 +66,7 @@ function() {
* Empties the storage. * Empties the storage.
* *
*/ */
var clear = function () { var clear = function() {
window[namespace] = {}; window[namespace] = {};
window[namespace][id] = {}; window[namespace][id] = {};
}; };
......
...@@ -25,14 +25,13 @@ ...@@ -25,14 +25,13 @@
* ~ Zen saying * ~ Zen saying
*/ */
(function (requirejs, require, define) { (function(requirejs, require, define) {
// FocusGrabber module. // FocusGrabber module.
define( define(
'video/025_focus_grabber.js', 'video/025_focus_grabber.js',
[], [],
function () { function() {
return function (state) { return function(state) {
var dfd = $.Deferred(); var dfd = $.Deferred();
state.focusGrabber = {}; state.focusGrabber = {};
...@@ -75,7 +74,7 @@ function () { ...@@ -75,7 +74,7 @@ function () {
// When the video container element receives programmatic focus, then // When the video container element receives programmatic focus, then
// on un-focus ('blur' event) we should trigger a 'mousemove' event so // on un-focus ('blur' event) we should trigger a 'mousemove' event so
// as to reveal autohidden controls. // as to reveal autohidden controls.
state.el.on('blur', function () { state.el.on('blur', function() {
state.el.trigger('mousemove'); state.el.trigger('mousemove');
}); });
} }
......
...@@ -13,16 +13,15 @@ ...@@ -13,16 +13,15 @@
* @module HTML5Video * @module HTML5Video
*/ */
(function (requirejs, require, define) { (function(requirejs, require, define) {
define(
define(
'video/02_html5_video.js', 'video/02_html5_video.js',
[], [],
function () { function() {
var HTML5Video = {}; var HTML5Video = {};
HTML5Video.Player = (function () { HTML5Video.Player = (function() {
Player.prototype.callStateChangeCallback = function () { Player.prototype.callStateChangeCallback = function() {
if ($.isFunction(this.config.events.onStateChange)) { if ($.isFunction(this.config.events.onStateChange)) {
this.config.events.onStateChange({ this.config.events.onStateChange({
data: this.playerState data: this.playerState
...@@ -30,11 +29,11 @@ function () { ...@@ -30,11 +29,11 @@ function () {
} }
}; };
Player.prototype.pauseVideo = function () { Player.prototype.pauseVideo = function() {
this.video.pause(); this.video.pause();
}; };
Player.prototype.seekTo = function (value) { Player.prototype.seekTo = function(value) {
if ( if (
typeof value === 'number' && typeof value === 'number' &&
value <= this.video.duration && value <= this.video.duration &&
...@@ -44,29 +43,29 @@ function () { ...@@ -44,29 +43,29 @@ function () {
} }
}; };
Player.prototype.setVolume = function (value) { Player.prototype.setVolume = function(value) {
if (typeof value === 'number' && value <= 100 && value >= 0) { if (typeof value === 'number' && value <= 100 && value >= 0) {
this.video.volume = value * 0.01; this.video.volume = value * 0.01;
} }
}; };
Player.prototype.getCurrentTime = function () { Player.prototype.getCurrentTime = function() {
return this.video.currentTime; return this.video.currentTime;
}; };
Player.prototype.playVideo = function () { Player.prototype.playVideo = function() {
this.video.play(); this.video.play();
}; };
Player.prototype.getPlayerState = function () { Player.prototype.getPlayerState = function() {
return this.playerState; return this.playerState;
}; };
Player.prototype.getVolume = function () { Player.prototype.getVolume = function() {
return this.video.volume; return this.video.volume;
}; };
Player.prototype.getDuration = function () { Player.prototype.getDuration = function() {
if (isNaN(this.video.duration)) { if (isNaN(this.video.duration)) {
return 0; return 0;
} }
...@@ -74,7 +73,7 @@ function () { ...@@ -74,7 +73,7 @@ function () {
return this.video.duration; return this.video.duration;
}; };
Player.prototype.setPlaybackRate = function (value) { Player.prototype.setPlaybackRate = function(value) {
var newSpeed; var newSpeed;
newSpeed = parseFloat(value); newSpeed = parseFloat(value);
...@@ -86,15 +85,15 @@ function () { ...@@ -86,15 +85,15 @@ function () {
} }
}; };
Player.prototype.getAvailablePlaybackRates = function () { Player.prototype.getAvailablePlaybackRates = function() {
return [0.75, 1.0, 1.25, 1.5]; return [0.75, 1.0, 1.25, 1.5];
}; };
Player.prototype._getLogs = function () { Player.prototype._getLogs = function() {
return this.logs; return this.logs;
}; };
Player.prototype.showErrorMessage = function () { Player.prototype.showErrorMessage = function() {
this.el this.el
.find('.video-player div') .find('.video-player div')
.addClass('hidden') .addClass('hidden')
...@@ -110,13 +109,13 @@ function () { ...@@ -110,13 +109,13 @@ function () {
}); });
}; };
Player.prototype.onError = function (event) { Player.prototype.onError = function(event) {
if ($.isFunction(this.config.events.onError)) { if ($.isFunction(this.config.events.onError)) {
this.config.events.onError(); this.config.events.onError();
} }
}; };
Player.prototype.destroy = function () { Player.prototype.destroy = function() {
this.video.removeEventListener('loadedmetadata', this.onLoadedMetadata, false); this.video.removeEventListener('loadedmetadata', this.onLoadedMetadata, false);
this.video.removeEventListener('play', this.onPlay, false); this.video.removeEventListener('play', this.onPlay, false);
this.video.removeEventListener('playing', this.onPlaying, false); this.video.removeEventListener('playing', this.onPlaying, false);
...@@ -131,29 +130,29 @@ function () { ...@@ -131,29 +130,29 @@ function () {
this.videoEl.remove(); this.videoEl.remove();
}; };
Player.prototype.onLoadedMetadata = function () { Player.prototype.onLoadedMetadata = function() {
this.playerState = HTML5Video.PlayerState.PAUSED; this.playerState = HTML5Video.PlayerState.PAUSED;
if ($.isFunction(this.config.events.onReady)) { if ($.isFunction(this.config.events.onReady)) {
this.config.events.onReady(null); this.config.events.onReady(null);
} }
}; };
Player.prototype.onPlay = function () { Player.prototype.onPlay = function() {
this.playerState = HTML5Video.PlayerState.BUFFERING; this.playerState = HTML5Video.PlayerState.BUFFERING;
this.callStateChangeCallback(); this.callStateChangeCallback();
}; };
Player.prototype.onPlaying = function () { Player.prototype.onPlaying = function() {
this.playerState = HTML5Video.PlayerState.PLAYING; this.playerState = HTML5Video.PlayerState.PLAYING;
this.callStateChangeCallback(); this.callStateChangeCallback();
}; };
Player.prototype.onPause = function () { Player.prototype.onPause = function() {
this.playerState = HTML5Video.PlayerState.PAUSED; this.playerState = HTML5Video.PlayerState.PAUSED;
this.callStateChangeCallback(); this.callStateChangeCallback();
}; };
Player.prototype.onEnded = function () { Player.prototype.onEnded = function() {
this.playerState = HTML5Video.PlayerState.ENDED; this.playerState = HTML5Video.PlayerState.ENDED;
this.callStateChangeCallback(); this.callStateChangeCallback();
}; };
...@@ -242,16 +241,16 @@ function () { ...@@ -242,16 +241,16 @@ function () {
// Create HTML markup for individual sources of the HTML5 <video> // Create HTML markup for individual sources of the HTML5 <video>
// element. // element.
sourceList = $.map(config.videoSources, function (source) { sourceList = $.map(config.videoSources, function(source) {
return [ return [
'<source ', '<source ',
'src="', source, 'src="', source,
// Following hack allows to open the same video twice // Following hack allows to open the same video twice
// https://code.google.com/p/chromium/issues/detail?id=31014 // https://code.google.com/p/chromium/issues/detail?id=31014
// Check whether the url already has a '?' inside, and if so, // Check whether the url already has a '?' inside, and if so,
// use '&' instead of '?' to prevent breaking the url's integrity. // use '&' instead of '?' to prevent breaking the url's integrity.
(source.indexOf('?') === -1 ? '?' : '&'), (source.indexOf('?') === -1 ? '?' : '&'),
(new Date()).getTime(), '" />' (new Date()).getTime(), '" />'
].join(''); ].join('');
}); });
...@@ -286,7 +285,7 @@ function () { ...@@ -286,7 +285,7 @@ function () {
// Attach a 'click' event on the <video> element. It will cause the // Attach a 'click' event on the <video> element. It will cause the
// video to pause/play. // video to pause/play.
this.videoEl.on('click', function (event) { this.videoEl.on('click', function(event) {
var PlayerState = HTML5Video.PlayerState; var PlayerState = HTML5Video.PlayerState;
if (_this.playerState === PlayerState.PLAYING) { if (_this.playerState === PlayerState.PLAYING) {
...@@ -307,7 +306,7 @@ function () { ...@@ -307,7 +306,7 @@ function () {
this.debug = false; this.debug = false;
$.each(events, function(index, eventName) { $.each(events, function(index, eventName) {
_this.video.addEventListener(eventName, function () { _this.video.addEventListener(eventName, function() {
_this.logs.push({ _this.logs.push({
'event name': eventName, 'event name': eventName,
'state': _this.playerState 'state': _this.playerState
...@@ -356,5 +355,4 @@ function () { ...@@ -356,5 +355,4 @@ 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));
(function(define) { (function(define) {
'use strict'; 'use strict';
// VideoAccessibleMenu module. // VideoAccessibleMenu module.
define( define(
'video/035_video_accessible_menu.js', [], 'video/035_video_accessible_menu.js', [],
function() { function() {
/** /**
...@@ -51,7 +51,7 @@ function() { ...@@ -51,7 +51,7 @@ function() {
this.menuList = this.el.children('.a11y-menu-list'); this.menuList = this.el.children('.a11y-menu-list');
this.menuItems = this.menuList.children('.a11y-menu-item'); this.menuItems = this.menuList.children('.a11y-menu-item');
this.menuItemsLinks = this.menuItems.children('.a11y-menu-item-link'); this.menuItemsLinks = this.menuItems.children('.a11y-menu-item-link');
value = (function (val, activeElement) { value = (function(val, activeElement) {
return val || activeElement.find('a').data('value') || 'srt'; return val || activeElement.find('a').data('value') || 'srt';
}(this.value, this.menuItems.filter('.active'))); }(this.value, this.menuItems.filter('.active')));
msg = '.' + value; msg = '.' + value;
...@@ -159,57 +159,57 @@ function() { ...@@ -159,57 +159,57 @@ function() {
index = target.parent().index(); index = target.parent().index();
switch (keyCode) { switch (keyCode) {
// Scroll up menu, wrapping at the top. Keep menu open. // Scroll up menu, wrapping at the top. Keep menu open.
case KEY.UP: case KEY.UP:
this.previousMenuItemLink(this.menuItemsLinks, index).focus(); this.previousMenuItemLink(this.menuItemsLinks, index).focus();
break; break;
// Scroll down menu, wrapping at the bottom. Keep menu // Scroll down menu, wrapping at the bottom. Keep menu
// open. // open.
case KEY.DOWN: case KEY.DOWN:
this.nextMenuItemLink(this.menuItemsLinks, index).focus(); this.nextMenuItemLink(this.menuItemsLinks, index).focus();
break; break;
// Close menu. // Close menu.
case KEY.TAB: case KEY.TAB:
this.closeMenu(); this.closeMenu();
// TODO // TODO
// What has to happen here? In speed menu, tabbing backward // What has to happen here? In speed menu, tabbing backward
// will give focus to Play/Pause button and tabbing // will give focus to Play/Pause button and tabbing
// forward to Volume button. // forward to Volume button.
break; break;
// Close menu, give focus to button and change // Close menu, give focus to button and change
// file type. // file type.
case KEY.ENTER: case KEY.ENTER:
case KEY.SPACE: case KEY.SPACE:
this.button.focus(); this.button.focus();
this.changeFileType.call(this, event); this.changeFileType.call(this, event);
this.closeMenu(); this.closeMenu();
break; break;
// Close menu and give focus to speed control. // Close menu and give focus to speed control.
case KEY.ESCAPE: case KEY.ESCAPE:
this.closeMenu(); this.closeMenu();
this.button.focus(); this.button.focus();
break; break;
} }
return false; return false;
} }
else { else {
switch(keyCode) { switch (keyCode) {
// Open menu and focus on last element of list above it. // Open menu and focus on last element of list above it.
case KEY.ENTER: case KEY.ENTER:
case KEY.SPACE: case KEY.SPACE:
case KEY.UP: case KEY.UP:
this.openMenu(); this.openMenu();
this.menuItemsLinks.last().focus(); this.menuItemsLinks.last().focus();
break; break;
// Close menu. // Close menu.
case KEY.ESCAPE: case KEY.ESCAPE:
this.closeMenu(); this.closeMenu();
break; break;
} }
// We do not stop propagation and default behavior on a TAB // We do not stop propagation and default behavior on a TAB
// keypress. // keypress.
return event.keyCode === KEY.TAB; return event.keyCode === KEY.TAB;
} }
    },      },
setValue: function(value) { setValue: function(value) {
this.value = value; this.value = value;
......
(function (requirejs, require, define) { (function(requirejs, require, define) {
// VideoControl module. // VideoControl module.
define( define(
'video/04_video_control.js', 'video/04_video_control.js',
[], [],
function () { function() {
// VideoControl() function - what this module "exports". // VideoControl() function - what this module "exports".
return function (state) { return function(state) {
var dfd = $.Deferred(); var dfd = $.Deferred();
state.videoControl = {}; state.videoControl = {};
...@@ -137,7 +136,7 @@ function () { ...@@ -137,7 +136,7 @@ function () {
} }
this.controlState = 'hiding'; this.controlState = 'hiding';
this.videoControl.el.fadeOut(this.videoControl.fadeOutTimeout, function () { this.videoControl.el.fadeOut(this.videoControl.fadeOutTimeout, function() {
_this.controlState = 'invisible'; _this.controlState = 'invisible';
// If the focus was on the video control or the volume control, // If the focus was on the video control or the volume control,
// then we must make sure to close these dialogs. Otherwise, after // then we must make sure to close these dialogs. Otherwise, after
...@@ -156,7 +155,5 @@ function () { ...@@ -156,7 +155,5 @@ function () {
endTime = Math.min(endTime, params.duration); endTime = Math.min(endTime, params.duration);
this.videoControl.vidTimeEl.html(Time.format(params.time) + ' / ' + Time.format(endTime)); this.videoControl.vidTimeEl.html(Time.format(params.time) + ' / ' + Time.format(endTime));
} }
}); });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
(function (requirejs, require, define) { (function(requirejs, require, define) {
// VideoQualityControl module. // VideoQualityControl module.
'use strict'; 'use strict';
define( define(
'video/05_video_quality_control.js', 'video/05_video_quality_control.js',
['edx-ui-toolkit/js/utils/html-utils'], ['edx-ui-toolkit/js/utils/html-utils'],
function (HtmlUtils) { function(HtmlUtils) {
var template = HtmlUtils.interpolateHtml( var template = HtmlUtils.interpolateHtml(
HtmlUtils.HTML([ HtmlUtils.HTML([
'<button class="control quality-control is-hidden" aria-disabled="false" title="', '<button class="control quality-control is-hidden" aria-disabled="false" title="',
'{highDefinition}', '{highDefinition}',
'">', '">',
'<span class="icon icon-hd" aria-hidden="true">HD</span>', '<span class="icon icon-hd" aria-hidden="true">HD</span>',
'<span class="sr text-translation">', '<span class="sr text-translation">',
'{highDefinition}', '{highDefinition}',
'</span>&nbsp;', '</span>&nbsp;',
'<span class="sr control-text">', '<span class="sr control-text">',
'{off}', '{off}',
'</span>', '</span>',
'</button>' '</button>'
].join('')), ].join('')),
{ {
...@@ -27,7 +26,7 @@ function (HtmlUtils) { ...@@ -27,7 +26,7 @@ function (HtmlUtils) {
); );
// VideoQualityControl() function - what this module "exports". // VideoQualityControl() function - what this module "exports".
return function (state) { return function(state) {
var dfd = $.Deferred(); var dfd = $.Deferred();
// Changing quality for now only works for YouTube videos. // Changing quality for now only works for YouTube videos.
...@@ -159,7 +158,6 @@ function (HtmlUtils) { ...@@ -159,7 +158,6 @@ function (HtmlUtils) {
.removeClass('active') .removeClass('active')
.find('.control-text') .find('.control-text')
.text(controlStateStr); .text(controlStateStr);
} }
} }
...@@ -175,7 +173,5 @@ function (HtmlUtils) { ...@@ -175,7 +173,5 @@ function (HtmlUtils) {
this.trigger('videoPlayer.handlePlaybackQualityChange', newQuality); this.trigger('videoPlayer.handlePlaybackQualityChange', newQuality);
} }
}); });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
(function (requirejs, require, define) { (function(requirejs, require, define) {
/* /*
"This is as true in everyday life as it is in battle: we are given one life "This is as true in everyday life as it is in battle: we are given one life
and the decision is ours whether to wait for circumstances to make up our and the decision is ours whether to wait for circumstances to make up our
...@@ -8,16 +7,16 @@ mind, or whether to act, and in acting, to live." ...@@ -8,16 +7,16 @@ mind, or whether to act, and in acting, to live."
*/ */
// VideoProgressSlider module. // VideoProgressSlider module.
define( define(
'video/06_video_progress_slider.js', 'video/06_video_progress_slider.js',
[], [],
function () { function() {
var template = [ var template = [
'<div class="slider" title="', gettext('Video position'), '"></div>' '<div class="slider" title="', gettext('Video position'), '"></div>'
].join(''); ].join('');
// VideoProgressSlider() function - what this module "exports". // VideoProgressSlider() function - what this module "exports".
return function (state) { return function(state) {
var dfd = $.Deferred(); var dfd = $.Deferred();
state.videoProgressSlider = {}; state.videoProgressSlider = {};
...@@ -298,19 +297,19 @@ function () { ...@@ -298,19 +297,19 @@ function () {
var seconds = Math.floor(time), var seconds = Math.floor(time),
minutes = Math.floor(seconds / 60), minutes = Math.floor(seconds / 60),
hours = Math.floor(minutes / 60), hours = Math.floor(minutes / 60),
i18n = function (value, word) { i18n = function(value, word) {
var msg; var msg;
switch(word) { switch (word) {
case 'hour': case 'hour':
msg = ngettext('%(value)s hour', '%(value)s hours', value); msg = ngettext('%(value)s hour', '%(value)s hours', value);
break; break;
case 'minute': case 'minute':
msg = ngettext('%(value)s minute', '%(value)s minutes', value); msg = ngettext('%(value)s minute', '%(value)s minutes', value);
break; break;
case 'second': case 'second':
msg = ngettext('%(value)s second', '%(value)s seconds', value); msg = ngettext('%(value)s second', '%(value)s seconds', value);
break; break;
} }
return interpolate(msg, {'value': value}, true); return interpolate(msg, {'value': value}, true);
}; };
...@@ -319,17 +318,15 @@ function () { ...@@ -319,17 +318,15 @@ function () {
minutes = minutes % 60; minutes = minutes % 60;
if (hours) { if (hours) {
return i18n(hours, 'hour') + ' ' + return i18n(hours, 'hour') + ' ' +
i18n(minutes, 'minute') + ' ' + i18n(minutes, 'minute') + ' ' +
i18n(seconds, 'second'); i18n(seconds, 'second');
} else if (minutes) { } else if (minutes) {
return i18n(minutes, 'minute') + ' ' + return i18n(minutes, 'minute') + ' ' +
i18n(seconds, 'second'); i18n(seconds, 'second');
} }
return i18n(seconds, 'second'); return i18n(seconds, 'second');
} }
}); });
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); }(RequireJS.requirejs, RequireJS.require, RequireJS.define));
(function (define) { (function(define) {
'use strict'; 'use strict';
// VideoVolumeControl module. // VideoVolumeControl module.
define( define(
'video/07_video_volume_control.js', ['edx-ui-toolkit/js/utils/html-utils'], 'video/07_video_volume_control.js', ['edx-ui-toolkit/js/utils/html-utils'],
function (HtmlUtils) { function(HtmlUtils) {
/** /**
* Video volume control module. * Video volume control module.
* @exports video/07_video_volume_control.js * @exports video/07_video_volume_control.js
...@@ -39,30 +39,30 @@ function (HtmlUtils) { ...@@ -39,30 +39,30 @@ function (HtmlUtils) {
videoVolumeControlHtml: HtmlUtils.interpolateHtml( videoVolumeControlHtml: HtmlUtils.interpolateHtml(
HtmlUtils.HTML([ HtmlUtils.HTML([
'<div class="volume" role="application">', '<div class="volume" role="application">',
'<p class="sr instructions" id="volume-instructions">', '<p class="sr instructions" id="volume-instructions">',
'{volumeInstructions}', '{volumeInstructions}',
'</p>', '</p>',
'<button class="control" aria-disabled="false" aria-describedby="volume-instructions"', '<button class="control" aria-disabled="false" aria-describedby="volume-instructions"',
'" aria-expanded="false" title="', '" aria-expanded="false" title="',
'{adjustVideoVolume}', '{adjustVideoVolume}',
'">', '">',
'<span class="icon fa fa-volume-up" aria-hidden="true"></span>', '<span class="icon fa fa-volume-up" aria-hidden="true"></span>',
'</button>', '</button>',
'<div class="volume-slider-container" aria-hidden="true" title="', '<div class="volume-slider-container" aria-hidden="true" title="',
'{adjustVideoVolume}', '{adjustVideoVolume}',
'">', '">',
'<div class="volume-slider" ', '<div class="volume-slider" ',
'role="slider"', 'role="slider"',
'aria-orientation="vertical" ', 'aria-orientation="vertical" ',
'aria-valuemin="0" ', 'aria-valuemin="0" ',
'aria-valuemax="100" ', 'aria-valuemax="100" ',
'aria-valuenow="" ', 'aria-valuenow="" ',
'aria-label="', 'aria-label="',
'{volumeText}', '{volumeText}',
'"></div>', '"></div>',
'</div>', '</div>',
'</div>'].join('')), '</div>'].join('')),
{ {
volumeInstructions: gettext('Click on this button to mute or unmute this video or press UP or DOWN buttons to increase or decrease volume level.'), // eslint-disable-line max-len volumeInstructions: gettext('Click on this button to mute or unmute this video or press UP or DOWN buttons to increase or decrease volume level.'), // eslint-disable-line max-len
adjustVideoVolume: gettext('Adjust video volume'), adjustVideoVolume: gettext('Adjust video volume'),
...@@ -70,7 +70,7 @@ function (HtmlUtils) { ...@@ -70,7 +70,7 @@ function (HtmlUtils) {
} }
), ),
destroy: function () { destroy: function() {
this.volumeSlider.slider('destroy'); this.volumeSlider.slider('destroy');
this.state.el.find('iframe').removeAttr('tabindex'); this.state.el.find('iframe').removeAttr('tabindex');
this.a11y.destroy(); this.a11y.destroy();
...@@ -230,7 +230,7 @@ function (HtmlUtils) { ...@@ -230,7 +230,7 @@ function (HtmlUtils) {
}, },
/** Updates volume slider view. */ /** Updates volume slider view. */
updateSliderView: function (volume) { updateSliderView: function(volume) {
this.volumeSlider.slider('value', volume); this.volumeSlider.slider('value', volume);
this.el.find('.volume-slider') this.el.find('.volume-slider')
.attr('aria-valuenow', volume); .attr('aria-valuenow', volume);
...@@ -259,7 +259,7 @@ function (HtmlUtils) { ...@@ -259,7 +259,7 @@ function (HtmlUtils) {
* Returns current volume state (is it muted or not?). * Returns current volume state (is it muted or not?).
* @return {Boolean} * @return {Boolean}
*/ */
getMuteStatus: function () { getMuteStatus: function() {
return this.getVolume() === 0; return this.getVolume() === 0;
}, },
...@@ -295,12 +295,12 @@ function (HtmlUtils) { ...@@ -295,12 +295,12 @@ function (HtmlUtils) {
* volume level. * volume level.
* @param {Number} volume Volume level. * @param {Number} volume Volume level.
*/ */
checkMuteButtonStatus: function (volume) { checkMuteButtonStatus: function(volume) {
if (volume <= this.min) { if (volume <= this.min) {
this.updateMuteButtonView(true); this.updateMuteButtonView(true);
this.state.el.off('volumechange.is-muted'); this.state.el.off('volumechange.is-muted');
this.state.el.on('volumechange.is-muted', _.once(function () { this.state.el.on('volumechange.is-muted', _.once(function() {
this.updateMuteButtonView(false); this.updateMuteButtonView(false);
}.bind(this))); }.bind(this)));
} }
}, },
...@@ -336,35 +336,35 @@ function (HtmlUtils) { ...@@ -336,35 +336,35 @@ function (HtmlUtils) {
keyCode = event.keyCode; keyCode = event.keyCode;
switch (keyCode) { switch (keyCode) {
case KEY.UP: case KEY.UP:
// Shift + Arrows keyboard shortcut might be used by // Shift + Arrows keyboard shortcut might be used by
// screen readers. In this case, do nothing. // screen readers. In this case, do nothing.
if (event.shiftKey) { if (event.shiftKey) {
return true; return true;
} }
this.increaseVolume(); this.increaseVolume();
return false; return false;
case KEY.DOWN: case KEY.DOWN:
// Shift + Arrows keyboard shortcut might be used by // Shift + Arrows keyboard shortcut might be used by
// screen readers. In this case, do nothing. // screen readers. In this case, do nothing.
if (event.shiftKey) { if (event.shiftKey) {
return true; return true;
} }
this.decreaseVolume(); this.decreaseVolume();
return false; return false;
case KEY.SPACE: case KEY.SPACE:
case KEY.ENTER: case KEY.ENTER:
// Shift + Enter keyboard shortcut might be used by // Shift + Enter keyboard shortcut might be used by
// screen readers. In this case, do nothing. // screen readers. In this case, do nothing.
if (event.shiftKey) { if (event.shiftKey) {
return true; return true;
} }
this.toggleMute(); this.toggleMute();
return false; return false;
} }
return true; return true;
...@@ -374,7 +374,7 @@ function (HtmlUtils) { ...@@ -374,7 +374,7 @@ function (HtmlUtils) {
* Keydown event handler for the volume button. * Keydown event handler for the volume button.
* @param {jquery Event} event * @param {jquery Event} event
*/ */
keyDownButtonHandler: function(event) { keyDownButtonHandler: function(event) {
// ALT key is used to change (alternate) the function of // ALT key is used to change (alternate) the function of
// other pressed keys. In this case, do nothing. // other pressed keys. In this case, do nothing.
if (event.altKey) { if (event.altKey) {
...@@ -385,10 +385,10 @@ function (HtmlUtils) { ...@@ -385,10 +385,10 @@ function (HtmlUtils) {
keyCode = event.keyCode; keyCode = event.keyCode;
switch (keyCode) { switch (keyCode) {
case KEY.ENTER: case KEY.ENTER:
case KEY.SPACE: case KEY.SPACE:
this.toggleMute(); this.toggleMute();
return false; return false;
} }
return true; return true;
...@@ -433,7 +433,7 @@ function (HtmlUtils) { ...@@ -433,7 +433,7 @@ function (HtmlUtils) {
* @param {Number} max Maximum value for the volume slider. * @param {Number} max Maximum value for the volume slider.
* @param {Object} i18n The object containing strings with translations. * @param {Object} i18n The object containing strings with translations.
*/ */
var Accessibility = function (button, min, max, i18n) { var Accessibility = function(button, min, max, i18n) {
this.min = min; this.min = min;
this.max = max; this.max = max;
this.button = button; this.button = button;
...@@ -443,14 +443,14 @@ function (HtmlUtils) { ...@@ -443,14 +443,14 @@ function (HtmlUtils) {
}; };
Accessibility.prototype = { Accessibility.prototype = {
destroy: function () { destroy: function() {
this.liveRegion.remove(); this.liveRegion.remove();
}, },
/** Initializes the module. */ /** Initializes the module. */
initialize: function() { initialize: function() {
this.liveRegion = $('<div />', { this.liveRegion = $('<div />', {
'class': 'sr video-live-region', 'class': 'sr video-live-region',
'aria-hidden': 'false', 'aria-hidden': 'false',
'aria-live': 'polite' 'aria-live': 'polite'
}); });
...@@ -502,7 +502,7 @@ function (HtmlUtils) { ...@@ -502,7 +502,7 @@ function (HtmlUtils) {
* @param {Number} min Minimum value for the volume slider. * @param {Number} min Minimum value for the volume slider.
* @param {Number} max Maximum value for the volume slider. * @param {Number} max Maximum value for the volume slider.
*/ */
var CookieManager = function (min, max) { var CookieManager = function(min, max) {
this.min = min; this.min = min;
this.max = max; this.max = max;
this.cookieName = 'video_player_volume_level'; this.cookieName = 'video_player_volume_level';
......
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