-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
76 lines (65 loc) · 2.41 KB
/
Copy paththeme.js
File metadata and controls
76 lines (65 loc) · 2.41 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
// Theme Management - Shared across all pages
// Initialize theme on page load
function initializeTheme() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
}
// Toggle between light and dark theme
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Add rotation animation
const themeToggle = document.getElementById('themeToggle');
if (themeToggle) {
themeToggle.style.transition = 'transform 0.3s ease';
themeToggle.style.transform = 'rotate(360deg)';
setTimeout(() => {
themeToggle.style.transform = 'rotate(0deg)';
}, 300);
}
}
// Update theme icon
function updateThemeIcon(theme) {
const icon = document.querySelector('.theme-icon');
if (icon) {
icon.textContent = theme === 'light' ? '🌙' : '☀️';
}
}
// Setup theme toggle listener
document.addEventListener('DOMContentLoaded', function() {
initializeTheme();
const themeToggle = document.getElementById('themeToggle');
if (themeToggle) {
themeToggle.addEventListener('click', toggleTheme);
}
// Mobile menu functionality
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('navLinks');
if (hamburger && navLinks) {
hamburger.addEventListener('click', function() {
navLinks.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Close menu when clicking outside
document.addEventListener('click', function(e) {
if (!hamburger.contains(e.target) && !navLinks.contains(e.target)) {
navLinks.classList.remove('active');
hamburger.classList.remove('active');
}
});
}
// Logout button
const logoutBtn = document.getElementById('logoutBtn');
if (logoutBtn) {
logoutBtn.addEventListener('click', async function(e) {
e.preventDefault();
if (confirm('Are you sure you want to logout?')) {
await logout();
}
});
}
});