Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted remaining text-track modules to full es6 #3130

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 cues to add to the list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment also needs to be updated. cues to be initialized with or something.

* @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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably doesn't understand const.

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