Last active
December 25, 2023 10:47
-
-
Save dz4k/6505fb82ae7fdb0a03e6f3e360931aa9 to your computer and use it in GitHub Desktop.
Draggable window in _hyperscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Usage: _="install Draggable(dragHandle: .titlebar in me)" | |
behavior Draggable(dragHandle) | |
init | |
if no dragHandle set the dragHandle to me | |
end | |
on pointerdown(clientX, clientY) from dragHandle | |
halt the event | |
trigger draggable:start -- hooks, e.g. for adding a drop shadow while dragging | |
measure my x, y | |
set xoff to clientX - x | |
set yoff to clientY - y | |
repeat until event pointerup from document | |
wait for pointermove(pageX, pageY) or | |
pointerup (pageX, pageY) from document | |
add { left: ${pageX - xoff}px; top: ${pageY - yoff}px; } | |
trigger draggable:move | |
end | |
trigger draggable:end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this live somewhere that could serve as a demo?