Skip to content

Commit

Permalink
Most of test conversion for es6ification
Browse files Browse the repository at this point in the history
  • Loading branch information
heff authored and mmcc committed Apr 2, 2015
1 parent 2e689f8 commit f298d18
Show file tree
Hide file tree
Showing 69 changed files with 937 additions and 838 deletions.
3 changes: 1 addition & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"exports",
"process",

"PlayerTest",
"TestHelpers",
"q",
"asyncTest",
"deepEqual",
"equal",
Expand Down
8 changes: 2 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = function(grunt) {
es6: ['test/es6.html']
},
watch: {
files: [ 'src/**/*', 'test/unit/*.js', 'Gruntfile.js' ],
files: [ 'src/**/*', 'test/unit/**/*.js', 'Gruntfile.js' ],
tasks: 'dev'
},
connect: {
Expand Down Expand Up @@ -445,16 +445,12 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-browserify');

// grunt.loadTasks('./docs/tasks/');
// grunt.loadTasks('../videojs-doc-generator/tasks/');

grunt.registerTask('pretask', ['jshint', 'less', 'vjslanguages', 'build', 'usebanner', 'uglify']);
// Default task.
grunt.registerTask('default', ['pretask', 'dist']);
// Development watch task
grunt.registerTask('dev', ['jshint', 'less', 'vjslanguages', 'build', 'usebanner', 'qunit:source']);
grunt.registerTask('dev', ['jshint', 'less', 'vjslanguages', 'browserify:dist', 'usebanner', 'karma:chrome']);
grunt.registerTask('test-qunit', ['pretask', 'qunit']);
grunt.registerTask('test-es6', ['browserify:test', 'qunit:es6']);

grunt.registerTask('dist', 'Creating distribution', ['dist-copy', 'zip:dist']);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"grunt-contrib-connect": "~0.7.1",
"grunt-contrib-copy": "~0.3.2",
"grunt-contrib-cssmin": "~0.6.0",
"grunt-contrib-jshint": "~0.11.0",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-less": "~0.6.4",
"grunt-contrib-qunit": "~0.2.1",
"grunt-contrib-uglify": "^0.8.0",
Expand Down
14 changes: 7 additions & 7 deletions src/js/button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from './component';
import * as VjsLib from './lib';
import * as VjsEvents from './events';
import * as Lib from './lib';
import * as Events from './events';
import document from 'global/document';

/* Button - Base class for all buttons
Expand Down Expand Up @@ -33,7 +33,7 @@ Component.registerComponent('Button', Button);

Button.prototype.createEl = function(type, props){
// Add standard Aria and Tabindex info
props = VjsLib.obj.merge({
props = Lib.obj.merge({
className: this.buildCSSClass(),
'role': 'button',
'aria-live': 'polite', // let the screen reader user know that the text of the button may change
Expand All @@ -44,11 +44,11 @@ Button.prototype.createEl = function(type, props){

// if innerHTML hasn't been overridden (bigPlayButton), add content elements
if (!props.innerHTML) {
this.contentEl_ = VjsLib.createEl('div', {
this.contentEl_ = Lib.createEl('div', {
className: 'vjs-control-content'
});

this.controlText_ = VjsLib.createEl('span', {
this.controlText_ = Lib.createEl('span', {
className: 'vjs-control-text',
innerHTML: this.localize(this.buttonText) || 'Need Text'
});
Expand All @@ -70,7 +70,7 @@ Button.prototype.onClick = function(){};

// Focus - Add keyboard functionality to element
Button.prototype.onFocus = function(){
VjsEvents.on(document, 'keydown', VjsLib.bind(this, this.onKeyPress));
Events.on(document, 'keydown', Lib.bind(this, this.onKeyPress));
};

// KeyPress (document level) - Trigger click when keys are pressed
Expand All @@ -84,7 +84,7 @@ Button.prototype.onKeyPress = function(event){

// Blur - Remove keyboard triggers
Button.prototype.onBlur = function(){
VjsEvents.off(document, 'keydown', VjsLib.bind(this, this.onKeyPress));
Events.off(document, 'keydown', Lib.bind(this, this.onKeyPress));
};

export default Button;
73 changes: 39 additions & 34 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

import CoreObject from './core-object.js';
import * as VjsLib from './lib.js';
import * as Lib from './lib.js';
import * as VjsUtil from './util.js';
import * as VjsEvents from './events.js';
import * as Events from './events.js';
import window from 'global/window';

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ var Component = CoreObject.extend({
this.player_ = player;

// Make a copy of prototype.options_ to protect against overriding global defaults
this.options_ = VjsLib.obj.copy(this.options_);
this.options_ = Lib.obj.copy(this.options_);

// Updated options with supplied options
options = this.options(options);
Expand All @@ -59,7 +59,7 @@ var Component = CoreObject.extend({
// If there was no ID from the options, generate one
if (!this.id_) {
// Don't require the player ID function in the case of mock players
this.id_ = ((player.id && player.id()) || 'no_player') + '_component_' + VjsLib.guid++;
this.id_ = ((player.id && player.id()) || 'no_player') + '_component_' + Lib.guid++;
}

this.name_ = options['name'] || null;
Expand Down Expand Up @@ -112,7 +112,7 @@ Component.prototype.dispose = function(){
this.el_.parentNode.removeChild(this.el_);
}

VjsLib.removeData(this.el_);
Lib.removeData(this.el_);
this.el_ = null;
};

Expand Down Expand Up @@ -204,7 +204,7 @@ Component.prototype.el_;
* @return {Element}
*/
Component.prototype.createEl = function(tagName, attributes){
return VjsLib.createEl(tagName, attributes);
return Lib.createEl(tagName, attributes);
};

Component.prototype.localize = function(string){
Expand Down Expand Up @@ -372,11 +372,13 @@ Component.prototype.addChild = function(child, options){
let componentName = child;

// Make sure options is at least an empty object to protect against errors
options = options || {};
if (!options || options === true) {
options = {};
}

// If no componentClass in options, assume componentClass is the name lowercased
// (e.g. playButton)
let componentClassName = options['componentClass'] || VjsLib.capitalize(componentName);
let componentClassName = options['componentClass'] || Lib.capitalize(componentName);

// Set name through options
options['name'] = componentName;
Expand All @@ -386,6 +388,7 @@ Component.prototype.addChild = function(child, options){
// Closure Compiler throws an 'incomplete alias' warning if we use the vjs variable directly.
// Every class should be exported, so this should never be a problem here.
let componentClass = Component.getComponent(componentClassName);

component = new componentClass(this.player_ || this, options);

// child is a component instance
Expand Down Expand Up @@ -511,7 +514,7 @@ Component.prototype.initChildren = function(){
};

// Allow for an array of children details to passed in the options
if (VjsLib.obj.isArray(children)) {
if (Lib.obj.isArray(children)) {
for (var i = 0; i < children.length; i++) {
let child = children[i];

Expand All @@ -529,7 +532,7 @@ Component.prototype.initChildren = function(){
handleAdd(name, opts);
}
} else {
VjsLib.obj.each(children, handleAdd);
Lib.obj.each(children, handleAdd);
}
}
};
Expand Down Expand Up @@ -583,14 +586,14 @@ Component.prototype.buildCSSClass = function(){
Component.prototype.on = function(first, second, third){
var target, type, fn, removeOnDispose, cleanRemover, thisComponent;

if (typeof first === 'string' || VjsLib.obj.isArray(first)) {
VjsEvents.on(this.el_, first, VjsLib.bind(this, second));
if (typeof first === 'string' || Lib.obj.isArray(first)) {
Events.on(this.el_, first, Lib.bind(this, second));

// Targeting another component or element
} else {
target = first;
type = second;
fn = VjsLib.bind(this, third);
fn = Lib.bind(this, third);
thisComponent = this;

// When this component is disposed, remove the listener from the other component
Expand All @@ -614,8 +617,8 @@ Component.prototype.on = function(first, second, third){
// Check if this is a DOM node
if (first.nodeName) {
// Add the listener to the other element
VjsEvents.on(target, type, fn);
VjsEvents.on(target, 'dispose', cleanRemover);
Events.on(target, type, fn);
Events.on(target, 'dispose', cleanRemover);

// Should be a component
// Not using `instanceof vjs.Component` because it makes mock players difficult
Expand Down Expand Up @@ -652,23 +655,23 @@ Component.prototype.on = function(first, second, third){
Component.prototype.off = function(first, second, third){
var target, otherComponent, type, fn, otherEl;

if (!first || typeof first === 'string' || VjsLib.obj.isArray(first)) {
VjsEvents.off(this.el_, first, second);
if (!first || typeof first === 'string' || Lib.obj.isArray(first)) {
Events.off(this.el_, first, second);
} else {
target = first;
type = second;
// Ensure there's at least a guid, even if the function hasn't been used
fn = VjsLib.bind(this, third);
fn = Lib.bind(this, third);

// Remove the dispose listener on this component,
// which was given the same guid as the event listener
this.off('dispose', fn);

if (first.nodeName) {
// Remove the listener
VjsEvents.off(target, type, fn);
Events.off(target, type, fn);
// Remove the listener for cleaning the dispose listener
VjsEvents.off(target, 'dispose', fn);
Events.off(target, 'dispose', fn);
} else {
target.off(type, fn);
target.off('dispose', fn);
Expand Down Expand Up @@ -697,12 +700,12 @@ Component.prototype.off = function(first, second, third){
Component.prototype.one = function(first, second, third) {
var target, type, fn, thisComponent, newFunc;

if (typeof first === 'string' || VjsLib.obj.isArray(first)) {
VjsEvents.one(this.el_, first, VjsLib.bind(this, second));
if (typeof first === 'string' || Lib.obj.isArray(first)) {
Events.one(this.el_, first, Lib.bind(this, second));
} else {
target = first;
type = second;
fn = VjsLib.bind(this, third);
fn = Lib.bind(this, third);
thisComponent = this;

newFunc = function(){
Expand All @@ -728,7 +731,7 @@ Component.prototype.one = function(first, second, third) {
* @return {vjs.Component} self
*/
Component.prototype.trigger = function(event){
VjsEvents.trigger(this.el_, event);
Events.trigger(this.el_, event);
return this;
};

Expand Down Expand Up @@ -820,7 +823,7 @@ Component.prototype.triggerReady = function(){
* @return {vjs.Component}
*/
Component.prototype.hasClass = function(classToCheck){
return VjsLib.hasClass(this.el_, classToCheck);
return Lib.hasClass(this.el_, classToCheck);
};

/**
Expand All @@ -830,7 +833,7 @@ Component.prototype.hasClass = function(classToCheck){
* @return {vjs.Component}
*/
Component.prototype.addClass = function(classToAdd){
VjsLib.addClass(this.el_, classToAdd);
Lib.addClass(this.el_, classToAdd);
return this;
};

Expand All @@ -841,7 +844,7 @@ Component.prototype.addClass = function(classToAdd){
* @return {vjs.Component}
*/
Component.prototype.removeClass = function(classToRemove){
VjsLib.removeClass(this.el_, classToRemove);
Lib.removeClass(this.el_, classToRemove);
return this;
};

Expand Down Expand Up @@ -966,7 +969,8 @@ Component.prototype.dimensions = function(width, height){
*/
Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
if (num !== undefined) {
if (num === null || isNaN(num)) {
// Set to zero if null or literally NaN (NaN !== NaN)
if (num === null || num !== num) {
num = 0;
}

Expand Down Expand Up @@ -1002,7 +1006,7 @@ Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
// TODO: handle display:none and no dimension style using px
} else {

return parseInt(this.el_['offset'+VjsLib.capitalize(widthOrHeight)], 10);
return parseInt(this.el_['offset'+Lib.capitalize(widthOrHeight)], 10);

// ComputedStyle version.
// Only difference is if the element is hidden it will return
Expand Down Expand Up @@ -1053,7 +1057,7 @@ Component.prototype.emitTapEvents = function(){
this.on('touchstart', function(event) {
// If more than one finger, don't consider treating this as a click
if (event.touches.length === 1) {
firstTouch = VjsLib.obj.copy(event.touches[0]);
firstTouch = Lib.obj.copy(event.touches[0]);
// Record start time so we can detect a tap vs. "touch and hold"
touchStart = new Date().getTime();
// Reset couldBeTap tracking
Expand Down Expand Up @@ -1136,7 +1140,7 @@ Component.prototype.enableTouchActivity = function() {
}

// listener for reporting that the user is active
report = VjsLib.bind(this.player(), this.player().reportUserActivity);
report = Lib.bind(this.player(), this.player().reportUserActivity);

this.on('touchstart', function() {
report();
Expand Down Expand Up @@ -1166,7 +1170,7 @@ Component.prototype.enableTouchActivity = function() {
* @return {Number} Returns the timeout ID
*/
Component.prototype.setTimeout = function(fn, timeout) {
fn = VjsLib.bind(this, fn);
fn = Lib.bind(this, fn);

// window.setTimeout would be preferable here, but due to some bizarre issue with Sinon and/or Phantomjs, we can't.
var timeoutId = setTimeout(fn, timeout);
Expand Down Expand Up @@ -1206,7 +1210,7 @@ Component.prototype.clearTimeout = function(timeoutId) {
* @return {Number} Returns the interval ID
*/
Component.prototype.setInterval = function(fn, interval) {
fn = VjsLib.bind(this, fn);
fn = Lib.bind(this, fn);

var intervalId = setInterval(fn, interval);

Expand Down Expand Up @@ -1250,9 +1254,10 @@ Component.getComponent = function(name){
}

if (window && window.videojs && window.videojs[name]) {
VjsLib.log.warn('The '+name+' component was added to the videojs object when it should be registered using videojs.registerComponent');
Lib.log.warn('The '+name+' component was added to the videojs object when it should be registered using videojs.registerComponent');
return window.videojs[name];
}
};

Component.registerComponent('Component', Component);
export default Component;
5 changes: 3 additions & 2 deletions src/js/control-bar/control-bar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Component from '../component';
import * as VjsLib from '../lib';
import * as Lib from '../lib';

import PlayToggle from './play-toggle';
import CurrentTimeDisplay from './time-display';
import LiveDisplay from './live-display';
import ProgressControl from './progress-control';
import FullscreenToggle from './fullscreen-toggle';
import VolumeControl from './volume-control';
import VolumeMenuButton from './volume-menu-button';
import MuteToggle from './mute-toggle';
import PlaybackRateMenuButton from './playback-rate-menu-button';

Expand Down Expand Up @@ -44,7 +45,7 @@ ControlBar.prototype.options_ = {
};

ControlBar.prototype.createEl = function(){
return VjsLib.createEl('div', {
return Lib.createEl('div', {
className: 'vjs-control-bar'
});
};
Loading

0 comments on commit f298d18

Please sign in to comment.