Files
wekan/models/lib/windowDrag.js
T
Lauri Ojansivu 1b05673200 The opened card and every popup move under a finger: Pointer Events and touch-action.
On an iPad the opened card did not move when dragged by a finger from the collapse
caret, the space beside it, the card number, or the drag handle, while the page
behind it scrolled. The card was moved by mousedown / mousemove / mouseup, and a
finger sends none of them while it moves; the drag areas also lacked
touch-action: none, so the browser took the gesture for a scroll. The card window
is now moved by Pointer Events: a press on the header row or the handle moves it, a
press on a link or button in the row (the caret, close, the menu) waits for a real
drag so a tap still does its job and a drag does not also collapse or close, the
title still edits, and with drag handles on the handle alone moves the window. The
card number is above the title's edit zone so it drags too, the window is kept
within reach, and touch-action: none is on the card header, its handle and every
popup's title bar and handle. Blaze hands over a jQuery event without isPrimary, so
the native event is read.

A browser spec drags with a real touch (DevTools protocol, Pointer Events) from the
caret, the number and the space beside the title, with handles on and off, a tap
that still collapses, a mouse that still drags and a popup; without the fix the
finger tests fail.

Thanks to xet7 !
2026-11-04 01:00:19 +02:00

59 lines
2.6 KiB
JavaScript

'use strict';
// Moving a window - the opened card, a popup - with a finger as well as a mouse.
// The decisions only, apart from the DOM, so plain Node tests can drive them.
//
// A mouse sends mousedown / mousemove / mouseup; a finger sends none of them while it
// moves (only a click after a tap), so a window moved by those events could not be
// moved on an iPad at all, while the page behind it scrolled. Pointer Events carry
// both, and a drag area also needs `touch-action: none`, or the browser takes the
// gesture for a scroll and cancels the pointer.
const TOUCH_THRESHOLD = 8; // px a finger may wobble in a tap
const MOUSE_THRESHOLD = 4;
// What a press on the card's header row does. All booleans are about the pressed
// element:
// onEditable an input, textarea, select or option, or the open title editor:
// the browser keeps those (text selection, caret)
// onTitleEditZone the title, which edits - all of it
// onHandle the drag handle
// cardHasHandle drag handles are on for this card: the handle is then the only
// thing that moves the window
// onControl a link or button (the collapse caret, close, maximize, menu):
// a tap does its job, a DRAG moves the window
// Returns { start, deferred }: whether the press can move the window, and whether it
// waits for the finger or mouse to move first (so a tap on a control still works).
function cardHeaderPress({ onEditable, onTitleEditZone, onHandle, cardHasHandle, onControl }) {
if (onHandle) return { start: true, deferred: false };
if (onEditable || onTitleEditZone) return { start: false, deferred: false };
if (cardHasHandle) return { start: false, deferred: false };
return { start: true, deferred: !!onControl };
}
function dragThreshold(pointerType, deferred) {
if (!deferred) return 0;
return pointerType === 'mouse' ? MOUSE_THRESHOLD : TOUCH_THRESHOLD;
}
function passedThreshold(dx, dy, threshold) {
return Math.hypot(dx, dy) >= threshold;
}
// Keeps a window where it can be found again: at least `keep` px of its top-left
// strip stays inside the viewport, so its header can always be grabbed.
function clampWindow(left, top, width, viewport, keep = 48) {
const minLeft = keep - width;
const maxLeft = viewport.width - keep;
const maxTop = viewport.height - keep;
return {
left: Math.min(Math.max(left, minLeft), Math.max(minLeft, maxLeft)),
top: Math.min(Math.max(top, 0), Math.max(0, maxTop)),
};
}
module.exports = { cardHeaderPress, dragThreshold, passedThreshold, clampWindow, TOUCH_THRESHOLD, MOUSE_THRESHOLD };