more htmx
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
-- ==============================================================================
|
||||
-- CV Site - Hyperscript Functions
|
||||
-- ==============================================================================
|
||||
-- Global hyperscript functions for CV interactive features
|
||||
-- Keeps HTML templates clean and behavior organized
|
||||
|
||||
-- ==============================================================================
|
||||
-- PRINT FUNCTIONS
|
||||
-- ==============================================================================
|
||||
|
||||
-- Print friendly - applies clean theme and short version for printing
|
||||
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 then 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 then 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
|
||||
-- ==============================================================================
|
||||
|
||||
-- Initialize scroll behavior state
|
||||
def initScrollBehavior()
|
||||
set :lastScroll to 0
|
||||
set :scrollThreshold to 100
|
||||
set :keepHeaderVisible to false
|
||||
end
|
||||
|
||||
-- Handle scroll events
|
||||
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 based on scroll direction
|
||||
if currentScroll > :scrollThreshold
|
||||
if currentScroll > :lastScroll and :keepHeaderVisible is false
|
||||
-- Scrolling down - hide header
|
||||
add .header-hidden to .action-bar
|
||||
if isMenuOpen is true then add .header-hidden to menu end
|
||||
else
|
||||
-- Scrolling up - show header
|
||||
remove .header-hidden from .action-bar
|
||||
if isMenuOpen is true then remove .header-hidden from menu end
|
||||
end
|
||||
else
|
||||
-- At top - always show header
|
||||
remove .header-hidden from .action-bar
|
||||
if isMenuOpen is true then remove .header-hidden from menu end
|
||||
end
|
||||
|
||||
-- Back to top button visibility (show after 300px scroll)
|
||||
if currentScroll > 300
|
||||
set #back-to-top's *display to 'flex'
|
||||
else
|
||||
set #back-to-top's *display to 'none'
|
||||
end
|
||||
|
||||
-- At-bottom positioning for fixed buttons
|
||||
if isAtBottom
|
||||
add .at-bottom to #back-to-top
|
||||
add .at-bottom to #info-button
|
||||
else
|
||||
remove .at-bottom from #back-to-top
|
||||
remove .at-bottom from #info-button
|
||||
end
|
||||
|
||||
-- Update last scroll position
|
||||
set :lastScroll to currentScroll
|
||||
end
|
||||
Reference in New Issue
Block a user