From a3d917f67c61b121fd16f6e78fe3bed3cec6a6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Sat, 30 Jan 2021 00:12:36 +0100 Subject: [PATCH] Oprava bugu - caste prekreslovani closes #7 a closes #6 --- js/controller.js | 50 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) 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; } }