-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
661 lines (562 loc) · 20.2 KB
/
Copy pathscript.js
File metadata and controls
661 lines (562 loc) · 20.2 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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
// Mobile Navigation Toggle
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.querySelector('.nav-menu');
mobileMenu.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
});
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 100) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
navbar.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
navbar.style.boxShadow = 'none';
}
});
// Smooth scrolling for navigation 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'
});
}
});
});
// Active navigation link highlighting
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('.nav-link');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollY >= (sectionTop - 200)) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').slice(1) === current) {
link.classList.add('active');
}
});
});
// Contact form handling
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = {
name: document.getElementById('name').value,
email: document.getElementById('email').value,
subject: document.getElementById('subject').value,
message: document.getElementById('message').value
};
// Simple validation
if (!formData.name || !formData.email || !formData.subject || !formData.message) {
showNotification('Please fill in all fields', 'error');
return;
}
// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
showNotification('Please enter a valid email address', 'error');
return;
}
// Simulate form submission (replace with actual implementation)
showNotification('Thank you for your message! I will get back to you soon.', 'success');
contactForm.reset();
// In a real implementation, you would send this data to a server
console.log('Form submitted:', formData);
// Example of how you might send this data to a server:
// fetch('/api/contact', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify(formData)
// })
// .then(response => response.json())
// .then(data => {
// showNotification('Message sent successfully!', 'success');
// contactForm.reset();
// })
// .catch(error => {
// showNotification('Error sending message. Please try again.', 'error');
// });
});
// Notification system
function showNotification(message, type = 'info') {
// Remove existing notifications
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
border-radius: 8px;
color: white;
font-weight: 500;
z-index: 10000;
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 300px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
`;
// Set background color based on type
switch(type) {
case 'success':
notification.style.background = '#10b981';
break;
case 'error':
notification.style.background = '#ef4444';
break;
default:
notification.style.background = '#3b82f6';
}
// Add to page
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Remove after 5 seconds
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 5000);
}
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll(
'.service-card, .stat-item, .highlight-item, .contact-method, .company-logo'
);
animateElements.forEach(el => {
observer.observe(el);
});
});
// Typing effect for hero name
function typeWriter(element, text, speed = 100) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Initialize typing effect when page loads
window.addEventListener('load', () => {
const heroName = document.querySelector('.hero-name');
if (heroName) {
const originalText = heroName.textContent;
typeWriter(heroName, originalText, 80);
}
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
const heroContent = document.querySelector('.hero-content');
if (hero && heroContent) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
heroContent.style.transform = `translateY(${scrolled * 0.3}px)`;
}
});
// Add hover effect to service cards
document.querySelectorAll('.service-card').forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-15px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Add hover effect to social links
document.querySelectorAll('.social-link').forEach(link => {
link.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) rotate(5deg)';
});
link.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) rotate(0)';
});
});
// Form input focus effects
document.querySelectorAll('.form-group input, .form-group textarea').forEach(input => {
input.addEventListener('focus', function() {
this.parentElement.style.transform = 'scale(1.02)';
this.parentElement.style.transition = 'transform 0.2s ease';
});
input.addEventListener('blur', function() {
this.parentElement.style.transform = 'scale(1)';
});
});
// Add loading state to buttons
document.querySelectorAll('.btn').forEach(button => {
button.addEventListener('click', function(e) {
if (this.type === 'submit') {
const originalText = this.textContent;
this.textContent = 'Sending...';
this.disabled = true;
// Reset after 2 seconds (in real implementation, this would be based on server response)
setTimeout(() => {
this.textContent = originalText;
this.disabled = false;
}, 2000);
}
});
});
// Smooth reveal animation for sections
function revealOnScroll() {
const reveals = document.querySelectorAll('.reveal');
reveals.forEach(element => {
const windowHeight = window.innerHeight;
const elementTop = element.getBoundingClientRect().top;
const elementVisible = 150;
if (elementTop < windowHeight - elementVisible) {
element.classList.add('active');
}
});
}
window.addEventListener('scroll', revealOnScroll);
// Add reveal class to elements that should animate on scroll
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('section');
sections.forEach(section => {
section.classList.add('reveal');
});
});
// Initialize reveal on scroll
revealOnScroll();
// Loading Screen
window.addEventListener('load', () => {
const loadingScreen = document.getElementById('loading-screen');
if (loadingScreen) {
setTimeout(() => {
loadingScreen.style.opacity = '0';
setTimeout(() => {
loadingScreen.style.display = 'none';
}, 500);
}, 1500);
}
});
// Back to Top Button
const backToTopBtn = document.getElementById('backToTop');
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopBtn.classList.add('active');
} else {
backToTopBtn.classList.remove('active');
}
});
backToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Enhanced Terminal Animation
function animateTerminal() {
const terminalLines = document.querySelectorAll('.terminal-line');
terminalLines.forEach((line, index) => {
setTimeout(() => {
line.style.opacity = '1';
line.style.transform = 'translateX(0)';
}, index * 200);
});
}
// Initialize terminal animation
document.addEventListener('DOMContentLoaded', () => {
setTimeout(animateTerminal, 1000);
});
// Enhanced Form Validation
function validateForm(formData) {
const errors = [];
if (!formData.name || formData.name.trim().length < 2) {
errors.push('Name must be at least 2 characters long');
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
errors.push('Please enter a valid email address');
}
if (!formData.subject || formData.subject.trim().length < 3) {
errors.push('Subject must be at least 3 characters long');
}
if (!formData.message || formData.message.trim().length < 10) {
errors.push('Message must be at least 10 characters long');
}
return errors;
}
// Enhanced Contact Form
contactForm.addEventListener('submit', async function(e) {
e.preventDefault();
const formData = {
name: document.getElementById('name').value,
email: document.getElementById('email').value,
subject: document.getElementById('subject').value,
message: document.getElementById('message').value
};
const errors = validateForm(formData);
if (errors.length > 0) {
showNotification(errors[0], 'error');
return;
}
const submitBtn = contactForm.querySelector('.btn-primary');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
try {
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 2000));
showNotification('Thank you for your message! I will get back to you soon.', 'success');
contactForm.reset();
// Track form submission (analytics)
if (typeof gtag !== 'undefined') {
gtag('event', 'form_submission', {
'event_category': 'Contact',
'event_label': 'Contact Form'
});
}
} catch (error) {
showNotification('Error sending message. Please try again.', 'error');
} finally {
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}
});
// Real-time form validation
document.querySelectorAll('.form-group input, .form-group textarea').forEach(input => {
input.addEventListener('blur', function() {
validateField(this);
});
input.addEventListener('input', function() {
if (this.parentElement.classList.contains('error')) {
validateField(this);
}
});
});
function validateField(field) {
const formGroup = field.parentElement;
const value = field.value.trim();
let isValid = true;
let errorMessage = '';
// Remove existing error
const existingError = formGroup.querySelector('.error-message');
if (existingError) {
existingError.remove();
}
formGroup.classList.remove('error');
switch(field.id) {
case 'name':
if (value.length < 2) {
isValid = false;
errorMessage = 'Name must be at least 2 characters';
}
break;
case 'email':
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(value)) {
isValid = false;
errorMessage = 'Please enter a valid email';
}
break;
case 'subject':
if (value.length < 3) {
isValid = false;
errorMessage = 'Subject must be at least 3 characters';
}
break;
case 'message':
if (value.length < 10) {
isValid = false;
errorMessage = 'Message must be at least 10 characters';
}
break;
}
if (!isValid) {
formGroup.classList.add('error');
const errorDiv = document.createElement('div');
errorDiv.className = 'error-message';
errorDiv.textContent = errorMessage;
formGroup.appendChild(errorDiv);
}
return isValid;
}
// Enhanced Intersection Observer
const enhancedObserverOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const enhancedObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
// Add staggered animation for grid items
if (entry.target.classList.contains('expertise-grid') ||
entry.target.classList.contains('tech-stack-grid')) {
const items = entry.target.querySelectorAll('.expertise-item, .tech-item');
items.forEach((item, index) => {
setTimeout(() => {
item.classList.add('animate-in');
}, index * 100);
});
}
enhancedObserver.unobserve(entry.target);
}
});
}, enhancedObserverOptions);
// Observe more elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll(
'.service-card, .stat-item, .highlight-item, .contact-method, .company-logo, ' +
'.expertise-grid, .tech-stack-grid, .achievement-card, .timeline-item'
);
animateElements.forEach(el => {
enhancedObserver.observe(el);
});
});
// Counter Animation for Stats
function animateCounter(element, target, duration = 2000) {
const start = 0;
const increment = target / (duration / 16);
let current = start;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
if (element.dataset.suffix) {
element.textContent = Math.floor(current) + element.dataset.suffix;
} else {
element.textContent = Math.floor(current);
}
}, 16);
}
// Initialize counters when in view
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('animated')) {
const target = parseInt(entry.target.dataset.target);
animateCounter(entry.target, target);
entry.target.classList.add('animated');
counterObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
document.addEventListener('DOMContentLoaded', () => {
const counters = document.querySelectorAll('.counter');
counters.forEach(counter => {
counterObserver.observe(counter);
});
});
// Enhanced Mobile Navigation
const mobileMenuBtn = document.getElementById('mobile-menu');
const navMenuEnhanced = document.querySelector('.nav-menu');
const navLinksEnhanced = document.querySelectorAll('.nav-link');
mobileMenuBtn.addEventListener('click', () => {
mobileMenuBtn.classList.toggle('active');
navMenu.classList.toggle('active');
document.body.classList.toggle('no-scroll');
});
navLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenuBtn.classList.remove('active');
navMenu.classList.remove('active');
document.body.classList.remove('no-scroll');
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!mobileMenuBtn.contains(e.target) && !navMenu.contains(e.target)) {
mobileMenuBtn.classList.remove('active');
navMenu.classList.remove('active');
document.body.classList.remove('no-scroll');
}
});
// Enhanced Scroll Progress Bar
function updateScrollProgress() {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = (scrollTop / docHeight) * 100;
const progressBar = document.getElementById('scrollProgress');
if (progressBar) {
progressBar.style.width = scrollPercent + '%';
}
}
window.addEventListener('scroll', updateScrollProgress);
// Theme Toggle (if implemented)
function initThemeToggle() {
const themeToggle = document.getElementById('theme-toggle');
const currentTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', currentTheme);
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
}
}
// Initialize theme toggle
document.addEventListener('DOMContentLoaded', initThemeToggle);
// Enhanced Performance Monitoring
function logPerformanceMetrics() {
if ('performance' in window) {
window.addEventListener('load', () => {
setTimeout(() => {
const perfData = performance.getEntriesByType('navigation')[0];
console.log('Page Load Time:', perfData.loadEventEnd - perfData.loadEventStart, 'ms');
console.log('DOM Interactive:', perfData.domInteractive - perfData.navigationStart, 'ms');
}, 0);
});
}
}
logPerformanceMetrics();
// Enhanced Console Welcome Message
console.log('%c🚀 Welcome to Souleimen Mrad\'s Portfolio!', 'color: #2563eb; font-size: 20px; font-weight: bold;');
console.log('%cBuilt with passion and modern web technologies', 'color: #10b981; font-size: 14px;');
console.log('%cInterested in collaboration? Reach out at soulsimplifai@gmail.com', 'color: #8b5cf6; font-size: 14px;');
console.log('%c🎨 Enhanced with SEO, accessibility, and performance optimizations', 'color: #f59e0b; font-size: 12px;');