refactor: Migrate zoom control and expand/collapse to hyperscript
- Move initZoomControlButtons() from main.js to hyperscript handlers - zoom-toggle-button: on click call toggleZoomControl() - zoom-close: on click call hideZoomControl() - show-zoom-menu-btn: on click call showZoomControl() - Move expandAllSections/collapseAllSections from JS to utils._hs - Add zoom visibility functions to zoom._hs: - showZoomControl(), hideZoomControl(), toggleZoomControl() - Update hamburger menu links to use hyperscript calls Eliminates ~75 more lines of JavaScript in favor of declarative hyperscript, continuing the pattern of moving behavior to ._hs files.
This commit is contained in:
@@ -134,6 +134,27 @@ def handleScroll()
|
||||
set :lastScroll to currentScroll
|
||||
end
|
||||
|
||||
-- ==============================================================================
|
||||
-- EXPAND/COLLAPSE ALL SECTIONS
|
||||
-- ==============================================================================
|
||||
-- Expand all <details> elements in the CV
|
||||
def expandAllSections(evt)
|
||||
if evt then call evt.preventDefault() end
|
||||
set details to document.querySelectorAll('details')
|
||||
for d in details
|
||||
set d's @open to ''
|
||||
end
|
||||
end
|
||||
|
||||
-- Collapse all <details> elements in the CV
|
||||
def collapseAllSections(evt)
|
||||
if evt then call evt.preventDefault() end
|
||||
set details to document.querySelectorAll('details')
|
||||
for d in details
|
||||
call d.removeAttribute('open')
|
||||
end
|
||||
end
|
||||
|
||||
-- ==============================================================================
|
||||
-- FOOTER HOVER INTERACTION
|
||||
-- ==============================================================================
|
||||
|
||||
@@ -100,14 +100,42 @@ def initZoomControl(control)
|
||||
end
|
||||
|
||||
-- ==============================================================================
|
||||
-- ZOOM CLOSE HANDLER
|
||||
-- ZOOM VISIBILITY HANDLERS
|
||||
-- ==============================================================================
|
||||
-- Called when clicking the close button on zoom control
|
||||
def handleZoomClose(control)
|
||||
add .zoom-hidden to control
|
||||
set localStorage['cv-zoom-visible'] to 'false'
|
||||
-- Show zoom control
|
||||
def showZoomControl()
|
||||
set control to document.getElementById('zoom-control')
|
||||
set menuBtn to document.getElementById('show-zoom-menu-btn')
|
||||
if control is not null
|
||||
remove .zoom-hidden from control
|
||||
set localStorage['cv-zoom-visible'] to 'true'
|
||||
end
|
||||
if menuBtn is not null
|
||||
add .zoom-hidden to menuBtn
|
||||
end
|
||||
end
|
||||
|
||||
-- Hide zoom control
|
||||
def hideZoomControl()
|
||||
set control to document.getElementById('zoom-control')
|
||||
set menuBtn to document.getElementById('show-zoom-menu-btn')
|
||||
if control is not null
|
||||
add .zoom-hidden to control
|
||||
set localStorage['cv-zoom-visible'] to 'false'
|
||||
end
|
||||
if menuBtn is not null
|
||||
remove .zoom-hidden from menuBtn
|
||||
end
|
||||
end
|
||||
|
||||
-- Toggle zoom control visibility
|
||||
def toggleZoomControl()
|
||||
set control to document.getElementById('zoom-control')
|
||||
if control is not null
|
||||
if control.classList.contains('zoom-hidden')
|
||||
call showZoomControl()
|
||||
else
|
||||
call hideZoomControl()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user