-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (55 loc) · 1.71 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const video = document.getElementById("video");
if (video) {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/player_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
const title = "CMS unique module text title";
const url = "https://www.youtube.com/watch?v=kZu3AYNjmjI";
const urlId = url.split("=")[1];
// console.log(url.split("=")[1]);
let player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("video", {
title: title,
videoId: urlId,
events: {
onReady: iframeModal,
},
});
}
function iframeModal() {
const container = document.querySelector(".embed-container");
const thumb = document.querySelector(".video_thumb");
const close = document.querySelector(".lines");
// const title = player.getVideoData().title;
// console.log(player.getVideoData());
// console.log(title);
const hqdefault = `<img src="https://img.youtube.com/vi/${urlId}/hqdefault.jpg" alt="${title}" />`;
if (thumb) {
thumb.insertAdjacentHTML("afterbegin", hqdefault);
}
thumb.addEventListener("click", () => {
const clicked = container.classList.contains("clicked");
if (!clicked) {
container.classList.add("clicked");
thumb.classList.add("overlay");
close.classList.add("active");
player.playVideo();
}
});
close.addEventListener("click", () => {
const active = close.classList.contains("active");
if (active) {
container.classList.remove("clicked");
thumb.classList.remove("overlay");
close.classList.remove("active");
player.pauseVideo();
}
});
}
}
window.onload = () => {
// onYouTubeIframeAPIReady();
// iframeModal();
};