diff --git a/js/controller.js b/js/controller.js index d8b52b8..14809ba 100644 --- a/js/controller.js +++ b/js/controller.js @@ -62,15 +62,21 @@ class Controller { ); const seek = document.getElementById("seek"); - seek.addEventListener("input", function() { - this.view.videoPlayer.skipAhead(seek.value); - }.bind(this)); + seek.addEventListener( + "input", + function () { + this.view.videoPlayer.skipAhead(seek.value); + }.bind(this) + ); - document.addEventListener("keyup", function (e) { - if (e.keyCode == 32) { - this.view.videoPlayer.togglePlay(); - } - }.bind(this)); + document.addEventListener( + "keyup", + function (e) { + if (e.keyCode == 32) { + this.view.videoPlayer.togglePlay(); + } + }.bind(this) + ); } async loadVideo(v) { @@ -101,16 +107,28 @@ class Controller { for (let i = 0; i < this.model.comments.length; i++) { if ( - currentTime > this.model.comments[i].start && - currentTime < this.model.comments[i].end + currentTime >= this.model.comments[i].start && + currentTime <= this.model.comments[i].end ) { - this.view.activateComment(i); - this.view.activateCommentText(this.model.comments[i].fulltext); - return; - } else { - this.view.activateComment(null); - this.view.activateCommentText(null); + this.activeComment = i; + break; + } + if (i == this.model.comments.length - 1) { + this.activeComment = null; + } + } + + if (this.activeComment !== this.lastActiveComment) { + this.view.activateComment(null); + this.view.activateCommentText(null); + + if (this.activeComment !== null) { + this.view.activateComment(this.activeComment); + this.view.activateCommentText( + this.model.comments[this.activeComment].fulltext + ); } } + this.lastActiveComment = this.activeComment; } }