refactor: use idiomatic hyperscript selector syntax
Replace verbose document.getElementById() and document.querySelectorAll()
with cleaner hyperscript syntax:
- #id for ID selectors
- .class and the first .class for class selectors
- <selector/> query literals for complex selectors
- #{variable} for dynamic ID interpolation
Files changed:
- utils._hs: scrollHeight, details, footer buttons, scrollToSection
- zoom._hs: all zoom control element selectors (14 changes)
- pdf-modal._hs: modal selector
- keyboard._hs: dynamic toggle and modal selectors
- contact-modal.html: response div and modal close
- index.html: ninja-keys bar selector
This commit is contained in:
@@ -67,8 +67,8 @@ def handleScroll()
|
||||
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 scrollHeight to the document's documentElement's scrollHeight
|
||||
set clientHeight to the document's documentElement's clientHeight
|
||||
set isAtBottom to (scrollHeight - currentScroll - clientHeight) < 50
|
||||
|
||||
-- Reset keepHeaderVisible when scrolling up
|
||||
@@ -144,7 +144,7 @@ end
|
||||
-- Expand all <details> elements in the CV
|
||||
def expandAllSections(evt)
|
||||
if evt then call evt.preventDefault() end
|
||||
set details to document.querySelectorAll('details')
|
||||
set details to <details/>
|
||||
for d in details
|
||||
set d's @open to ''
|
||||
end
|
||||
@@ -153,7 +153,7 @@ end
|
||||
-- Collapse all <details> elements in the CV
|
||||
def collapseAllSections(evt)
|
||||
if evt then call evt.preventDefault() end
|
||||
set details to document.querySelectorAll('details')
|
||||
set details to <details/>
|
||||
for d in details
|
||||
call d.removeAttribute('open')
|
||||
end
|
||||
@@ -164,7 +164,7 @@ end
|
||||
-- ==============================================================================
|
||||
-- Adds/removes footer-hovered class to fixed buttons when hovering footer
|
||||
def setFooterHover(show)
|
||||
set buttons to document.querySelectorAll('.download-btn, .print-friendly-btn, .shortcuts-btn, .info-button, .back-to-top, .color-theme-switcher')
|
||||
set buttons to <.download-btn, .print-friendly-btn, .shortcuts-btn, .info-button, .back-to-top, .color-theme-switcher/>
|
||||
for btn in buttons
|
||||
if show
|
||||
add .footer-hovered to btn
|
||||
@@ -199,11 +199,11 @@ end
|
||||
-- Smooth scroll to a section by ID
|
||||
def scrollToSection(evt, sectionId)
|
||||
if evt then call evt.preventDefault() end
|
||||
set el to document.getElementById(sectionId)
|
||||
set el to #{sectionId}
|
||||
if el is not null
|
||||
call el.scrollIntoView({ behavior: 'smooth' })
|
||||
-- Close the menu after navigation
|
||||
set menu to document.querySelector('.navigation-menu')
|
||||
set menu to the first .navigation-menu
|
||||
if menu is not null
|
||||
remove .menu-hover from menu
|
||||
remove .menu-open from menu
|
||||
|
||||
Reference in New Issue
Block a user