Commit 5f5a77ac by ataki

Add comment, refactor, handle edge cases

parent 27d3d034
......@@ -62,15 +62,24 @@ function() {
};
function filter(start, end) {
/* filters captions that occur between inputs
* `start` and `end`. Start and end should
* be Numbers (doubles) corresponding to the
* number of seconds elapsed since the beginning
* of the video.
*
* Returns an object with properties
* "start" and "captions" representing
* parallel arrays of start times and
* their corresponding captions.
*/
var filteredTimes = [];
var filteredCaptions = [];
var startTimes = getStartTimes();
var captions = getCaptions();
var currentStartTime;
var i;
if (startTimes.length !== captions.length) {
return [];
throw new Exception("video caption and start time arrays do not match in length");
}
// if end is null, then it's been set to
......@@ -80,17 +89,16 @@ function() {
end = startTimes[startTimes.length - 1];
}
for (i = 0; i < startTimes.length; i++) {
currentStartTime = startTimes[i];
if (currentStartTime >= start && currentStartTime <= end) {
filteredTimes.push(currentStartTime);
filteredCaptions.push(captions[i]);
}
}
_.filter(startTimes, function(currentStartTime, i) {
if (currentStartTime >= start && currentStartTime <= end) {
filteredTimes.push(currentStartTime);
filteredCaptions.push(captions[i]);
}
});
return {
'start': filteredTimes,
'captions': filteredCaptions
'start': filteredTimes,
'captions': filteredCaptions
};
}
......
......@@ -818,7 +818,7 @@ function (HTML5Video, Resizer) {
endTime = this.videoPlayer.duration(),
youTubeId;
if (this.config.endTime !== null) {
if (this.config.endTime) {
endTime = Math.min(this.config.endTime, endTime);
}
......
......@@ -166,7 +166,7 @@ function () {
var time = ui.value,
endTime = this.videoPlayer.duration();
if (this.config.endTime !== null) {
if (this.config.endTime) {
endTime = Math.min(this.config.endTime, endTime);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment