refactor: Extract zoom drag handlers to functions in zoom._hs
- Move inline drag handling (~35 lines) to external functions (~4 lines) - Add isZoomDragTarget(el), startZoomDrag(), moveZoomDrag(), endZoomDrag() - Note: 'target' is reserved in hyperscript, use 'el' for parameters - Drag state stored on element (_isDragging, _initialX, _initialY) Zoom control HTML now has clean, minimal hyperscript handlers.
This commit is contained in:
@@ -139,3 +139,64 @@ def toggleZoomControl()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ==============================================================================
|
||||
-- ZOOM CONTROL DRAG HANDLERS
|
||||
-- ==============================================================================
|
||||
-- Check if drag target is valid (not a button or input)
|
||||
def isZoomDragTarget(el)
|
||||
if el.tagName is 'INPUT'
|
||||
return false
|
||||
end
|
||||
if el.tagName is 'BUTTON'
|
||||
return false
|
||||
end
|
||||
if el.matches('.zoom-slider, .zoom-close-btn, .zoom-reset-btn, .zoom-value')
|
||||
return false
|
||||
end
|
||||
if el.closest('.zoom-close-btn')
|
||||
return false
|
||||
end
|
||||
if el.closest('.zoom-reset-btn')
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- Start dragging zoom control
|
||||
def startZoomDrag(control, clientX, clientY)
|
||||
set control._isDragging to true
|
||||
set control's *transition to 'none'
|
||||
set rect to control.getBoundingClientRect()
|
||||
set control._initialX to clientX - rect.left
|
||||
set control._initialY to clientY - rect.top
|
||||
end
|
||||
|
||||
-- Handle drag move
|
||||
def moveZoomDrag(control, clientX, clientY)
|
||||
if control._isDragging is not true
|
||||
return false
|
||||
end
|
||||
set currentX to clientX - control._initialX
|
||||
set currentY to clientY - control._initialY
|
||||
set maxX to window.innerWidth - control.offsetWidth
|
||||
set maxY to window.innerHeight - control.offsetHeight
|
||||
set currentX to Math.max(0, Math.min(currentX, maxX))
|
||||
set currentY to Math.max(0, Math.min(currentY, maxY))
|
||||
set control's *left to `${currentX}px`
|
||||
set control's *bottom to `${window.innerHeight - currentY - control.offsetHeight}px`
|
||||
set control's *transform to 'none'
|
||||
return true
|
||||
end
|
||||
|
||||
-- End drag and save position
|
||||
def endZoomDrag(control)
|
||||
if control._isDragging is not true
|
||||
return false
|
||||
end
|
||||
set control._isDragging to false
|
||||
set control's *transition to 'all 0.3s ease'
|
||||
set position to { bottom: control.style.bottom, left: control.style.left }
|
||||
set localStorage['cv-zoom-position'] to JSON.stringify(position)
|
||||
return true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user