Commit 5f5a77ac by ataki

Add comment, refactor, handle edge cases

parent 27d3d034
...@@ -62,15 +62,24 @@ function() { ...@@ -62,15 +62,24 @@ function() {
}; };
function filter(start, end) { 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 filteredTimes = [];
var filteredCaptions = []; var filteredCaptions = [];
var startTimes = getStartTimes(); var startTimes = getStartTimes();
var captions = getCaptions(); var captions = getCaptions();
var currentStartTime;
var i;
if (startTimes.length !== captions.length) { 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 // if end is null, then it's been set to
...@@ -80,17 +89,16 @@ function() { ...@@ -80,17 +89,16 @@ function() {
end = startTimes[startTimes.length - 1]; end = startTimes[startTimes.length - 1];
} }
for (i = 0; i < startTimes.length; i++) { _.filter(startTimes, function(currentStartTime, i) {
currentStartTime = startTimes[i]; if (currentStartTime >= start && currentStartTime <= end) {
if (currentStartTime >= start && currentStartTime <= end) { filteredTimes.push(currentStartTime);
filteredTimes.push(currentStartTime); filteredCaptions.push(captions[i]);
filteredCaptions.push(captions[i]); }
} });
}
return { return {
'start': filteredTimes, 'start': filteredTimes,
'captions': filteredCaptions 'captions': filteredCaptions
}; };
} }
......
...@@ -818,7 +818,7 @@ function (HTML5Video, Resizer) { ...@@ -818,7 +818,7 @@ function (HTML5Video, Resizer) {
endTime = this.videoPlayer.duration(), endTime = this.videoPlayer.duration(),
youTubeId; youTubeId;
if (this.config.endTime !== null) { if (this.config.endTime) {
endTime = Math.min(this.config.endTime, endTime); endTime = Math.min(this.config.endTime, endTime);
} }
......
...@@ -166,7 +166,7 @@ function () { ...@@ -166,7 +166,7 @@ function () {
var time = ui.value, var time = ui.value,
endTime = this.videoPlayer.duration(); endTime = this.videoPlayer.duration();
if (this.config.endTime !== null) { if (this.config.endTime) {
endTime = Math.min(this.config.endTime, 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