mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
HTML5 drag-and-drop never fires from touch, so the board-icon reorder (and the
other HTML5-DnD spots) only worked with a mouse. This adds
client/lib/dragDropTouch.js: a long press on a `draggable="true"` element starts
a synthetic drag that dispatches REAL, bubbling
dragstart/dragenter/dragover/dragleave/drop/dragend DOM events with a
dataTransfer shim - so every existing delegated handler works from a finger with
no change to the reorder logic, the workspace drag-to-share, or the card/rule
drags.
Chosen to be safe alongside the existing touch scrolling:
* LONG PRESS (250 ms) to start - a quick swipe on a draggable tile still
scrolls; only a deliberate hold-then-move begins a drag, and preventDefault
is called ONLY once a drag is under way.
* It fires a `mousedown` on the pressed element first, so the board reorder's
handle gate (which records the mousedown target) works from touch too.
* setDragImage is honoured, so the ghost is centred on the finger exactly as it
is on the cursor for a mouse.
* It excludes form fields and jQuery-UI sortables (lists/swimlanes/cards
already get touch via touch-punch), and coexists with dragscrollTouch.js,
which already skips the `.nodragscroll` board tiles and handle.
Loaded globally (via pageDragscroll / boardBody, and imported in boardsList).
Adds tests/dragDropTouch.test.cjs pinning the properties above.
This is Option A from the discussion - it keeps every mouse fix and every other
HTML5-DnD feature, rather than rewriting reorder onto jQuery-UI-sortable.
Thanks to xet7 !
47 lines
2.0 KiB
JavaScript
47 lines
2.0 KiB
JavaScript
import dragscroll from '@wekanteam/dragscroll';
|
|
import '/client/lib/dragscrollTouch';
|
|
import '/client/lib/dragDropTouch';
|
|
|
|
// Enable / disable mouse drag-to-scroll for whole-page layouts (All Boards,
|
|
// My Cards, Login, Register).
|
|
//
|
|
// The dragscroll library scrolls whichever element carries the `dragscroll`
|
|
// class AND is the actual scroll container. Which element that is depends on
|
|
// the layout and on mobile vs desktop mode:
|
|
//
|
|
// * Login / Register (userFormsLayout) have no `#content`; the page scroll
|
|
// container is `<body>` in both modes (it has `overflow-y: auto` and a
|
|
// `100vh` height).
|
|
// * All Boards / My Cards (defaultLayout) render inside `#content`. On
|
|
// desktop the scroll container is `<body>`; in mobile mode `<body>` becomes
|
|
// `position: fixed` and `#content` becomes the scroller
|
|
// (`overflow-y: auto; height: calc(100vh - 48px)`), so tagging only
|
|
// `<body>` would never scroll on a phone.
|
|
//
|
|
// To cover every case we tag BOTH `<body>` and `#content` (when present). Only
|
|
// the element that actually overflows scrolls, so there is no double-scroll:
|
|
// on desktop `<body>` scrolls and `#content` (no vertical overflow) is a no-op;
|
|
// in mobile mode `#content` scrolls and `<body>` (fixed, no overflow) is a
|
|
// no-op. dragscroll has a dedicated `el == document.body` branch for the body
|
|
// case. dragscroll.reset() re-scans the DOM and (re)binds the mouse listeners.
|
|
// One-finger touch scrolling is handled by client/lib/dragscrollTouch.js, which
|
|
// picks the nearest scrollable `.dragscroll` ancestor (so `#content` wins over
|
|
// `<body>` when both are tagged).
|
|
|
|
function pageScrollEls() {
|
|
const els = [document.body];
|
|
const content = document.getElementById('content');
|
|
if (content) els.push(content);
|
|
return els;
|
|
}
|
|
|
|
export function enablePageDragscroll() {
|
|
pageScrollEls().forEach(el => el.classList.add('dragscroll'));
|
|
dragscroll.reset();
|
|
}
|
|
|
|
export function disablePageDragscroll() {
|
|
pageScrollEls().forEach(el => el.classList.remove('dragscroll'));
|
|
dragscroll.reset();
|
|
}
|