Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (86 loc) · 2.72 KB
/
Copy pathscript.js
File metadata and controls
99 lines (86 loc) · 2.72 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
console.log("Portfolio script loaded");
// Theme management
let theme = localStorage.getItem("theme");
// Set default theme if none exists
if (theme == null) {
setTheme("blue");
} else {
setTheme(theme);
}
// Add event listeners to theme dots
let themeDots = document.getElementsByClassName("theme-dot");
for (var i = 0; i < themeDots.length; i++) {
themeDots[i].addEventListener("click", function () {
let mode = this.dataset.mode;
console.log("Theme selected:", mode);
setTheme(mode);
});
}
// Set theme function
function setTheme(mode) {
const themeStylesheet = document.getElementById("theme-style");
if (mode == "blue") {
themeStylesheet.href = "blue.css";
} else if (mode == "green") {
themeStylesheet.href = "green.css";
} else if (mode == "purple") {
themeStylesheet.href = "purple.css";
}
localStorage.setItem("theme", mode);
console.log("Theme set to:", mode);
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href !== '#' && href !== '') {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
});
});
// Timeline animation (if timeline elements exist)
if (typeof IntersectionObserver !== 'undefined') {
const timelineItems = document.querySelectorAll('.ag-timeline_item');
if (timelineItems.length > 0) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('js-ag-active');
}
});
}, {
threshold: 0.3
});
timelineItems.forEach(item => {
observer.observe(item);
});
}
}
// Form validation
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
const name = this.querySelector('input[name="name"]').value.trim();
const email = this.querySelector('input[name="email"]').value.trim();
const message = this.querySelector('textarea[name="message"]').value.trim();
if (!name || !email || !message) {
e.preventDefault();
alert('Please fill in all fields before submitting.');
return false;
}
// Basic email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
e.preventDefault();
alert('Please enter a valid email address.');
return false;
}
});
}