-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
112 lines (101 loc) · 3.51 KB
/
Copy pathscript.js
File metadata and controls
112 lines (101 loc) · 3.51 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
// ./script.js
// Theme toggle with localStorage persistence
function toggleTheme() {
document.documentElement.classList.toggle('dark');
const isDark = document.documentElement.classList.contains('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
// Update aria-pressed for accessibility
const themeBtn = document.querySelector('.theme-toggle');
themeBtn.setAttribute('aria-pressed', isDark);
}
// Initialize theme on page load
(function initTheme() {
const savedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && prefersDark)) {
document.documentElement.classList.add('dark');
const themeBtn = document.querySelector('.theme-toggle');
if (themeBtn) themeBtn.setAttribute('aria-pressed', 'true');
}
})();
// Mobile menu toggle
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', () => {
const isActive = navLinks.classList.toggle('active');
mobileMenuBtn.setAttribute('aria-expanded', isActive);
});
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
// Close mobile menu if open
if (navLinks) {
navLinks.classList.remove('active');
if (mobileMenuBtn) {
mobileMenuBtn.setAttribute('aria-expanded', 'false');
}
}
}
});
});
// Contact form handling (optional enhancement)
const contactForm = document.getElementById('contactForm');
const formStatus = document.getElementById('formStatus');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
// For mailto: fallback, show a simple message
if (formStatus) {
setTimeout(() => {
formStatus.textContent = 'Opening your email client...';
formStatus.className = 'form-status success';
}, 100);
}
});
}
// Add structured data for SEO
const structuredData = {
"@context": "https://schema.org",
"@type": "Person",
"name": "BERRIMI Outmane",
"jobTitle": "Software Engineer",
"url": "https://berrimi.github.io/portfolio/",
"sameAs": [
"https://github.com/berrimi"
],
"alumniOf": {
"@type": "EducationalOrganization",
"name": "ISGA Fès"
},
"knowsAbout": [
"Python",
"JavaScript",
"PHP",
"Laravel",
"React",
"Web Development"
]
};
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(structuredData);
document.head.appendChild(script);
// Keyboard navigation enhancement
document.addEventListener('keydown', function(e) {
// Escape key closes mobile menu
if (e.key === 'Escape' && navLinks && navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
if (mobileMenuBtn) {
mobileMenuBtn.setAttribute('aria-expanded', 'false');
mobileMenuBtn.focus();
}
}
});