-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
522 lines (317 loc) · 12.5 KB
/
script.js
File metadata and controls
522 lines (317 loc) · 12.5 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
//FUNCTIONS
//Navigation Bar & Hamburger
function openMenu(){
document.body.classList += " menu--open"
}
function closeMenu(){
document.body.classList.remove('menu--open')
}
//Portfolio Modal
//Desktop
const portfolioModal = document.getElementById("portfolio__modal");
const detailsAnchor = document.getElementById("details-anchor");
portfolioModal.style.display = "none";
detailsAnchor.addEventListener("mouseover", () => {
portfolioModal.style.display = "block";
})
portfolioModal.addEventListener("mouseleave", () => {
portfolioModal.style.display = "none";
})
//Header Image
document.getElementById("header__img").addEventListener("click", () => {
document.getElementById("contact-section").scrollIntoView({behavior: 'smooth'});
})
//Change Important Links Colour depending on Background Colour
//FOR FIRST WHITE SECTION
//First Link
const link = document.querySelector('.div1');
const sections = document.querySelector('.white-sections');
const linkObserverCallback = (watchEntry, linkObserver) => {
if(!watchEntry[0].isIntersecting) {
link.classList.remove('dark-theme');
link.classList.add('imp__link--anchor')
} else {
link.classList.remove('imp__link--anchor');
link.classList.add('dark-theme');
}
}
const linkObserverOptions = {
rootMargin: '-110px',
threshold: 0
}
const linkObserver = new IntersectionObserver(linkObserverCallback, linkObserverOptions);
linkObserver.observe(sections);
//Second Link
const secLink = document.querySelector('.div2');
const secSections = document.querySelector('.white-sections');
const secLinkObserverCallback = (watchEntry, secLinkObserver) => {
if(!watchEntry[0].isIntersecting) {
secLink.classList.remove('dark-theme');
secLink.classList.add('imp__link--anchor')
} else {
secLink.classList.remove('imp__link--anchor');
secLink.classList.add('dark-theme');
}
}
const secLinkObserverOptions = {
rootMargin: '-110px',
threshold: 0
}
const secLinkObserver = new IntersectionObserver(secLinkObserverCallback, secLinkObserverOptions);
secLinkObserver.observe(secSections);
//Third Link
const thirdLink = document.querySelector('.div3');
const thirdSections = document.querySelector('.white-sections');
const thirdLinkObserverCallback = (watchEntry, thirdLinkObserver) => {
if(!watchEntry[0].isIntersecting) {
thirdLink.classList.remove('dark-theme');
thirdLink.classList.add('imp__link--anchor')
} else {
thirdLink.classList.remove('imp__link--anchor');
thirdLink.classList.add('dark-theme');
}
}
const thirdLinkObserverOptions = {
rootMargin: '-110px',
threshold: 0
}
const thirdLinkObserver = new IntersectionObserver(thirdLinkObserverCallback, thirdLinkObserverOptions);
thirdLinkObserver.observe(thirdSections);
//Fourth Link
const fourthLink = document.querySelector('.div4');
const fourthSections = document.querySelector('.white-sections');
const fourthLinkObserverCallback = (watchEntry, fourthLinkObserver) => {
if(!watchEntry[0].isIntersecting) {
fourthLink.classList.remove('dark-theme');
fourthLink.classList.add('imp__link--anchor')
} else {
fourthLink.classList.remove('imp__link--anchor');
fourthLink.classList.add('dark-theme');
}
}
const fourthLinkObserverOptions = {
rootMargin: '-110px',
threshold: 0
}
const fourthLinkObserver = new IntersectionObserver(fourthLinkObserverCallback, fourthLinkObserverOptions);
fourthLinkObserver.observe(fourthSections);
//FOR SECOND WHITE SECTION
const linkFirst = document.querySelector('.div1');
const sectionsFirst = document.querySelector('.white-section-2');
const linkObserverCallbackFirst = (watchEntry, linkObserverFirst) => {
if(!watchEntry[0].isIntersecting) {
linkFirst.classList.remove('dark-theme');
linkFirst.classList.add('imp__link--anchor')
} else {
linkFirst.classList.remove('imp__link--anchor');
linkFirst.classList.add('dark-theme');
}
}
const linkObserverOptionsFirst = {
rootMargin: '-110px',
threshold: 0
}
const linkObserverFirst = new IntersectionObserver(linkObserverCallbackFirst, linkObserverOptionsFirst);
linkObserverFirst.observe(sectionsFirst);
//Second Link
const linkSec = document.querySelector('.div2');
const sectionsSec = document.querySelector('.white-section-2');
const linkObserverCallbackSec = (watchEntry, linkObserverSec) => {
if(!watchEntry[0].isIntersecting) {
linkSec.classList.remove('dark-theme');
linkSec.classList.add('imp__link--anchor')
} else {
linkSec.classList.remove('imp__link--anchor');
linkSec.classList.add('dark-theme');
}
}
const linkObserverOptionsSec = {
rootMargin: '-110px',
threshold: 0
}
const linkObserverSec = new IntersectionObserver(linkObserverCallbackSec, linkObserverOptionsSec);
linkObserverSec.observe(sectionsSec);
//Third Link
const linkThird = document.querySelector('.div3');
const sectionsThird = document.querySelector('.white-section-2');
const linkObserverCallbackThird = (watchEntry, linkObserverThird) => {
if(!watchEntry[0].isIntersecting) {
linkThird.classList.remove('dark-theme');
linkThird.classList.add('imp__link--anchor')
} else {
linkThird.classList.remove('imp__link--anchor');
linkThird.classList.add('dark-theme');
}
}
const linkObserverOptionsThird = {
rootMargin: '-110px',
threshold: 0
}
const linkObserverThird = new IntersectionObserver(linkObserverCallbackThird, linkObserverOptionsThird);
linkObserverThird.observe(sectionsThird);
//Third Link
const linkFourth = document.querySelector('.div4');
const sectionsFourth = document.querySelector('.white-section-2');
const linkObserverCallbackFourth = (watchEntry, linkObserverFourth) => {
if(!watchEntry[0].isIntersecting) {
linkFourth.classList.remove('dark-theme');
linkFourth.classList.add('imp__link--anchor')
} else {
linkFourth.classList.remove('imp__link--anchor');
linkFourth.classList.add('dark-theme');
}
}
const linkObserverOptionsFourth = {
rootMargin: '-110px',
threshold: 0
}
const linkObserverFourth = new IntersectionObserver(linkObserverCallbackFourth, linkObserverOptionsFourth);
linkObserverFourth.observe(sectionsFourth);
//Side Navigation Bar changing Colour According to Current Section
//HOME CIRCLE
const circleLinkOne = document.querySelector('.circle1');
const homeSection = document.getElementById('home-section');
const circleLinkObserverCallbackOne = (watchEntry, circleLinkObserverOne) => {
if(watchEntry[0].isIntersecting) {
circleLinkOne.classList.remove('side-nav-bar');
circleLinkOne.classList.add('current-circle')
} else {
circleLinkOne.classList.remove('current-circle');
circleLinkOne.classList.add('side-nav-bar');
}
}
const circleLinkObserverOptionsOne = {
rootMargin: '-110px',
threshold: 0
}
const circleLinkObserverOne = new IntersectionObserver(circleLinkObserverCallbackOne, circleLinkObserverOptionsOne);
circleLinkObserverOne.observe(homeSection);
//ABOUT CIRCLE
const circleLinkTwo = document.querySelector('.circle2');
const aboutSection = document.getElementById('about-section');
const circleLinkObserverCallbackTwo = (watchEntry, circleLinkObserverTwo) => {
if(watchEntry[0].isIntersecting) {
circleLinkTwo.classList.remove('side-nav-bar');
circleLinkTwo.classList.add('current-circle')
} else {
circleLinkTwo.classList.remove('current-circle');
circleLinkTwo.classList.add('side-nav-bar');
}
}
const circleLinkObserverOptionsTwo = {
rootMargin: '-110px',
threshold: 0
}
const circleLinkObserverTwo = new IntersectionObserver(circleLinkObserverCallbackTwo, circleLinkObserverOptionsTwo);
circleLinkObserverTwo.observe(aboutSection);
//PROJECTS CIRCLE
const circleLinkThree = document.querySelector('.circle3');
const projectsSection = document.getElementById('projects-section');
const circleLinkObserverCallbackThree = (watchEntry, circleLinkObserverThree) => {
if(watchEntry[0].isIntersecting) {
circleLinkThree.classList.remove('side-nav-bar');
circleLinkThree.classList.add('current-circle')
} else {
circleLinkThree.classList.remove('current-circle');
circleLinkThree.classList.add('side-nav-bar');
}
}
const circleLinkObserverOptionsThree = {
rootMargin: '-110px',
threshold: 0
}
const circleLinkObserverThree = new IntersectionObserver(circleLinkObserverCallbackThree, circleLinkObserverOptionsThree);
circleLinkObserverThree.observe(projectsSection);
//CONTACT CIRCLE
const circleLinkFour = document.querySelector('.circle4');
const contactSection = document.getElementById('contact-section');
const circleLinkObserverCallbackFour = (watchEntry, circleLinkObserverFour) => {
if(watchEntry[0].isIntersecting) {
circleLinkFour.classList.remove('side-nav-bar');
circleLinkFour.classList.add('current-circle')
} else {
circleLinkFour.classList.remove('current-circle');
circleLinkFour.classList.add('side-nav-bar');
}
}
const circleLinkObserverOptionsFour = {
rootMargin: '-110px',
threshold: 0
}
const circleLinkObserverFour = new IntersectionObserver(circleLinkObserverCallbackFour, circleLinkObserverOptionsFour);
circleLinkObserverFour.observe(contactSection);
// function alarm() {
// alert("This project is currently under development, please try again later.");
// }
//Random Quote Generator
const quotes = [
'“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”',
'“First, solve the problem. Then, write the code.”',
'“Experience is the name everyone gives to their mistakes.”',
'“In order to be irreplaceable, one must always be different”',
'“Java is to JavaScript what car is to Carpet.”',
'“Knowledge is power.”',
'“Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debugging Monday’s code.”',
'“Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.”',
'“Ruby is rubbish! PHP is phpantastic!”',
'Code is like humor. When you have to explain it, it’s bad.”',
'“Fix the cause, not the symptom.”',
'“Optimism is an occupational hazard of programming: feedback is the treatment.',
'“When to use iterative development? You should use iterative development only on projects that you want to succeed.”',
'"Simplicty is the soul of efficiency"',
'"Before software can be reusable, it first has to be usable."',
'"Make it work, make it right, make it fast."',
'"There are only two kinds of languages: the ones people complain about and the ones nobody uses."',
'"Any application that can be written in JavaScript, will eventually be written in JavaScript."',
'"C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."'
]
//Quote Button
const quoteButton = document.getElementById("quotes__btn").addEventListener("click", () => {
//Get a random index
randomIndex = Math.floor(Math.random() * quotes.length);
//Get quote at random index
selectedQuote = quotes[randomIndex];
//Display quote
document.getElementById("quotes__para").innerHTML = selectedQuote;
});
let age = document.getElementById("age");
const birthYear = 2003;
const date = new Date();
let currentDay = date.getDate();
let currentMonth = date.getMonth() + 1;
let currentYear = date.getFullYear();
let newAge;
currentMonth >= 11 && currentDay >= 13 ? newAge = currentYear - birthYear : newAge = currentYear - birthYear - 1;
age.innerHTML = newAge;
const alertModal = document.getElementById("alert__modal");
const closeButton = document.getElementById("close__btn");
const retryButton = document.getElementById("retry__btn");
alertModal.style.display = "none";
function disableScroll() {
// Get the current page scroll position
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
// if any scroll is attempted, set this to the previous value
window.onscroll = function() {
window.scrollTo(scrollLeft, scrollTop);
};
}
function enableScroll() {
window.onscroll = function() {};
}
function alarm(obj) {
redirectLink = obj.getAttribute("href");
alertModal.style.display = "block";
disableScroll();
closeButton.addEventListener("click", () => {
alertModal.style.display = "none";
enableScroll();
});
retryButton.addEventListener("click", () => {
window.location.href = redirectLink;
alertModal.style.display = "none";
enableScroll();
})
}
// let copyrightYear = document.getElementById("copyright__year");
// copyrightYear.innerHTML = currentYear;