-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwe-are-tommies.js
59 lines (52 loc) · 1.53 KB
/
we-are-tommies.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
export default () => {
// const script = document.querySelector('script[src="https://www.youtube.com/iframe_api"]');
const video = document.querySelector(".video");
// if (!script && video) {
// const tag = document.createElement('script');
// tag.src = 'https://www.youtube.com/iframe_api';
// const firstScriptTag = document.getElementsByTagName('script')[0];
// firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// }
let player;
// eslint-disable-next-line
function onYouTubeIframeAPIReady() {
if (video) {
// eslint-disable-next-line
player = new YT.Player("video", {
events: {
// eslint-disable-next-line
onReady: iframeModal,
},
});
}
}
function iframeModal() {
if (video) {
const container = video.querySelector(".embed-container");
const thumb = video.querySelector(".video_thumb");
const close = video.querySelector(".lines");
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();
};
};