pročištění kodu
This commit is contained in:
45
js/video.js
45
js/video.js
@@ -2,18 +2,10 @@ class VideoPlayer {
|
||||
constructor() {
|
||||
this.video = document.getElementById("video");
|
||||
|
||||
this.video.addEventListener(
|
||||
"loadedmetadata",
|
||||
function () {
|
||||
this.init();
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
// Init
|
||||
init() {
|
||||
this.enableCustomControls();
|
||||
this.addEventListeners();
|
||||
}
|
||||
|
||||
updateVideoDuration() {
|
||||
this.videoDuration = Math.round(this.video.duration);
|
||||
|
||||
const seek = document.getElementById("seek");
|
||||
@@ -22,36 +14,7 @@ class VideoPlayer {
|
||||
const progressBar = document.getElementById("progress-bar");
|
||||
progressBar.setAttribute("max", this.videoDuration);
|
||||
}
|
||||
// Přidání listenerů
|
||||
addEventListeners() {
|
||||
const videoControls = document.getElementById("video-controls");
|
||||
const togleButton = document.getElementById("togglePlayIcon");
|
||||
videoControls.addEventListener(
|
||||
"click",
|
||||
function (e) {
|
||||
if (e.target !== videoControls && e.target !== togleButton) {
|
||||
return;
|
||||
}
|
||||
this.togglePlay();
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.video.addEventListener(
|
||||
"timeupdate",
|
||||
function () {
|
||||
this.updateProgress();
|
||||
}.bind(this)
|
||||
);
|
||||
this.video.addEventListener(
|
||||
"ended",
|
||||
function () {
|
||||
this.showButton();
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
const seek = document.getElementById("seek");
|
||||
seek.addEventListener("input", this.skipAhead);
|
||||
}
|
||||
enableCustomControls() {
|
||||
const video = document.getElementById("video");
|
||||
const videoControls = document.getElementById("video-controls");
|
||||
@@ -109,7 +72,7 @@ class VideoPlayer {
|
||||
playButton.style.display = "none";
|
||||
}
|
||||
}
|
||||
async getVideoDuration() {
|
||||
return Math.round(await this.video.duration);
|
||||
getVideoDuration() {
|
||||
return Math.round(this.video.duration);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user