Skip to content

Commit 0802d3f

Browse files
committed
chore: Convert the JS files from require JS to ES6 import
1 parent 596d515 commit 0802d3f

40 files changed

Lines changed: 8788 additions & 8900 deletions

webpack.common.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ module.exports = Merge.smart({
139139
ReactRenderer: './common/static/js/src/ReactRenderer.jsx',
140140
XModuleShim: './xmodule/js/src/xmodule.js',
141141
VerticalStudentView: './xmodule/assets/vertical/public/js/vertical_student_view.js',
142+
VideoBlockMain: './xmodule/assets/video/public/js/10_main.js',
142143
commons: 'babel-polyfill'
143144
},
144145

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,52 @@
1-
(function(define) {
2-
define(
3-
'video/00_async_process.js',
4-
[],
5-
function() {
6-
'use strict';
7-
8-
/**
1+
'use strict';
2+
3+
/**
94
* Provides convenient way to process big amount of data without UI blocking.
105
*
116
* @param {array} list Array to process.
127
* @param {function} process Calls this function on each item in the list.
138
* @return {array} Returns a Promise object to observe when all actions of a
149
* certain type bound to the collection, queued or not, have finished.
1510
*/
16-
var AsyncProcess = {
17-
array: function(list, process) {
18-
if (!_.isArray(list)) {
19-
return $.Deferred().reject().promise();
20-
}
21-
22-
if (!_.isFunction(process) || !list.length) {
23-
return $.Deferred().resolve(list).promise();
24-
}
25-
26-
var MAX_DELAY = 50, // maximum amount of time that js code should be allowed to run continuously
27-
dfd = $.Deferred(),
28-
result = [],
29-
index = 0,
30-
len = list.length;
31-
32-
var getCurrentTime = function() {
33-
return (new Date()).getTime();
34-
};
35-
36-
var handler = function() {
37-
var start = getCurrentTime();
38-
39-
do {
40-
result[index] = process(list[index], index);
41-
index++;
42-
} while (index < len && getCurrentTime() - start < MAX_DELAY);
43-
44-
if (index < len) {
45-
setTimeout(handler, 25);
46-
} else {
47-
dfd.resolve(result);
48-
}
49-
};
50-
51-
setTimeout(handler, 25);
52-
53-
return dfd.promise();
54-
}
55-
};
56-
57-
return AsyncProcess;
58-
});
59-
}(RequireJS.define));
11+
let AsyncProcess = {
12+
array: function(list, process) {
13+
if (!_.isArray(list)) {
14+
return $.Deferred().reject().promise();
15+
}
16+
17+
if (!_.isFunction(process) || !list.length) {
18+
return $.Deferred().resolve(list).promise();
19+
}
20+
21+
let MAX_DELAY = 50, // maximum amount of time that js code should be allowed to run continuously
22+
dfd = $.Deferred();
23+
let result = [];
24+
let index = 0;
25+
let len = list.length;
26+
27+
let getCurrentTime = function() {
28+
return (new Date()).getTime();
29+
};
30+
31+
let handler = function() {
32+
let start = getCurrentTime();
33+
34+
do {
35+
result[index] = process(list[index], index);
36+
index++;
37+
} while (index < len && getCurrentTime() - start < MAX_DELAY);
38+
39+
if (index < len) {
40+
setTimeout(handler, 25);
41+
} else {
42+
dfd.resolve(result);
43+
}
44+
};
45+
46+
setTimeout(handler, 25);
47+
48+
return dfd.promise();
49+
}
50+
};
51+
52+
export default AsyncProcess;
Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,81 @@
1-
(function(define) {
2-
'use strict';
1+
'use strict';
32

4-
define('video/00_component.js', [],
5-
function() {
6-
/**
7-
* Creates a new object with the specified prototype object and properties.
8-
* @param {Object} o The object which should be the prototype of the
9-
* newly-created object.
10-
* @private
11-
* @throws {TypeError, Error}
12-
* @return {Object}
13-
*/
14-
var inherit = Object.create || (function() {
15-
var F = function() {};
3+
import _ from 'underscore';
4+
import $ from 'jquery';
165

17-
return function(o) {
18-
if (arguments.length > 1) {
19-
throw Error('Second argument not supported');
20-
}
21-
if (_.isNull(o) || _.isUndefined(o)) {
22-
throw Error('Cannot set a null [[Prototype]]');
23-
}
24-
if (!_.isObject(o)) {
25-
throw TypeError('Argument must be an object');
26-
}
6+
/**
7+
* Creates a new object with the specified prototype object and properties.
8+
* @param {Object} o The object which should be the prototype of the
9+
* newly-created object.
10+
* @private
11+
* @throws {TypeError, Error}
12+
* @return {Object}
13+
*/
14+
let inherit = Object.create || (function() {
15+
let F = function() {};
2716

28-
F.prototype = o;
17+
return function(o) {
18+
if (arguments.length > 1) {
19+
throw Error('Second argument not supported');
20+
}
21+
if (_.isNull(o) || _.isUndefined(o)) {
22+
throw Error('Cannot set a null [[Prototype]]');
23+
}
24+
if (!_.isObject(o)) {
25+
throw TypeError('Argument must be an object');
26+
}
2927

30-
return new F();
31-
};
32-
}());
28+
F.prototype = o;
3329

34-
/**
35-
* Component module.
36-
* @exports video/00_component.js
37-
* @constructor
38-
* @return {jquery Promise}
39-
*/
40-
var Component = function() {
41-
if ($.isFunction(this.initialize)) {
42-
// eslint-disable-next-line prefer-spread
43-
return this.initialize.apply(this, arguments);
44-
}
45-
};
30+
return new F();
31+
};
32+
}());
4633

47-
/**
48-
* Returns new constructor that inherits form the current constructor.
49-
* @static
50-
* @param {Object} protoProps The object containing which will be added to
51-
* the prototype.
52-
* @return {Object}
53-
*/
54-
Component.extend = function(protoProps, staticProps) {
55-
var Parent = this,
56-
Child = function() {
57-
if ($.isFunction(this.initialize)) {
58-
// eslint-disable-next-line prefer-spread
59-
return this.initialize.apply(this, arguments);
60-
}
61-
};
34+
/**
35+
* Component module.
36+
* @exports video/00_component.js
37+
* @constructor
38+
* @return {jquery Promise}
39+
*/
40+
let Component = function() {
41+
if ($.isFunction(this.initialize)) {
42+
// eslint-disable-next-line prefer-spread
43+
return this.initialize.apply(this, arguments);
44+
}
45+
};
6246

63-
// Inherit methods and properties from the Parent prototype.
64-
Child.prototype = inherit(Parent.prototype);
65-
Child.constructor = Parent;
66-
// Provide access to parent's methods and properties
67-
Child.__super__ = Parent.prototype;
47+
/**
48+
* Returns new constructor that inherits form the current constructor.
49+
* @static
50+
* @param {Object} protoProps The object containing which will be added to
51+
* the prototype.
52+
* @return {Object}
53+
*/
54+
Component.extend = function(protoProps, staticProps) {
55+
let Parent = this;
56+
let Child = function() {
57+
if ($.isFunction(this.initialize)) {
58+
// eslint-disable-next-line prefer-spread
59+
return this.initialize.apply(this, arguments);
60+
}
61+
};
6862

69-
// Extends inherited methods and properties by methods/properties
70-
// passed as argument.
71-
if (protoProps) {
72-
$.extend(Child.prototype, protoProps);
73-
}
63+
// Inherit methods and properties from the Parent prototype.
64+
Child.prototype = inherit(Parent.prototype);
65+
Child.constructor = Parent;
66+
// Provide access to parent's methods and properties
67+
Child.__super__ = Parent.prototype;
7468

75-
// Inherit static methods and properties
76-
$.extend(Child, Parent, staticProps);
69+
// Extends inherited methods and properties by methods/properties
70+
// passed as argument.
71+
if (protoProps) {
72+
$.extend(Child.prototype, protoProps);
73+
}
7774

78-
return Child;
79-
};
75+
// Inherit static methods and properties
76+
$.extend(Child, Parent, staticProps);
8077

81-
return Component;
82-
});
83-
}(RequireJS.define));
78+
return Child;
79+
};
80+
81+
export default Component;
Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
1-
(function(define) {
2-
'use strict';
1+
'use strict';
32

4-
define(
5-
'video/00_i18n.js',
6-
[],
7-
function() {
8-
/**
9-
* i18n module.
10-
* @exports video/00_i18n.js
11-
* @return {object}
12-
*/
3+
/**
4+
* i18n module.
5+
* @exports video/00_i18n.js
6+
* @return {object}
7+
*/
138

14-
return {
15-
Play: gettext('Play'),
16-
Pause: gettext('Pause'),
17-
Mute: gettext('Mute'),
18-
Unmute: gettext('Unmute'),
19-
'Exit full browser': gettext('Exit full browser'),
20-
'Fill browser': gettext('Fill browser'),
21-
Speed: gettext('Speed'),
22-
'Auto-advance': gettext('Auto-advance'),
23-
Volume: gettext('Volume'),
24-
// Translators: Volume level equals 0%.
25-
Muted: gettext('Muted'),
26-
// Translators: Volume level in range ]0,20]%
27-
'Very low': gettext('Very low'),
28-
// Translators: Volume level in range ]20,40]%
29-
Low: gettext('Low'),
30-
// Translators: Volume level in range ]40,60]%
31-
Average: gettext('Average'),
32-
// Translators: Volume level in range ]60,80]%
33-
Loud: gettext('Loud'),
34-
// Translators: Volume level in range ]80,99]%
35-
'Very loud': gettext('Very loud'),
36-
// Translators: Volume level equals 100%.
37-
Maximum: gettext('Maximum')
38-
};
39-
});
40-
}(RequireJS.define));
9+
let i18n = {
10+
Play: gettext('Play'),
11+
Pause: gettext('Pause'),
12+
Mute: gettext('Mute'),
13+
Unmute: gettext('Unmute'),
14+
'Exit full browser': gettext('Exit full browser'),
15+
'Fill browser': gettext('Fill browser'),
16+
Speed: gettext('Speed'),
17+
'Auto-advance': gettext('Auto-advance'),
18+
Volume: gettext('Volume'),
19+
// Translators: Volume level equals 0%.
20+
Muted: gettext('Muted'),
21+
// Translators: Volume level in range ]0,20]%
22+
'Very low': gettext('Very low'),
23+
// Translators: Volume level in range ]20,40]%
24+
Low: gettext('Low'),
25+
// Translators: Volume level in range ]40,60]%
26+
Average: gettext('Average'),
27+
// Translators: Volume level in range ]60,80]%
28+
Loud: gettext('Loud'),
29+
// Translators: Volume level in range ]80,99]%
30+
'Very loud': gettext('Very loud'),
31+
// Translators: Volume level equals 100%.
32+
Maximum: gettext('Maximum')
33+
};
34+
35+
export default i18n;

0 commit comments

Comments
 (0)