-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
160 lines (146 loc) · 4.95 KB
/
script.js
File metadata and controls
160 lines (146 loc) · 4.95 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
let header = document.getElementsByClassName('header')[0];
let space = document.getElementsByClassName('space')[0];
let h = screen.height - header.offsetHeight - 150;
space.style.height = h + 'px';
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > h || document.documentElement.scrollTop > h) {
header.classList.add('small-header')
} else {
header.classList.remove('small-header')
}
}
let MAX_PROJECT_PICS = 5;
const frame = document.getElementsByClassName('frame')[0];
const project = document.getElementsByClassName('project')[0];
let currentProjKey = "";
let currentImg = 0;
let projectData = {
"scheduleMaker": {
"imgs": [
"assets/scheduleMaker1.JPG"
],
"link": "http://github.com/emilyclam/scheduleMaker",
"title": "Schedule Maker",
"langs": [
"HTML",
"CSS",
"JS"
],
"desc": "A chrome extension that helps you schedule your time. Features a todo list, a timer, and numbers."
},
"leetMon": {
"imgs": [
"assets/leetmon1.gif",
"assets/leetmon2.gif",
"assets/leetmon3.png",
"assets/leetmon4.png",
],
"link": "https://github.com/emilyclam/leetmon",
"title": "LeetMon",
"langs": [
"HTML",
"TypeScript",
],
"desc": "A chrome extension where you catch pokemon when you do LeetCode."
},
"pogoBot": {
"imgs": [
"assets/bot-example.png"
],
"link": "https://github.com/emilyclam/PogoBot",
"title": "PoGo Bot",
"langs": [
"python",
"BeautifulSoup",
"RegEx"
],
"desc": "A discord bot that gives updates about the current and upcoming events in the Pokemon Go app."
},
"recipeBook": {
"imgs": [
"assets/recipebook1.png",
"assets/recipebook2.png",
"assets/recipebook3.png",
"assets/recipebook4.png",
],
"link": "https://github.com/emilyclam/recipe_book",
"title": "Recipe Book",
"langs": [
"React",
"Django",
"Postgres"
],
"desc": "A full-stack web application where users can search, view, and save recipes."
},
}
const imgIndicator = document.getElementById("img-indicators");
let indicators = [];
for (let i = 0; i < MAX_PROJECT_PICS; i++) {
const indicator = document.createElement("div");
indicator.className = 'indicator';
imgIndicator.appendChild(indicator);
indicators.push(indicator);
}
function openFrame(projectKey) {
let fImg = document.querySelector(".frame-img img");
let link = projectData[projectKey]["link"];
let fTitle = document.getElementsByClassName("proj-title")[0];
let fLink = document.querySelector(".proj-header a");
let fLangs = document.getElementsByClassName("languages")[0];
let fDesc = document.getElementsByClassName("description")[0];
const numImgsInProject = projectData[projectKey]["imgs"].length;
fImg.src = projectData[projectKey]["imgs"][0];
fTitle.textContent = projectData[projectKey]["title"];
fLink.href = link;
fLangs.textContent = "";
projectData[projectKey]["langs"].forEach(lang => {
fLangs.insertAdjacentHTML('beforeend', `<li>${lang}</li>`)
});
fDesc.children[1].innerHTML = projectData[projectKey]["desc"];
frame.style.display = "flex";
currentProjKey = projectKey;
currentImg = 0;
for (let i = 0; i < MAX_PROJECT_PICS; i++) {
const indicator = indicators[i];
if (i == 0) {
indicator.classList.add('active');
}
if (i < numImgsInProject) {
indicator.style.display = 'block';
} else {
indicator.style.display = 'none';
}
}
}
function closeFrame() {
frame.style.display = "none";
for (let i = 0; i < MAX_PROJECT_PICS; i++) {
indicators[i].classList = 'indicator';
}
}
function nextImg(direction) {
const fImg = document.querySelector(".frame-img img");
const numImgsInProject = projectData[currentProjKey]["imgs"].length;
indicators[currentImg].classList.remove('active');
currentImg = (currentImg += direction) % numImgsInProject;
if (currentImg < 0) {
currentImg = numImgsInProject-1;
}
fImg.src = projectData[currentProjKey]["imgs"][currentImg];
indicators[currentImg].classList.add('active');
}
let galleryItems = document.getElementsByClassName('gallery-item');
for (let i = 0; i < galleryItems.length; i++) {
galleryItems[i].onclick = () => {
openFrame(galleryItems[i].classList[1]);
}
}
// if the frame is open, you could also close it by clicking anywhere outside the frame
window.addEventListener('mousedown', function(e){
if (frame.style.display == "flex") {
if (!project.contains(e.target)){
closeFrame();
}
}
});