feat: replace hash-based CV toggle with path-based routing
Co-authored-by: aider (openai/qwen3.6) <aider@aider.chat>
This commit is contained in:
parent
dc42199ba4
commit
9abb6efd73
19
index.php
19
index.php
@ -315,7 +315,7 @@ $cv_skills = $cvData['skills'] ?? [];
|
||||
const animationDuration = 500; // Matches CSS animation duration (0.5s)
|
||||
const staggerDelay = 200; // Delay between each panel unrolling (ms)
|
||||
|
||||
const toggleCV = (show, updateHash = true, animate = true) => {
|
||||
const toggleCV = (show, updateUrl = true, animate = true) => {
|
||||
const grid = document.querySelector('.bento-grid');
|
||||
const labelText = document.getElementById('toggle-label-text');
|
||||
|
||||
@ -363,8 +363,9 @@ $cv_skills = $cvData['skills'] ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
if (updateHash) {
|
||||
window.location.hash = show ? 'CV' : '';
|
||||
if (updateUrl) {
|
||||
const newUrl = show ? '/cv' : '/';
|
||||
history.pushState({ cv: show }, '', newUrl);
|
||||
}
|
||||
|
||||
// Keep toggle in sync
|
||||
@ -373,14 +374,20 @@ $cv_skills = $cvData['skills'] ?? [];
|
||||
};
|
||||
|
||||
// Initialize state from URL
|
||||
const checkHash = (animate = false) => toggleCV(window.location.hash === '#CV', false, animate);
|
||||
const isCvPath = window.location.pathname.includes('/cv');
|
||||
const checkUrl = (animate = false) => toggleCV(isCvPath, false, animate);
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
checkHash(false);
|
||||
checkUrl(false);
|
||||
// Small delay to ensure initial styles are applied before enabling transitions
|
||||
setTimeout(() => document.body.classList.remove('preload'), 20);
|
||||
});
|
||||
window.addEventListener('hashchange', () => checkHash(true));
|
||||
|
||||
// Handle back/forward navigation
|
||||
window.addEventListener('popstate', () => {
|
||||
const showCv = window.location.pathname.includes('/cv');
|
||||
toggleCV(showCv, false, true);
|
||||
});
|
||||
|
||||
const cvToggleInput = document.getElementById('cv-toggle');
|
||||
cvToggleInput?.addEventListener('change', (e) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user