diff --git a/static/hyperscript/zoom._hs b/static/hyperscript/zoom._hs index aff260e..1a0b665 100644 --- a/static/hyperscript/zoom._hs +++ b/static/hyperscript/zoom._hs @@ -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 diff --git a/templates/partials/widgets/zoom-control.html b/templates/partials/widgets/zoom-control.html index e1c63b0..d06710d 100644 --- a/templates/partials/widgets/zoom-control.html +++ b/templates/partials/widgets/zoom-control.html @@ -2,39 +2,9 @@