-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
119 lines (94 loc) · 3.84 KB
/
main.js
File metadata and controls
119 lines (94 loc) · 3.84 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
document.addEventListener('DOMContentLoaded', () => {
const themeCheckbox = document.getElementById('themeCheckbox');
const body = document.body;
// Apply saved theme on load
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
body.classList.add('dark-theme');
themeCheckbox.checked = true;
}
// Toggle theme on checkbox change
themeCheckbox.addEventListener('change', () => {
if (themeCheckbox.checked) {
body.classList.add('dark-theme');
localStorage.setItem('theme', 'dark');
} else {
body.classList.remove('dark-theme');
localStorage.setItem('theme', 'light');
}
});
// Intersection Observer for active navigation
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('nav a');
const observerOptions = {
root: null,
rootMargin: '-50% 0px -50% 0px',
threshold: 0
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('id');
// Remove active from all links
navLinks.forEach(function(link) {
link.classList.remove('active');
});
// Add active to the matching link
navLinks.forEach(function(link) {
if (link.getAttribute('href') === '#' + id) {
link.classList.add('active');
}
});
}
});
}, observerOptions);
sections.forEach(function(section) {
observer.observe(section);
});
// Smooth scrolling for internal links only
navLinks.forEach(function(link) {
link.addEventListener('click', function(e) {
const href = this.getAttribute('href');
// Only handle links that start with '#' (anchors)
if (href.startsWith('#')) {
e.preventDefault();
const targetSection = document.querySelector(href);
if (targetSection) {
targetSection.scrollIntoView({ behavior: 'smooth' });
}
}
// If not a hash link (e.g. /fr/index.html), allow normal navigation
});
});
// restart animation
document.querySelector('.profile-logo').addEventListener('click', function() {
const container = document.querySelector('.subtitle-container');
// Remove and re-add the container to restart animations
const clone = container.cloneNode(true);
container.parentNode.replaceChild(clone, container);
});
}); // wrapper for all JS
// text carousel modal to inlarge images
document.querySelectorAll('.view-large').forEach(btn => {
btn.addEventListener('click', () => {
const img = btn.closest('li').querySelector('img');
const modal = document.getElementById('imageModal');
const modalImg = document.getElementById('modalImage');
modalImg.src = img.src;
modalImg.alt = img.alt;
modal.removeAttribute('hidden');
requestAnimationFrame(() => modal.classList.add('show'));
});
});
document.querySelector('.close-modal').addEventListener('click', () => {
const modal = document.getElementById('imageModal');
modal.classList.remove('show');
setTimeout(() => modal.setAttribute('hidden', ''), 300);
});
document.getElementById('imageModal').addEventListener('click', e => {
if (e.target === e.currentTarget) {
const modal = e.currentTarget;
modal.classList.remove('show');
setTimeout(() => modal.setAttribute('hidden', ''), 300);
}
});