Added popups
This commit is contained in:
@@ -12,7 +12,8 @@ class Controller {
|
||||
if (videoToLoad != null && videoToLoad != "") {
|
||||
this.model.loadXml(videoToLoad).then(
|
||||
function (v) {
|
||||
let comments = this.model.parseXML(v);
|
||||
this.model.parseXML(v);
|
||||
let comments = this.model.comments;
|
||||
let videoFileName = this.model.getVideoFileName(v);
|
||||
this.view.drawCommentTitles(comments);
|
||||
this.addEventListeners();
|
||||
@@ -66,6 +67,7 @@ class Controller {
|
||||
function () {
|
||||
this.view.videoPlayer.updateProgress();
|
||||
this.getActiveComment();
|
||||
this.getActivePopup();
|
||||
}.bind(this)
|
||||
);
|
||||
video.addEventListener(
|
||||
@@ -152,7 +154,6 @@ class Controller {
|
||||
|
||||
if (this.activeComment !== null) {
|
||||
this.view.activateComment(this.activeComment);
|
||||
console.log(this.model.comments[this.activeComment].text.length);
|
||||
|
||||
for (
|
||||
let i = 0;
|
||||
@@ -167,4 +168,31 @@ class Controller {
|
||||
}
|
||||
this.lastActiveComment = this.activeComment;
|
||||
}
|
||||
|
||||
getActivePopup() {
|
||||
const video = document.getElementById("video");
|
||||
let currentTime = video.currentTime;
|
||||
|
||||
for (let i = 0; i < this.model.popups.length; i++) {
|
||||
if (
|
||||
currentTime >= this.model.popups[i].start &&
|
||||
currentTime <= this.model.popups[i].end
|
||||
) {
|
||||
this.activePopup = i;
|
||||
break;
|
||||
}
|
||||
if (i == this.model.popups.length - 1) {
|
||||
this.activePopup = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.activePopup !== this.lastActivePopup) {
|
||||
if (this.activePopup !== null) {
|
||||
this.view.activatePopup(this.model.popups[this.activePopup].text);
|
||||
} else {
|
||||
this.view.activatePopup(null);
|
||||
}
|
||||
}
|
||||
this.lastActivePopup = this.activePopup;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class Model {
|
||||
let xmlDoc = parser.parseFromString(xml, "text/xml");
|
||||
|
||||
this.comments = [];
|
||||
this.popups = [];
|
||||
|
||||
let comment = xmlDoc.getElementsByTagName("comment");
|
||||
for (let i = 0; i < comment.length; i++) {
|
||||
@@ -16,8 +17,14 @@ class Model {
|
||||
|
||||
this.comments.push(new Comment(start, end, title, text));
|
||||
}
|
||||
let popup = xmlDoc.getElementsByTagName("popup");
|
||||
for (let i = 0; i < popup.length; i++) {
|
||||
let start = popup[i].getElementsByTagName("start")[0].innerHTML;
|
||||
let end = popup[i].getElementsByTagName("end")[0].innerHTML;
|
||||
let text = popup[i].getElementsByTagName("text")[0].innerHTML;
|
||||
|
||||
return this.comments;
|
||||
this.popups.push(new Popup(start, end, text));
|
||||
}
|
||||
}
|
||||
|
||||
getVideoFileName(xml) {
|
||||
|
||||
7
js/popup.js
Normal file
7
js/popup.js
Normal file
@@ -0,0 +1,7 @@
|
||||
class Popup {
|
||||
constructor(start, end, text) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
15
js/view.js
15
js/view.js
@@ -150,6 +150,21 @@ class View {
|
||||
svgDoc.getElementById("path4").style.fill = "#c1c1c1";
|
||||
}
|
||||
}
|
||||
|
||||
activatePopup(text) {
|
||||
let popArea = document.getElementById("popup");
|
||||
|
||||
if (text == null) {
|
||||
popArea.style.removeProperty("right");
|
||||
setTimeout(function () {
|
||||
popArea.innerHTML = text;
|
||||
}, 300);
|
||||
return;
|
||||
}
|
||||
|
||||
popArea.innerHTML = text;
|
||||
popArea.style.right = "0";
|
||||
}
|
||||
/* colorTogglePlaySVG() {
|
||||
var playSVG = document.getElementById("togglePlayIcon");
|
||||
var svgDoc;
|
||||
|
||||
Reference in New Issue
Block a user