big overhaul

This commit is contained in:
speyll
2025-04-09 16:09:59 +01:00
parent ae125d2bc6
commit 9af0a02acd
32 changed files with 517 additions and 410 deletions

View File

@@ -1,12 +1,15 @@
:root {
--icon-size: 1.3rem;
--icon-color: var(--text);
}
#nav-bar {
padding: .625rem 0 0 0;
display: flex;
flex-direction: row;
gap: .25rem;
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
align-content: flex-end
padding: 0.625rem 0 0;
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
justify-content: flex-end;
align-items: center;
}
#footer-container {
@@ -38,21 +41,37 @@
}
/* icons settings */
.icons {
width: 1.3rem;
height: 1.3rem;
aspect-ratio: 1/1;
display: inline-block;
vertical-align: middle;
color: var(--text);
fill: var(--text);
background-color: transparent;
cursor: pointer;
.icon {
width: var(--icon-size);
height: var(--icon-size);
display: inline-block;
vertical-align: middle;
color: var(--icon-color);
fill: currentColor;
transition: color 0.3s ease;
cursor: pointer;
}
.icons:hover {
background-color: transparent;
color: var(--accent);
.icon:hover {
--icon-color: var(--accent);
}
/* Theme toggle specific styles */
.theme-toggle {
cursor: pointer;
padding: 0;
margin: 0;
background: none;
border: none;
display: inline-flex;
}
.theme-toggle:hover .icon {
--icon-color: var(--accent);
}
.theme-toggle:active {
transform: scale(0.95);
}
/* footnotes */
@@ -70,16 +89,25 @@
}
/* general classes */
/* Cleaned no-style class */
.no-style {
padding: 0;
margin: 0;
border: none;
border-radius: 0
all: unset;
background: none !important;
border: none !important;
}
.no-style:hover {
background-color: transparent;
color: var(--accent);
background: transparent;
color: inherit;
}
/* Modern float replacement */
.float-right {
margin-inline-start: auto;
}
.float-left {
margin-inline-end: auto;
}
.center {
@@ -91,15 +119,7 @@
margin: 1rem auto;
}
.float-right {
float: right
}
.float-left {
float: left
}
/* shortcodes css */
.webring {
margin: .375rem;
}
}

View File

@@ -18,4 +18,4 @@
<symbol id="chevronRight" viewBox="0 0 24 24"><rect x="0" y="0" fill="none" stroke="none" />
<path fill="currentColor" d="M8.59 16.58L13.17 12L8.59 7.41L10 6l6 6l-6 6l-1.41-1.42Z"/>
</symbol>
</svg>
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -1,49 +1,64 @@
const toggleButton = document.getElementById('theme-toggle');
const themeIcon = document.getElementById('theme-icon');
const themeSound = document.getElementById('theme-sound');
class ThemeManager {
constructor() {
// Cache DOM elements once
this.toggle = document.getElementById('theme-toggle');
this.icon = document.getElementById('theme-icon');
// Function to update the theme icon based on the current theme
const updateThemeIcon = (isDarkMode) => {
const themeMode = isDarkMode ? 'darkMode' : 'lightMode';
const iconPath = themeIcon.querySelector('use').getAttribute('href').replace(/#.*$/, `#${themeMode}`);
themeIcon.querySelector('use').setAttribute('href', iconPath);
};
// Get data attributes once
const { iconBase, iconDark, iconLight, soundSrc } = this.toggle.dataset;
this.iconBase = iconBase;
this.iconDark = iconDark;
this.iconLight = iconLight;
// Function to update the theme based on the current mode
const updateTheme = (isDarkMode) => {
const theme = isDarkMode ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', theme);
updateThemeIcon(isDarkMode);
};
// Create audio element only when needed
this.sound = new Audio(soundSrc);
// Function to toggle the theme
const toggleTheme = () => {
const isDarkMode = toggleButton.checked;
updateTheme(isDarkMode);
themeSound.play();
localStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
this.init();
}
// Add transition class to body for smooth transition
document.body.classList.add('theme-transition');
setTimeout(() => {
document.body.classList.remove('theme-transition');
}, 300);
};
init() {
this.setInitialTheme();
this.toggle.addEventListener('click', () => this.toggleTheme());
}
// Event listener for theme toggle
toggleButton.addEventListener('change', toggleTheme);
setInitialTheme() {
const savedTheme = localStorage.getItem('theme');
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const initialTheme = savedTheme || (systemDark ? 'dark' : 'light');
// Function to initialize the theme based on the stored preference
const initializeTheme = () => {
const storedTheme = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const isDarkMode = storedTheme === 'dark' || (!storedTheme && prefersDark);
toggleButton.checked = isDarkMode;
updateTheme(isDarkMode);
};
document.documentElement.setAttribute('data-theme', initialTheme);
this.updateIcon(initialTheme === 'dark');
}
// Initialize the theme
initializeTheme();
toggleTheme() {
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
const newTheme = isDark ? 'light' : 'dark';
// Listen for changes in system preference
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', initializeTheme);
document.body.classList.add('theme-transition');
document.documentElement.setAttribute('data-theme', newTheme);
// Use the inverse to update the icon to match the new theme
this.updateIcon(!isDark);
localStorage.setItem('theme', newTheme);
// Use requestAnimationFrame for better performance on transition
requestAnimationFrame(() => {
setTimeout(() => {
document.body.classList.remove('theme-transition');
}, 300);
});
this.sound.play().catch(() => {});
}
// Extracted common functionality
updateIcon(isDark) {
this.icon.setAttribute('href',
`${this.iconBase}${isDark ? this.iconDark : this.iconLight}`);
}
}
// Use modern syntax
document.addEventListener('DOMContentLoaded', () => new ThemeManager());