Skip to content

Commit

Permalink
@brandonocasey converted remaining text-track modules to ES6. closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed Feb 29, 2016
1 parent d9a0a45 commit cb3d709
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 402 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

## HEAD (Unreleased)
* @gkatsev updated videojs badges in the README ([view](https://github.com/videojs/video.js/pull/3134))
* @BrandonOCasey converted remaining text-track modules to ES6 ([view](https://github.com/videojs/video.js/pull/3130))

--------------------

Expand Down
120 changes: 71 additions & 49 deletions src/js/tracks/text-track-cue-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,102 @@
import * as browser from '../utils/browser.js';
import document from 'global/document';

/*
/**
* A List of text track cues as defined in:
* https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist
*
* interface TextTrackCueList {
* readonly attribute unsigned long length;
* getter TextTrackCue (unsigned long index);
* TextTrackCue? getCueById(DOMString id);
* };
*
* @param {Array} cues A list of cues to be initialized with
* @class TextTrackCueList
*/

function TextTrackCueList (cues) {
let list = this;
class TextTrackCueList {
constructor(cues) {
let list = this;

if (browser.IS_IE8) {
list = document.createElement('custom');
if (browser.IS_IE8) {
list = document.createElement('custom');

for (let prop in TextTrackCueList.prototype) {
if (prop !== 'constructor') {
list[prop] = TextTrackCueList.prototype[prop];
for (let prop in TextTrackCueList.prototype) {
if (prop !== 'constructor') {
list[prop] = TextTrackCueList.prototype[prop];
}
}
}
}

TextTrackCueList.prototype.setCues_.call(list, cues);
TextTrackCueList.prototype.setCues_.call(list, cues);

Object.defineProperty(list, 'length', {
get: function() {
return this.length_;
}
});
Object.defineProperty(list, 'length', {
get() {
return this.length_;
}
});

if (browser.IS_IE8) {
return list;
if (browser.IS_IE8) {
return list;
}
}
}

TextTrackCueList.prototype.setCues_ = function(cues) {
let oldLength = this.length || 0;
let i = 0;
let l = cues.length;
/**
* A setter for cues in this list
*
* @param {Array} cues an array of cues
* @method setCues_
* @private
*/
setCues_(cues) {
let oldLength = this.length || 0;
let i = 0;
let l = cues.length;

this.cues_ = cues;
this.length_ = cues.length;
this.cues_ = cues;
this.length_ = cues.length;

let defineProp = function(i) {
if (!(''+i in this)) {
Object.defineProperty(this, '' + i, {
get: function() {
return this.cues_[i];
}
});
}
};
let defineProp = function(index) {
if (!('' + index in this)) {
Object.defineProperty(this, '' + index, {
get() {
return this.cues_[index];
}
});
}
};

if (oldLength < l) {
i = oldLength;
if (oldLength < l) {
i = oldLength;

for(; i < l; i++) {
defineProp.call(this, i);
for (; i < l; i++) {
defineProp.call(this, i);
}
}
}
};

TextTrackCueList.prototype.getCueById = function(id) {
let result = null;
for (let i = 0, l = this.length; i < l; i++) {
let cue = this[i];
if (cue.id === id) {
result = cue;
break;

/**
* Get a cue that is currently in the Cue list by id
*
* @param {String} id
* @method getCueById
* @return {Object} a single cue
*/
getCueById(id) {
let result = null;

for (let i = 0, l = this.length; i < l; i++) {
let cue = this[i];

if (cue.id === id) {
result = cue;
break;
}
}
}

return result;
};
return result;
}
}

export default TextTrackCueList;
38 changes: 25 additions & 13 deletions src/js/tracks/text-track-enums.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
/**
* @file text-track-enums.js
*
*/

/**
* https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode
*
* enum TextTrackMode { "disabled", "hidden", "showing" };
*/
var TextTrackMode = {
'disabled': 'disabled',
'hidden': 'hidden',
'showing': 'showing'
const TextTrackMode = {
disabled: 'disabled',
hidden: 'hidden',
showing: 'showing'
};

/*
/**
* https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackkind
*
* enum TextTrackKind { "subtitles", "captions", "descriptions", "chapters", "metadata" };
* enum TextTrackKind {
* "subtitles",
* "captions",
* "descriptions",
* "chapters",
* "metadata"
* };
*/
var TextTrackKind = {
'subtitles': 'subtitles',
'captions': 'captions',
'descriptions': 'descriptions',
'chapters': 'chapters',
'metadata': 'metadata'
const TextTrackKind = {
subtitles: 'subtitles',
captions: 'captions',
descriptions: 'descriptions',
chapters: 'chapters',
metadata: 'metadata'
};

/* jshint ignore:start */
// we ignore jshint here because it does not see
// TextTrackMode or TextTrackKind as defined here somehow...
export { TextTrackMode, TextTrackKind };
/* jshint ignore:end */
Loading

0 comments on commit cb3d709

Please sign in to comment.