-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (69 loc) · 2.79 KB
/
script.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
document.addEventListener('DOMContentLoaded', function () {
var modal = document.getElementById('modal');
var closeModal = document.querySelector('.close');
var modalIframe = document.getElementById('modal-iframe');
// YouTube API script
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var players = {};
function createYouTubePlayer(videoId) {
return new YT.Player(videoId, {
height: '360',
width: '640',
videoId: videoId,
events: {
// Add any events you need
},
});
}
function stopYouTubeVideo() {
modalIframe.src = '';
}
// Get all website project boxes
var websiteProjectBoxes = document.querySelectorAll('#web .project');
websiteProjectBoxes.forEach(function (box) {
box.addEventListener('click', function () {
var projectLink = box.querySelector('a');
modalIframe.src = projectLink.href;
modal.style.display = 'block';
});
});
// Get all software project boxes
var softwareProjectBoxes = document.querySelectorAll('#software .project');
softwareProjectBoxes.forEach(function (box) {
box.addEventListener('click', function () {
var videoId = box.querySelector('.video-popup').getAttribute('data-video-id');
modalIframe.src = 'https://www.youtube.com/embed/' + videoId;
modal.style.display = 'block';
if (!players[videoId]) {
players[videoId] = createYouTubePlayer(videoId);
}
});
});
// Close the modal when clicking the close button
closeModal.addEventListener('click', function () {
modal.style.display = 'none';
stopYouTubeVideo();
});
// Close the modal and stop the video when clicking outside the modal content
window.addEventListener('click', function (event) {
if (event.target === modal) {
modal.style.display = 'none';
stopYouTubeVideo();
}
});
// Get all video game project boxes
var videoGameProjectBoxes = document.querySelectorAll('#games .project');
videoGameProjectBoxes.forEach(function (box) {
box.addEventListener('click', function () {
var videoId = box.querySelector('.video-popup').getAttribute('data-video-id');
modalIframe.src = 'https://www.youtube.com/embed/' + videoId;
modal.style.display = 'block';
if (!players[videoId]) {
players[videoId] = createYouTubePlayer(videoId);
}
});
});
});