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