-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (33 loc) · 1.62 KB
/
script.js
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
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.accordion .accordion-header').forEach(header => {
header.addEventListener('click', () => {
const accordion = header.closest('.accordion');
const content = header.nextElementSibling;
const isCurrentlyActive = accordion.classList.contains('active');
// Close all accordion contents
document.querySelectorAll('.accordion').forEach(acc => {
const accContent = acc.querySelector('.accordion-content');
acc.classList.remove('active');
accContent.style.maxHeight = '0';
});
// If it wasn't already active, open this one
if (!isCurrentlyActive) {
accordion.classList.add('active');
content.style.maxHeight = `${content.scrollHeight}px`;
}
});
});
const themeToggle = document.getElementById('theme-toggle');
const htmlElement = document.documentElement;
// Check for saved theme preference or default to dark
const savedTheme = localStorage.getItem('site-theme') || 'dark';
htmlElement.setAttribute('data-theme', savedTheme);
themeToggle.addEventListener('click', () => {
const currentTheme = htmlElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
// Update theme attribute
htmlElement.setAttribute('data-theme', newTheme);
// Save preference
localStorage.setItem('site-theme', newTheme);
});
});