Files
cv-site/static/hyperscript/functions._hs
T
juanatsap fbc270278e fix: restore toggle synchronization using hyperscript 'or' operator
**Problem**: Toggles in action bar and hamburger menu were not
synchronizing. When user clicked one toggle, the other didn't update.

**Root Cause**: After restoring toggle functions, they were setting BOTH
checkboxes explicitly instead of using the hyperscript 'or' operator
pattern from the working version.

**Fix**: Restored the original pattern from commit d4ef91b:
- Use `set otherToggle to (#lengthToggle or #lengthToggleMenu)`
- This dynamically selects "the other" toggle (not the one being clicked)
- Simplified code: removed redundant null checks for both checkboxes
- Fixed all 3 toggles: toggleCVLength, toggleIcons, toggleTheme

**Benefits**:
- Toggles now properly sync between action bar and menu
- Cleaner, more maintainable code
- Matches the proven working pattern

**Reference**: Compared with working version at commit d4ef91b
2025-11-16 17:58:48 +00:00

239 lines
6.5 KiB
Plaintext

-- ==============================================================================
-- CV Site - Hyperscript Functions
-- ==============================================================================
-- Global hyperscript functions for CV interactive features
-- Keeps HTML templates clean and behavior organized
-- ==============================================================================
-- PRINT FUNCTIONS
-- ==============================================================================
def printFriendly()
-- Store current state
set container to the first .cv-container
set paper to the first .cv-paper
set wasClean to container.classList.contains('theme-clean')
set wasLong to paper.classList.contains('cv-long')
set currentZoom to localStorage.getItem('cv-zoom') or '100'
-- Apply print-friendly settings
if wasClean is false
add .theme-clean to container
end
remove .cv-long from paper
add .cv-short to paper
-- Reset zoom for consistent printing
set #zoom-wrapper's *zoom to 1
-- Let CSS apply, then print
wait 50ms
call window.print()
-- Wait for print dialog to close, then restore
wait 100ms
-- Restore original theme
if wasClean is false
remove .theme-clean from container
end
-- Restore original length
if wasLong is true
remove .cv-short from paper
add .cv-long to paper
end
-- Restore original zoom by triggering slider input event
if currentZoom is not '100'
set #zoom-slider's value to currentZoom
send input to #zoom-slider
end
end
-- ==============================================================================
-- SCROLL BEHAVIOR
-- ==============================================================================
def initScrollBehavior()
set :lastScroll to 0
set :scrollThreshold to 100
set :keepHeaderVisible to false
end
def handleScroll()
set currentScroll to window.pageYOffset
set menu to the first .navigation-menu
set isMenuOpen to menu.classList.contains('menu-open')
-- Calculate if at bottom (within 50px)
set scrollHeight to document.documentElement.scrollHeight
set clientHeight to document.documentElement.clientHeight
set isAtBottom to (scrollHeight - currentScroll - clientHeight) < 50
-- Reset keepHeaderVisible when scrolling up
if currentScroll < :lastScroll
set :keepHeaderVisible to false
end
-- Header visibility: Scrolling down past threshold
if currentScroll > :scrollThreshold and currentScroll > :lastScroll and :keepHeaderVisible is false
add .header-hidden to .action-bar
if isMenuOpen is true
add .header-hidden to menu
end
end
-- Header visibility: Scrolling up past threshold
if currentScroll > :scrollThreshold and (currentScroll <= :lastScroll or :keepHeaderVisible is true)
remove .header-hidden from .action-bar
if isMenuOpen is true
remove .header-hidden from menu
end
end
-- Header visibility: At top
if currentScroll <= :scrollThreshold
remove .header-hidden from .action-bar
if isMenuOpen is true
remove .header-hidden from menu
end
end
-- Back to top button visibility
if currentScroll > 300
set #back-to-top's *display to 'flex'
end
if currentScroll <= 300
set #back-to-top's *display to 'none'
end
-- At-bottom class for fixed buttons
if isAtBottom
add .at-bottom to #back-to-top
add .at-bottom to #info-button
add .at-bottom to #shortcuts-button
end
if not isAtBottom
remove .at-bottom from #back-to-top
remove .at-bottom from #info-button
remove .at-bottom from #shortcuts-button
end
-- Update last scroll position
set :lastScroll to currentScroll
end
-- ==============================================================================
-- TOGGLE FUNCTIONS
-- ==============================================================================
def toggleCVLength(isLong)
set paper to the first .cv-paper
set otherToggle to (#lengthToggle or #lengthToggleMenu)
if isLong is true
remove .cv-short from paper
add .cv-long to paper
call localStorage.setItem('cv-length', 'long')
if otherToggle exists set otherToggle's checked to true
end
if isLong is false
remove .cv-long from paper
add .cv-short to paper
call localStorage.setItem('cv-length', 'short')
if otherToggle exists set otherToggle's checked to false
end
end
def toggleIcons(showIcons)
set paper to the first .cv-paper
set otherToggle to (#iconToggle or #iconToggleMenu)
if showIcons is true
add .show-icons to paper
call localStorage.setItem('cv-icons', 'true')
if otherToggle exists set otherToggle's checked to true
end
if showIcons is false
remove .show-icons from paper
call localStorage.setItem('cv-icons', 'false')
if otherToggle exists set otherToggle's checked to false
end
end
def toggleTheme(isClean)
set container to the first .cv-container
set otherToggle to (#themeToggle or #themeToggleMenu)
if isClean is true
add .theme-clean to container
call localStorage.setItem('cv-theme', 'clean')
if otherToggle exists set otherToggle's checked to true
end
if isClean is false
remove .theme-clean from container
call localStorage.setItem('cv-theme', 'default')
if otherToggle exists set otherToggle's checked to false
end
end
-- ==============================================================================
-- HOVER SYNC FUNCTIONS
-- ==============================================================================
def syncPdfHover(show)
set pdfButtons to .pdf-download-button
if show is true
for button in pdfButtons
add .pdf-hover-sync to button
end
end
if show is false
for button in pdfButtons
remove .pdf-hover-sync from button
end
end
end
def syncPrintHover(show)
set printButtons to .print-button
if show is true
for button in printButtons
add .print-hover-sync to button
end
end
if show is false
for button in printButtons
remove .print-hover-sync from button
end
end
end
def highlightZoomControl(show)
set zoomWrapper to the first #zoom-wrapper
if show is true
add .highlight to zoomWrapper
end
if show is false
remove .highlight from zoomWrapper
end
end
-- ==============================================================================
-- KEYBOARD SHORTCUTS
-- ==============================================================================
-- Note: Keyboard event handlers are now defined inline in the body tag
-- because hyperscript 0.9.12 doesn't support nested event handlers (on ... inside def)