refactor: Extract modal backdrop close and scrollToTop to functions
- Add closeOnBackdrop(modal, evt) to utils._hs for modal backdrop clicks - Add scrollToTop(evt) to utils._hs for smooth scroll to top - Simplify 3 modal templates (shortcuts, info, pdf) from 4 lines to 1 - Simplify back-to-top button from 3 lines to 1
This commit is contained in:
@@ -170,6 +170,25 @@ def setFooterHover(show)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ==============================================================================
|
||||||
|
-- MODAL HELPERS
|
||||||
|
-- ==============================================================================
|
||||||
|
-- Close modal when clicking backdrop (outside content)
|
||||||
|
def closeOnBackdrop(modal, evt)
|
||||||
|
if evt.target is modal
|
||||||
|
call modal.close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ==============================================================================
|
||||||
|
-- SCROLL HELPERS
|
||||||
|
-- ==============================================================================
|
||||||
|
-- Smooth scroll to top of page
|
||||||
|
def scrollToTop(evt)
|
||||||
|
call evt.preventDefault()
|
||||||
|
call window.scrollTo({top: 0, behavior: 'smooth'})
|
||||||
|
end
|
||||||
|
|
||||||
-- ==============================================================================
|
-- ==============================================================================
|
||||||
-- NAVIGATION SCROLL
|
-- NAVIGATION SCROLL
|
||||||
-- ==============================================================================
|
-- ==============================================================================
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
{{define "info-modal"}}
|
{{define "info-modal"}}
|
||||||
<!-- Info Modal - Native Dialog -->
|
<!-- Info Modal - Native Dialog -->
|
||||||
<dialog id="info-modal" class="info-modal no-print"
|
<dialog id="info-modal" class="info-modal no-print"
|
||||||
_="on click
|
_="on click call closeOnBackdrop(me, event)">
|
||||||
if event.target is me
|
|
||||||
call me.close()
|
|
||||||
end">
|
|
||||||
<div class="info-modal-content">
|
<div class="info-modal-content">
|
||||||
<button class="info-modal-close" onclick="document.getElementById('info-modal').close()" aria-label="Close">
|
<button class="info-modal-close" onclick="document.getElementById('info-modal').close()" aria-label="Close">
|
||||||
<iconify-icon icon="mdi:close" width="24" height="24"></iconify-icon>
|
<iconify-icon icon="mdi:close" width="24" height="24"></iconify-icon>
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
{{define "pdf-modal"}}
|
{{define "pdf-modal"}}
|
||||||
<!-- PDF Download Modal - Interactive Thumbnails -->
|
<!-- PDF Download Modal - Interactive Thumbnails -->
|
||||||
<dialog id="pdf-modal" class="info-modal pdf-download-modal no-print"
|
<dialog id="pdf-modal" class="info-modal pdf-download-modal no-print"
|
||||||
_="on click
|
_="on click call closeOnBackdrop(me, event)">
|
||||||
if event.target is me
|
|
||||||
call me.close()
|
|
||||||
end">
|
|
||||||
<div class="info-modal-content" id="pdf-modal-content">
|
<div class="info-modal-content" id="pdf-modal-content">
|
||||||
<!-- Loading Overlay -->
|
<!-- Loading Overlay -->
|
||||||
<div class="pdf-loading-overlay" id="pdf-loading-overlay">
|
<div class="pdf-loading-overlay" id="pdf-loading-overlay">
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
{{define "shortcuts-modal"}}
|
{{define "shortcuts-modal"}}
|
||||||
<!-- Keyboard Shortcuts Modal - Native Dialog -->
|
<!-- Keyboard Shortcuts Modal - Native Dialog -->
|
||||||
<dialog id="shortcuts-modal" class="info-modal no-print"
|
<dialog id="shortcuts-modal" class="info-modal no-print"
|
||||||
_="on click
|
_="on click call closeOnBackdrop(me, event)">
|
||||||
if event.target is me
|
|
||||||
call me.close()
|
|
||||||
end">
|
|
||||||
<div class="info-modal-content">
|
<div class="info-modal-content">
|
||||||
<button class="info-modal-close" onclick="document.getElementById('shortcuts-modal').close()" aria-label="{{if eq .Lang "es"}}Cerrar{{else}}Close{{end}}">
|
<button class="info-modal-close" onclick="document.getElementById('shortcuts-modal').close()" aria-label="{{if eq .Lang "es"}}Cerrar{{else}}Close{{end}}">
|
||||||
<iconify-icon icon="mdi:close" width="24" height="24"></iconify-icon>
|
<iconify-icon icon="mdi:close" width="24" height="24"></iconify-icon>
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
aria-label="{{if eq .Lang "es"}}Volver arriba{{else}}Back to top{{end}}"
|
aria-label="{{if eq .Lang "es"}}Volver arriba{{else}}Back to top{{end}}"
|
||||||
data-tooltip="{{if eq .Lang "es"}}Volver arriba{{else}}Back to top{{end}}"
|
data-tooltip="{{if eq .Lang "es"}}Volver arriba{{else}}Back to top{{end}}"
|
||||||
style="display: none;"
|
style="display: none;"
|
||||||
_="on click
|
_="on click call scrollToTop(event)">
|
||||||
call event.preventDefault()
|
|
||||||
call window.scrollTo({top: 0, behavior: 'smooth'})">
|
|
||||||
<iconify-icon icon="mdi:arrow-up" width="24" height="24"></iconify-icon>
|
<iconify-icon icon="mdi:arrow-up" width="24" height="24"></iconify-icon>
|
||||||
</button>
|
</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user