forked from rudransh-vatsyayan/ethos-workshop-rudransh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
204 lines (175 loc) · 6.46 KB
/
Copy pathscript.js
File metadata and controls
204 lines (175 loc) · 6.46 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
document.addEventListener('DOMContentLoaded', () => {
initNavigation();
initMobileMenu();
initScrollEffects();
initThemeToggle();
});
// ==================== THEME TOGGLE ====================
function initThemeToggle() {
const root = document.documentElement;
const toggleBtn = document.getElementById('theme-toggle');
if (!toggleBtn) return;
const storedTheme = localStorage.getItem('color-scheme');
const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const initialTheme = storedTheme || (systemPrefersDark ? 'dark' : 'light');
root.setAttribute('data-color-scheme', initialTheme);
toggleBtn.textContent = initialTheme === 'dark' ? '☀️' : '🌙';
toggleBtn.addEventListener('click', () => {
const current = root.getAttribute('data-color-scheme');
const next = current === 'dark' ? 'light' : 'dark';
root.setAttribute('data-color-scheme', next);
localStorage.setItem('color-scheme', next);
toggleBtn.textContent = next === 'dark' ? '☀️' : '🌙';
});
}
// ==================== NAVIGATION ====================
function initNavigation() {
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const navHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = targetElement.offsetTop - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
closeMobileMenu();
}
});
});
// Button actions
const primaryBtns = document.querySelectorAll('.btn-primary');
const secondaryBtns = document.querySelectorAll('.btn-secondary');
primaryBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
if (btn.getAttribute('href') === '#') {
e.preventDefault();
showNotification('Feature coming soon!', 'info');
}
});
});
secondaryBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
if (btn.getAttribute('href') === '#' || btn.tagName === 'BUTTON') {
e.preventDefault();
showNotification('Feature coming soon!', 'info');
}
});
});
}
function initMobileMenu() {
const burger = document.querySelector('.burger');
if (burger) {
burger.addEventListener('click', () => {
toggleMobileMenu();
});
}
}
function toggleMobileMenu() {
const burger = document.querySelector('.burger');
const navLinks = document.querySelector('.nav-links');
const navActions = document.querySelector('.nav-actions');
burger.classList.toggle('active');
if (navLinks) {
navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex';
}
if (navActions) {
navActions.style.display = navActions.style.display === 'flex' ? 'none' : 'flex';
}
}
function closeMobileMenu() {
const burger = document.querySelector('.burger');
const navLinks = document.querySelector('.nav-links');
const navActions = document.querySelector('.nav-actions');
if (burger && burger.classList.contains('active')) {
burger.classList.remove('active');
}
if (navLinks) navLinks.style.display = 'none';
if (navActions) navActions.style.display = 'none';
}
// ==================== SCROLL EFFECTS ====================
function initScrollEffects() {
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const scrollTop = window.scrollY;
if (scrollTop > 10) {
navbar.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = '0 1px 2px 0 rgba(0, 0, 0, 0.05)';
}
fadeInOnScroll();
});
}
function fadeInOnScroll() {
const elements = document.querySelectorAll('.feature-item, .step-card');
elements.forEach(element => {
const rect = element.getBoundingClientRect();
const isVisible = rect.top < window.innerHeight * 0.85;
if (isVisible && !element.classList.contains('visible')) {
element.classList.add('visible');
}
});
}
// ==================== NOTIFICATIONS ====================
function showNotification(message, type = 'info') {
const existingNotification = document.querySelector('.notification');
if (existingNotification) existingNotification.remove();
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
const bgColor = type === 'success' ? '#10B981' : type === 'error' ? '#EF4444' : '#3B82F6';
notification.style.cssText = `
position: fixed;
top: 100px;
right: 20px;
padding: 1rem 1.5rem;
background: ${bgColor};
color: white;
border-radius: 0.5rem;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
z-index: 10000;
font-weight: 500;
max-width: 400px;
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
// ==================== EVENT LISTENERS ====================
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeMobileMenu();
});
// Burger menu styles
const style = document.createElement('style');
style.textContent = `
.burger.active span:nth-child(1) {
transform: rotate(45deg) translate(8px, 8px);
}
.burger.active span:nth-child(2) {
opacity: 0;
}
.burger.active span:nth-child(3) {
transform: rotate(-45deg) translate(7px, -7px);
}
@media (max-width: 768px) {
.nav-links, .nav-actions {
position: absolute;
top: 70px;
left: 0;
width: 100%;
background: white;
flex-direction: column;
padding: 1.5rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
gap: 1rem;
border-bottom: 1px solid #E5E7EB;
}
}
`;
document.head.appendChild(style);
console.log('UniSync initialized successfully!');