Skip to content

Commit

Permalink
videojs-standard Control Bar (#3469)
Browse files Browse the repository at this point in the history
* Remove jshint, install videojs-standard

* Make src/js/*.js pass videojs-standard

* Roll back TODO replacement

* Updates from code review feedback

* Elaborate on unassigned imports

* videojs-standard Control Bar

* const should've been let
  • Loading branch information
misteroneill committed Jul 28, 2016
1 parent 02899b3 commit deddb6b
Show file tree
Hide file tree
Showing 31 changed files with 278 additions and 247 deletions.
9 changes: 4 additions & 5 deletions src/js/control-bar/audio-track-controls/audio-track-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import TrackButton from '../track-button.js';
import Component from '../../component.js';
import * as Fn from '../../utils/fn.js';
import AudioTrackMenuItem from './audio-track-menu-item.js';

/**
Expand Down Expand Up @@ -40,19 +39,19 @@ class AudioTrackButton extends TrackButton {
* @method createItems
*/
createItems(items = []) {
let tracks = this.player_.audioTracks && this.player_.audioTracks();
const tracks = this.player_.audioTracks && this.player_.audioTracks();

if (!tracks) {
return items;
}

for (let i = 0; i < tracks.length; i++) {
let track = tracks[i];
const track = tracks[i];

items.push(new AudioTrackMenuItem(this.player_, {
track,
// MenuItem is selectable
'selectable': true,
'track': track
selectable: true
}));
}

Expand Down
14 changes: 8 additions & 6 deletions src/js/control-bar/audio-track-controls/audio-track-menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import * as Fn from '../../utils/fn.js';
*/
class AudioTrackMenuItem extends MenuItem {
constructor(player, options) {
let track = options.track;
let tracks = player.audioTracks();
const track = options.track;
const tracks = player.audioTracks();

// Modify options for parent MenuItem class's init.
options.label = track.label || track.language || 'Unknown';
Expand All @@ -27,7 +27,7 @@ class AudioTrackMenuItem extends MenuItem {
this.track = track;

if (tracks) {
let changeHandler = Fn.bind(this, this.handleTracksChange);
const changeHandler = Fn.bind(this, this.handleTracksChange);

tracks.addEventListener('change', changeHandler);
this.on('dispose', () => {
Expand All @@ -42,14 +42,16 @@ class AudioTrackMenuItem extends MenuItem {
* @method handleClick
*/
handleClick(event) {
let tracks = this.player_.audioTracks();
const tracks = this.player_.audioTracks();

super.handleClick(event);

if (!tracks) return;
if (!tracks) {
return;
}

for (let i = 0; i < tracks.length; i++) {
let track = tracks[i];
const track = tracks[i];

if (track === this.track) {
track.enabled = true;
Expand Down
39 changes: 20 additions & 19 deletions src/js/control-bar/control-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import Component from '../component.js';

// Required children
import PlayToggle from './play-toggle.js';
import CurrentTimeDisplay from './time-controls/current-time-display.js';
import DurationDisplay from './time-controls/duration-display.js';
import TimeDivider from './time-controls/time-divider.js';
import RemainingTimeDisplay from './time-controls/remaining-time-display.js';
import LiveDisplay from './live-display.js';
import ProgressControl from './progress-control/progress-control.js';
import FullscreenToggle from './fullscreen-toggle.js';
import VolumeControl from './volume-control/volume-control.js';
import VolumeMenuButton from './volume-menu-button.js';
import MuteToggle from './mute-toggle.js';
import ChaptersButton from './text-track-controls/chapters-button.js';
import DescriptionsButton from './text-track-controls/descriptions-button.js';
import SubtitlesButton from './text-track-controls/subtitles-button.js';
import CaptionsButton from './text-track-controls/captions-button.js';
import AudioTrackButton from './audio-track-controls/audio-track-button.js';
import PlaybackRateMenuButton from './playback-rate-menu/playback-rate-menu-button.js';
import CustomControlSpacer from './spacer-controls/custom-control-spacer.js';
import './play-toggle.js';
import './time-controls/current-time-display.js';
import './time-controls/duration-display.js';
import './time-controls/time-divider.js';
import './time-controls/remaining-time-display.js';
import './live-display.js';
import './progress-control/progress-control.js';
import './fullscreen-toggle.js';
import './volume-control/volume-control.js';
import './volume-menu-button.js';
import './mute-toggle.js';
import './text-track-controls/chapters-button.js';
import './text-track-controls/descriptions-button.js';
import './text-track-controls/subtitles-button.js';
import './text-track-controls/captions-button.js';
import './audio-track-controls/audio-track-button.js';
import './playback-rate-menu/playback-rate-menu-button.js';
import './spacer-controls/custom-control-spacer.js';

/**
* Container of main controls
Expand All @@ -42,7 +42,8 @@ class ControlBar extends Component {
className: 'vjs-control-bar',
dir: 'ltr'
}, {
'role': 'group' // The control bar is a group, so it can contain menuitems
// The control bar is a group, so it can contain menuitems
role: 'group'
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/control-bar/live-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LiveDisplay extends Component {
* @method createEl
*/
createEl() {
var el = super.createEl('div', {
const el = super.createEl('div', {
className: 'vjs-live-control vjs-control'
});

Expand Down
20 changes: 11 additions & 9 deletions src/js/control-bar/mute-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class MuteToggle extends Button {
this.on(player, 'volumechange', this.update);

// hide mute toggle if the current tech doesn't support volume control
if (player.tech_ && player.tech_['featuresVolumeControl'] === false) {
if (player.tech_ && player.tech_.featuresVolumeControl === false) {
this.addClass('vjs-hidden');
}

this.on(player, 'loadstart', function() {
this.update(); // We need to update the button to account for a default muted state.
// We need to update the button to account for a default muted state.
this.update();

if (player.tech_['featuresVolumeControl'] === false) {
if (player.tech_.featuresVolumeControl === false) {
this.addClass('vjs-hidden');
} else {
this.removeClass('vjs-hidden');
Expand All @@ -52,7 +53,7 @@ class MuteToggle extends Button {
* @method handleClick
*/
handleClick() {
this.player_.muted( this.player_.muted() ? false : true );
this.player_.muted(this.player_.muted() ? false : true);
}

/**
Expand All @@ -61,8 +62,8 @@ class MuteToggle extends Button {
* @method update
*/
update() {
var vol = this.player_.volume(),
level = 3;
const vol = this.player_.volume();
let level = 3;

if (vol === 0 || this.player_.muted()) {
level = 0;
Expand All @@ -75,13 +76,14 @@ class MuteToggle extends Button {
// Don't rewrite the button text if the actual text doesn't change.
// This causes unnecessary and confusing information for screen reader users.
// This check is needed because this function gets called every time the volume level is changed.
let toMute = this.player_.muted() ? 'Unmute' : 'Mute';
const toMute = this.player_.muted() ? 'Unmute' : 'Mute';

if (this.controlText() !== toMute) {
this.controlText(toMute);
}

/* TODO improve muted icon classes */
for (var i = 0; i < 4; i++) {
// TODO improve muted icon classes
for (let i = 0; i < 4; i++) {
Dom.removeElClass(this.el_, `vjs-vol-${i}`);
}
Dom.addElClass(this.el_, `vjs-vol-${level}`);
Expand Down
8 changes: 5 additions & 3 deletions src/js/control-bar/play-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Component from '../component.js';
*/
class PlayToggle extends Button {

constructor(player, options){
constructor(player, options) {
super(player, options);

this.on(player, 'play', this.handlePlay);
Expand Down Expand Up @@ -52,7 +52,8 @@ class PlayToggle extends Button {
handlePlay() {
this.removeClass('vjs-paused');
this.addClass('vjs-playing');
this.controlText('Pause'); // change the button text to "Pause"
// change the button text to "Pause"
this.controlText('Pause');
}

/**
Expand All @@ -63,7 +64,8 @@ class PlayToggle extends Button {
handlePause() {
this.removeClass('vjs-playing');
this.addClass('vjs-paused');
this.controlText('Play'); // change the button text to "Play"
// change the button text to "Play"
this.controlText('Play');
}

}
Expand Down
27 changes: 14 additions & 13 deletions src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as Dom from '../../utils/dom.js';
*/
class PlaybackRateMenuButton extends MenuButton {

constructor(player, options){
constructor(player, options) {
super(player, options);

this.updateVisibility();
Expand All @@ -34,7 +34,7 @@ class PlaybackRateMenuButton extends MenuButton {
* @method createEl
*/
createEl() {
let el = super.createEl();
const el = super.createEl();

this.labelEl_ = Dom.createEl('div', {
className: 'vjs-playback-rate-value',
Expand Down Expand Up @@ -63,13 +63,13 @@ class PlaybackRateMenuButton extends MenuButton {
* @method createMenu
*/
createMenu() {
let menu = new Menu(this.player());
let rates = this.playbackRates();
const menu = new Menu(this.player());
const rates = this.playbackRates();

if (rates) {
for (let i = rates.length - 1; i >= 0; i--) {
menu.addChild(
new PlaybackRateMenuItem(this.player(), { 'rate': rates[i] + 'x'})
new PlaybackRateMenuItem(this.player(), {rate: rates[i] + 'x'})
);
}
}
Expand All @@ -94,12 +94,13 @@ class PlaybackRateMenuButton extends MenuButton {
*/
handleClick() {
// select next rate option
let currentRate = this.player().playbackRate();
let rates = this.playbackRates();
const currentRate = this.player().playbackRate();
const rates = this.playbackRates();

// this will select first one if the last one currently selected
let newRate = rates[0];
for (let i = 0; i < rates.length ; i++) {

for (let i = 0; i < rates.length; i++) {
if (rates[i] > currentRate) {
newRate = rates[i];
break;
Expand All @@ -115,7 +116,7 @@ class PlaybackRateMenuButton extends MenuButton {
* @method playbackRates
*/
playbackRates() {
return this.options_['playbackRates'] || (this.options_.playerOptions && this.options_.playerOptions['playbackRates']);
return this.options_.playbackRates || (this.options_.playerOptions && this.options_.playerOptions.playbackRates);
}

/**
Expand All @@ -126,10 +127,10 @@ class PlaybackRateMenuButton extends MenuButton {
* @method playbackRateSupported
*/
playbackRateSupported() {
return this.player().tech_
&& this.player().tech_['featuresPlaybackRate']
&& this.playbackRates()
&& this.playbackRates().length > 0
return this.player().tech_ &&
this.player().tech_.featuresPlaybackRate &&
this.playbackRates() &&
this.playbackRates().length > 0
;
}

Expand Down
10 changes: 5 additions & 5 deletions src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import Component from '../../component.js';
*/
class PlaybackRateMenuItem extends MenuItem {

constructor(player, options){
let label = options['rate'];
let rate = parseFloat(label, 10);
constructor(player, options) {
const label = options.rate;
const rate = parseFloat(label, 10);

// Modify options for parent MenuItem class's init.
options['label'] = label;
options['selected'] = rate === 1;
options.label = label;
options.selected = rate === 1;
super(player, options);

this.label = label;
Expand Down
22 changes: 12 additions & 10 deletions src/js/control-bar/progress-control/load-progress-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as Dom from '../../utils/dom.js';
*/
class LoadProgressBar extends Component {

constructor(player, options){
constructor(player, options) {
super(player, options);
this.on(player, 'progress', this.update);
}
Expand All @@ -38,14 +38,16 @@ class LoadProgressBar extends Component {
* @method update
*/
update() {
let buffered = this.player_.buffered();
let duration = this.player_.duration();
let bufferedEnd = this.player_.bufferedEnd();
let children = this.el_.children;
const buffered = this.player_.buffered();
const duration = this.player_.duration();
const bufferedEnd = this.player_.bufferedEnd();
const children = this.el_.children;

// get the percent width of a time compared to the total end
let percentify = function (time, end){
let percent = (time / end) || 0; // no NaN
const percentify = function(time, end) {
// no NaN
const percent = (time / end) || 0;

return ((percent >= 1 ? 1 : percent) * 100) + '%';
};

Expand All @@ -54,8 +56,8 @@ class LoadProgressBar extends Component {

// add child elements to represent the individual buffered time ranges
for (let i = 0; i < buffered.length; i++) {
let start = buffered.start(i);
let end = buffered.end(i);
const start = buffered.start(i);
const end = buffered.end(i);
let part = children[i];

if (!part) {
Expand All @@ -69,7 +71,7 @@ class LoadProgressBar extends Component {

// remove unused buffered range elements
for (let i = children.length; i > buffered.length; i--) {
this.el_.removeChild(children[i-1]);
this.el_.removeChild(children[i - 1]);
}
}

Expand Down
Loading

0 comments on commit deddb6b

Please sign in to comment.