feat: add zoom control with accessibility and persistence
UI Components: - Fixed bottom-center zoom slider (50%-200% range, step 5%) - Modern glass-morphism design with gradient slider track - Reset button with smooth rotation animation - Real-time zoom percentage display - Fully responsive (desktop/tablet/mobile) Functionality: - CSS transform-based zoom (GPU accelerated) - localStorage persistence across sessions - Keyboard shortcuts: Ctrl/Cmd +/-/0 - Smooth transitions with debouncing (50ms) - Scroll position preservation during zoom - Print mode: Temporarily resets to 100% Accessibility (WCAG AA): - Complete ARIA labels and live regions - Keyboard navigation support - Focus indicators on all interactive elements - Screen reader compatible (announces zoom level) - Touch-friendly (44px+ targets) Integration: - Follows existing toggle patterns (length, logos, theme) - Initializes in initPreferences() - Works with print-friendly mode - Hidden in print (.no-print class) - Bilingual support (English/Spanish) Performance: - will-change: transform for compositor layer - Debounced slider input for smooth dragging - requestAnimationFrame for scroll preservation - No layout thrashing (transform-only changes) Technical Details: - Range: 50-200 (prevents unusability, allows 2x mag) - Transform origin: top center (maintains alignment) - Transition: 300ms cubic-bezier (material design) - Storage key: 'cv-zoom' - Default: 100% (normal view)
This commit is contained in:
@@ -254,6 +254,136 @@
|
||||
}
|
||||
};
|
||||
|
||||
// =============================================================================
|
||||
// ZOOM CONTROL
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Initialize zoom control on page load
|
||||
* Restores saved zoom level from localStorage
|
||||
*/
|
||||
function initZoomControl() {
|
||||
const slider = document.getElementById('zoom-slider');
|
||||
const resetBtn = document.getElementById('zoom-reset');
|
||||
const cvPaper = document.querySelector('.cv-paper');
|
||||
|
||||
if (!slider || !cvPaper) return;
|
||||
|
||||
// Restore saved zoom level
|
||||
const savedZoom = localStorage.getItem('cv-zoom');
|
||||
if (savedZoom) {
|
||||
const zoomValue = parseInt(savedZoom, 10);
|
||||
slider.value = zoomValue;
|
||||
applyZoom(zoomValue, false); // false = don't save (already loaded from storage)
|
||||
}
|
||||
|
||||
// Real-time slider updates with debouncing for performance
|
||||
let zoomTimeout;
|
||||
slider.addEventListener('input', function(e) {
|
||||
const zoomValue = parseInt(e.target.value, 10);
|
||||
|
||||
// Update ARIA and display immediately (no debounce)
|
||||
updateZoomDisplay(zoomValue);
|
||||
|
||||
// Debounce the actual transform application (smoother on slower devices)
|
||||
clearTimeout(zoomTimeout);
|
||||
zoomTimeout = setTimeout(() => {
|
||||
applyZoom(zoomValue, true);
|
||||
}, 50); // 50ms debounce
|
||||
});
|
||||
|
||||
// Reset button
|
||||
if (resetBtn) {
|
||||
resetBtn.addEventListener('click', function() {
|
||||
slider.value = 100;
|
||||
applyZoom(100, true);
|
||||
slider.focus(); // Return focus to slider for accessibility
|
||||
});
|
||||
}
|
||||
|
||||
// Keyboard shortcuts (Ctrl/Cmd + Plus/Minus/0)
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && !e.shiftKey) {
|
||||
if (e.key === '=' || e.key === '+') {
|
||||
e.preventDefault();
|
||||
incrementZoom(5);
|
||||
} else if (e.key === '-') {
|
||||
e.preventDefault();
|
||||
incrementZoom(-5);
|
||||
} else if (e.key === '0') {
|
||||
e.preventDefault();
|
||||
slider.value = 100;
|
||||
applyZoom(100, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply zoom transformation to CV paper
|
||||
* @param {number} zoomValue - Zoom percentage (50-200)
|
||||
* @param {boolean} saveToStorage - Whether to persist to localStorage
|
||||
*/
|
||||
function applyZoom(zoomValue, saveToStorage = true) {
|
||||
const cvPaper = document.querySelector('.cv-paper');
|
||||
if (!cvPaper) return;
|
||||
|
||||
// Convert percentage to scale factor (100 = 1.0, 150 = 1.5, etc.)
|
||||
const scaleFactor = zoomValue / 100;
|
||||
|
||||
// Preserve scroll position (matching existing toggle pattern)
|
||||
requestAnimationFrame(() => {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
|
||||
// Apply transform
|
||||
cvPaper.style.transform = `scale(${scaleFactor})`;
|
||||
|
||||
// Restore scroll position
|
||||
window.scrollTo(0, scrollTop);
|
||||
|
||||
// Update display
|
||||
updateZoomDisplay(zoomValue);
|
||||
|
||||
// Save to localStorage
|
||||
if (saveToStorage) {
|
||||
localStorage.setItem('cv-zoom', zoomValue.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update visual display and ARIA attributes
|
||||
* @param {number} zoomValue - Current zoom percentage
|
||||
*/
|
||||
function updateZoomDisplay(zoomValue) {
|
||||
const slider = document.getElementById('zoom-slider');
|
||||
const display = document.getElementById('zoom-display');
|
||||
|
||||
if (display) {
|
||||
display.textContent = `${zoomValue}%`;
|
||||
}
|
||||
|
||||
if (slider) {
|
||||
slider.setAttribute('aria-valuenow', zoomValue);
|
||||
slider.setAttribute('aria-valuetext', `${zoomValue}%`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment/decrement zoom by step amount
|
||||
* @param {number} step - Amount to change (positive or negative)
|
||||
*/
|
||||
function incrementZoom(step) {
|
||||
const slider = document.getElementById('zoom-slider');
|
||||
if (!slider) return;
|
||||
|
||||
const currentZoom = parseInt(slider.value, 10);
|
||||
const newZoom = Math.min(200, Math.max(50, currentZoom + step));
|
||||
|
||||
slider.value = newZoom;
|
||||
applyZoom(newZoom, true);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// PRINT & PDF
|
||||
// =============================================================================
|
||||
@@ -265,6 +395,9 @@
|
||||
const wasClean = container.classList.contains('theme-clean');
|
||||
const wasLong = paper.classList.contains('cv-long');
|
||||
|
||||
// Store current zoom
|
||||
const currentZoom = localStorage.getItem('cv-zoom') || '100';
|
||||
|
||||
// Apply clean theme for minimal print (no sidebars, no header, no icons)
|
||||
if (!wasClean) {
|
||||
container.classList.add('theme-clean');
|
||||
@@ -274,6 +407,11 @@
|
||||
paper.classList.remove('cv-long');
|
||||
paper.classList.add('cv-short');
|
||||
|
||||
// Temporarily reset zoom for printing
|
||||
if (paper) {
|
||||
paper.style.transform = 'scale(1)';
|
||||
}
|
||||
|
||||
// Small delay to let CSS apply
|
||||
setTimeout(() => {
|
||||
window.print();
|
||||
@@ -288,6 +426,10 @@
|
||||
paper.classList.remove('cv-short');
|
||||
paper.classList.add('cv-long');
|
||||
}
|
||||
// Restore zoom
|
||||
if (paper && currentZoom !== '100') {
|
||||
applyZoom(parseInt(currentZoom, 10), false);
|
||||
}
|
||||
}, 100);
|
||||
}, 50);
|
||||
};
|
||||
@@ -354,6 +496,9 @@
|
||||
if (themeChecked) {
|
||||
window.toggleTheme();
|
||||
}
|
||||
|
||||
// Initialize zoom control
|
||||
initZoomControl();
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user