-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
248 lines (200 loc) · 7.93 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
let body = document.body;
//for the preloader
var preloader = document.getElementById("preloader");
window.addEventListener("load", ()=>
preloader.style.display = "none"
)
//All the modals
let abtMeModal = document.getElementById("about-me-modal");
let awardsModal = document.getElementById("awards-modal");
let contactModal = document.getElementById("contact-modal");
let projectModal = document.getElementById("project-modal");
let helpModal = document.getElementById("help-modal");
//For the smaller resolution
let welcomeModal = document.getElementById("welcome-modal");
//All the buttons
let continueButton = document.getElementById("resolution-confirmation");
var closeBtns = document.getElementsByClassName("close-Btn");
let abtMeImage = document.getElementById("about-me-image");
let projectImage = document.getElementById("my-projects-image");
let awardsButton = document.getElementById("awards-image");
let contactButton = document.getElementById("contact-image");
var helpButton = document.getElementById("help-btn");
var lowResolution = false;
var highResolution = false;
//get the initial/original resolution
window.onload = getCurrentResolution;
function getCurrentResolution(){
if (window.innerWidth>1100){
highResolution = true;
lowResolution = false;
}
else{
highResolution = false;
lowResolution = true;
}
}
//show the welcome modal only once when the resolution changes
window.onresize = calculateWidth;
function calculateWidth(){
if ((window.innerWidth > 1100) && (highResolution==false)){
welcomeModal.style.display="block";
getCurrentResolution();
}
else if ((window.innerWidth < 1100) && (lowResolution==false)){
welcomeModal.style.display="block";
getCurrentResolution();
}
}
var awardList = document.getElementsByClassName("award-item");
var awardDescriptionContainer = document.getElementsByClassName("item-description")[1];
var projectButtons = document.getElementsByClassName('button');
var projectItems = document.getElementsByClassName('project-item');
addProjectButtonListeners();
initialProjectSetup();
//registering event listeners for award bullets - for their description
addAwardMouseListener();
awardMouseLeave();
//the currently clicked modal, will always be the welcome modal initially
var clickedModal = welcomeModal;
//click events for all the clickable elements
abtMeImage.addEventListener("click", openAbtMeModal);
projectImage.addEventListener("click", openProjectModal)
awardsButton.addEventListener("click", openAwardsModal);
contactButton.addEventListener("click", openContactModal);
helpButton.addEventListener("click", openHelpModal);
continueButton.addEventListener("click", continueAtSmallResolution);
//click event for when clicked outside the modal
window.addEventListener("click", clickedOutsideModal);
//when the modal is open, pressing the escape key will close it
document.addEventListener("keydown", function(e){
if(e.key =="Escape"){
closeModal();
}
});
//close the welcome modal on low res
function continueAtSmallResolution(){
welcomeModal.style.display = "none";
}
//Functions for opening the differnet models and making other components unclickable while the modal is open
function openAbtMeModal(){
clickedModal = abtMeModal;
abtMeModal.style.display = "block";
disableClicks();
}
function openProjectModal(){
clickedModal = projectModal;
projectModal.style.display = "block";
disableClicks();
}
function openHelpModal(){
clickedModal = helpModal;
helpModal.style.display = "block";
disableClicks();
}
function openAwardsModal(){
clickedModal = awardsModal;
awardsModal.style.display = "block";
disableClicks();
}
function openContactModal(){
clickedModal = contactModal;
contactModal.style.display = "block";
disableClicks();
}
//when the modal is closed, clicks for all other clickable components are enabled
function closeModal(){
clickedModal.style.display = "none";
enableClicks();
}
//closes the modal if clicked outside it
function clickedOutsideModal(e){
if (e.target == abtMeModal){
abtMeModal.style.display = "none";
enableClicks();
}
else if (e.target == awardsModal){
awardsModal.style.display = "none";
enableClicks();
}
else if (e.target == contactModal){
contactModal.style.display = "none";
enableClicks();
}
else if (e.target == projectModal){
projectModal.style.display = "none";
enableClicks();
}
else if (e.target == helpModal){
helpModal.style.display = "none";
enableClicks();
}
else if (e.target == welcomeModal){
welcomeModal.style.display = "none";
enableClicks();
}
}
//prevnts all other elements to be clicked, used when a modal is open
function disableClicks(){
abtMeImage.style.pointerEvents = "none";
projectImage.style.pointerEvents = "none";
awardsButton.style.pointerEvents = "none";
contactButton.style.pointerEvents = "none";
helpButton.style.pointerEvents = "none";
}
//re-enables the elements to be clicked
function enableClicks(){
abtMeImage.style.pointerEvents = "auto";
projectImage.style.pointerEvents = "auto";
awardsButton.style.pointerEvents = "auto";
contactButton.style.pointerEvents = "auto";
helpButton.style.pointerEvents = "auto";
}
//event listeners for all close buttons
for (let i=0; i<closeBtns.length; i++){
closeBtns[i].addEventListener("click", closeModal);
}
//mouse listeners for the hover function that displays the award descriptions
function addAwardMouseListener(){
let awardDescriptions =["Awarded to the top academic performing student in the department of Computer Science for the year","Awarded to the top 10% of students in the Faculty of Science", "Awarded for completing a minimum of 20 volunteering hours within one semester" , "Awarded to an undergraduate international student who has displayed a high level of academic excellence", "Awarded to an international student for financial aid of academic success", "Awarded to second year students or beyond on the basis of scholarship standing", "Awarded to the top academic achieving international undergraduate students"];
for(let i =0 ; i<awardList.length ; i++){
awardList[i].addEventListener("mouseenter", () =>
awardDescriptionContainer.innerHTML = awardDescriptions[i]
);
}
}
//display default text when hovered out of an award item
function awardMouseLeave(){
for(let i =0 ; i<awardList.length ; i++){
awardList[i].addEventListener("mouseleave", () =>
awardDescriptionContainer.innerHTML = "Hover for description"
);
}
}
//adds event listeners for the projects, project details will show up when clicked
function addProjectButtonListeners(){
for(let i =0 ; i<projectButtons.length ; i++){
projectButtons[i].addEventListener("click", ()=>
showProject(i));
}
}
//only displays the currently chosen project and highlights its corresponding button
function showProject(i){
for (let j=0 ; j<projectItems.length ; j++){
projectItems[j].style.display = "none";
projectButtons[j].style.backgroundColor = "black";
projectButtons[j].style.color = "#00e3ff";
}
projectItems[i].style.display = "block";
makeSelected(projectButtons[i]);
}
//initial project setup for the first project
function initialProjectSetup(){
projectItems[0].style.display = "block";
makeSelected(projectButtons[0]);
}
//makes the butttons for the currently selected project have a different colour
function makeSelected(button){
button.style.backgroundColor = "#d59217";
button.style.color = "white";
}