mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Four things reported while using mobile mode, three of them in the second header
bar.
Drag-to-scroll now works on BOTH top header bars, not only below them. Everywhere
else a drag scrolls - `.board-canvas.dragscroll` on a board, `<body>` / `#content`
on the whole-page layouts - but the two header bars were dead, and on a phone they
are a large share of what is on screen. They cannot simply be tagged `.dragscroll`:
that class scrolls the element carrying it, and neither bar is a scroll container -
`#header` sits outside `#content` and outside the board canvas. So a new module,
client/lib/headerDragscroll.js, forwards the drag to whatever actually scrolls: a
scroller inside the header first (the starred-boards list is overflow-x:auto), then
the board canvas, then the page scroller. Both bars are `.nodragscroll` so the
page-level dragscroll does not scroll a second time from the same gesture. Mouse and
touch are both handled - a phone sends no mouse events, and the dragscroll library is
mouse-only and element-bound. A tap is still a tap: scrolling starts only past a 4px
threshold, and only then is the click that ends the gesture swallowed, in the capture
phase, so dragging across the bar does not press whatever you let go over.
The second header bar on a phone now reads title, buttons, hamburger. The board title
is shown again - it was hidden by a `display: none !important` that predates this
work, which left the bar with nothing but icons, so you could not tell which board you
were on. A board name is how you know where you are, so it wraps rather than
truncating. The buttons start at the right of the title and drop to a second row as a
block when the space between the title and the menu button runs out; they are one flex
item, so they never split across the two rows.
The sidebar hamburger, with its divider to its left, is pinned in the TOP RIGHT
corner. It was lifted out of the `.right` group into its own flex item placed after
the title, because inside that group it could only ever wrap down together with the
other buttons - a flex line breaks in order. On a phone it is taken out of the flow
(position:absolute) and the bar reserves its width as end padding, so a long title or
a full row of buttons never runs underneath it; that reservation is board-only, since
the same bar on All Boards has no hamburger. On a wide screen `order: 1` puts it back
at the end of the bar, visually identical to before.
Lists and cards are full width in mobile mode on a DESKTOP browser too, not only on a
phone. Two causes, both from mobile mode being decided in two places that disagreed:
* Utils.isMiniScreen(), which drives the `mobile-view` class on each list, swimlane
and minicard, looked only at screen width and user agent. The explicit toggle was
honoured on iPhone only - and even there through a test that could never be false,
since getMobileMode() falls back to viewport detection and so always returns a
boolean. An explicit choice now wins on every device, via a new
getExplicitMobileMode() that can answer "never chosen"; the per-device branches
below it are the defaults for that case.
* `.mobile-mode .list { width: 100% !important }` was outranked by
`.js-swimlane .list[style*="--list-width"] { width: var(--list-width) !important }`
- both !important, and the second more specific. It never showed on a phone (no
inline --list-width is emitted there), only in mobile mode on a desktop window.
The override repeats those three selectors prefixed with body.mobile-mode, and
keeps the :not(.list-collapsed) exclusion so a collapsed list stays 30px (#5892).
Also adds tests/jadeCompiles.test.cjs, which compiles every .jade with the SAME
compiler the build uses. Nothing else caught a broken template: the other suites read
.jade as text and grep it, so a file the compiler rejects still passes them all. It
was written after a `<body>` inside an indented `//-` comment block broke the build
here - the comment text is still lexed, so the angle brackets opened a tag that never
closed. All 107 templates parse in ~0.2s.
tests/headerHamburger.test.cjs asserted the hamburger sits inside the `.right` group,
which is exactly what moved; it now checks the new wrapper, its divider, and that
`order` still puts it last on a wide screen.
Tests: 1309 passing.
Thanks to xet7 !
165 lines
6.1 KiB
JavaScript
165 lines
6.1 KiB
JavaScript
// Drag-to-scroll starting on the two top header bars.
|
|
//
|
|
// Everywhere else a drag scrolls: `.board-canvas.dragscroll` on a board, and
|
|
// `<body>` / `#content` on the whole-page layouts (see client/lib/pageDragscroll.js).
|
|
// The header bars were the one dead area - grabbing the quick-access bar or the
|
|
// board bar and dragging did nothing, so on a phone, where those two bars take a
|
|
// large share of the screen, most of what you could put a finger on was unscrollable.
|
|
//
|
|
// They cannot simply be tagged `.dragscroll`: that class scrolls the element that
|
|
// carries it, and neither bar is a scroll container - `#header` has no overflow and
|
|
// sits OUTSIDE `#content` and outside the board canvas. So a drag that starts here
|
|
// is forwarded to whichever element actually scrolls:
|
|
//
|
|
// 1. a scrollable container under the pointer, inside the header itself - the
|
|
// starred-boards list is `overflow-x: auto` and does overflow once you star a
|
|
// few boards, so dragging it scrolls it sideways rather than the page;
|
|
// 2. otherwise the board canvas, when we are on a board;
|
|
// 3. otherwise the page scroller: `#content` in mobile mode (where `<body>` is
|
|
// position:fixed), `<body>` on desktop.
|
|
//
|
|
// Mouse and touch are both handled here. The @wekanteam/dragscroll library is
|
|
// mouse-only and element-bound, and client/lib/dragscrollTouch.js only picks
|
|
// `.dragscroll` ancestors, so neither can express "drag here, scroll there".
|
|
//
|
|
// Clicks still work: scrolling only begins after the pointer has moved past a small
|
|
// threshold, and only then is the click that ends the gesture swallowed - otherwise
|
|
// dragging across the bar would fire whatever button you happened to let go over.
|
|
|
|
const HEADER_SELECTOR = '#header-quick-access, #header';
|
|
|
|
// Threshold in px before a press becomes a drag. Small enough to feel immediate,
|
|
// large enough that a tap with a shaky finger is still a tap.
|
|
const DRAG_THRESHOLD = 4;
|
|
|
|
let active = null;
|
|
let dragged = false;
|
|
|
|
function isExcluded(target) {
|
|
return !!(
|
|
target.closest &&
|
|
// Form fields keep their own behaviour (the zoom-level input lives in the
|
|
// quick-access bar), and `.nodragscroll` opts an element out explicitly.
|
|
target.closest('input, select, textarea, .note-editable, .nodragscroll')
|
|
);
|
|
}
|
|
|
|
function canScroll(el) {
|
|
return (
|
|
el && (el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth)
|
|
);
|
|
}
|
|
|
|
// A scroll container between the pointer and the header bar - the starred-boards
|
|
// list. Walking up ourselves rather than using closest() because we are looking for
|
|
// a computed property, not a class.
|
|
function scrollableInsideHeader(target, header) {
|
|
let el = target;
|
|
while (el && el !== header) {
|
|
if (el.nodeType === 1 && canScroll(el)) {
|
|
const overflow = getComputedStyle(el).overflow + getComputedStyle(el).overflowX;
|
|
if (/auto|scroll/.test(overflow)) return el;
|
|
}
|
|
el = el.parentElement;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Where a drag on the header should send its scrolling.
|
|
export function resolveScrollTarget(target, header) {
|
|
const inside = scrollableInsideHeader(target, header);
|
|
if (inside) return inside;
|
|
const canvas = document.querySelector('.board-canvas');
|
|
if (canScroll(canvas)) return canvas;
|
|
const content = document.getElementById('content');
|
|
if (canScroll(content)) return content;
|
|
return document.scrollingElement || document.body;
|
|
}
|
|
|
|
function start(clientX, clientY, target) {
|
|
active = null;
|
|
dragged = false;
|
|
if (isExcluded(target)) return;
|
|
const header = target.closest && target.closest(HEADER_SELECTOR);
|
|
if (!header) return;
|
|
const el = resolveScrollTarget(target, header);
|
|
if (!el) return;
|
|
active = {
|
|
el,
|
|
startX: clientX,
|
|
startY: clientY,
|
|
scrollLeft: el.scrollLeft,
|
|
scrollTop: el.scrollTop,
|
|
};
|
|
}
|
|
|
|
// Returns true once the gesture counts as a drag, so the caller can suppress the
|
|
// browser's own default (text selection, page rubber-banding).
|
|
function move(clientX, clientY) {
|
|
if (!active) return false;
|
|
const dx = clientX - active.startX;
|
|
const dy = clientY - active.startY;
|
|
if (!dragged && Math.abs(dx) < DRAG_THRESHOLD && Math.abs(dy) < DRAG_THRESHOLD) {
|
|
return false;
|
|
}
|
|
dragged = true;
|
|
active.el.scrollLeft = active.scrollLeft - dx;
|
|
active.el.scrollTop = active.scrollTop - dy;
|
|
return true;
|
|
}
|
|
|
|
function onMouseDown(e) {
|
|
// Left button only: a right-click opens the context menu, a middle-click pastes.
|
|
if (e.button !== 0) return;
|
|
start(e.clientX, e.clientY, e.target);
|
|
}
|
|
|
|
function onMouseMove(e) {
|
|
// Stop the browser selecting the header text under the moving pointer.
|
|
if (move(e.clientX, e.clientY)) e.preventDefault();
|
|
}
|
|
|
|
function onMouseUp() {
|
|
active = null;
|
|
}
|
|
|
|
// A drag must not also activate the button it ends on. Capture phase, so this runs
|
|
// before the component's own click handler.
|
|
function onClick(e) {
|
|
if (!dragged) return;
|
|
dragged = false;
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
function onTouchStart(e) {
|
|
if (e.touches.length !== 1) return;
|
|
const touch = e.touches[0];
|
|
start(touch.clientX, touch.clientY, e.target);
|
|
}
|
|
|
|
function onTouchMove(e) {
|
|
if (!active || e.touches.length !== 1) return;
|
|
const touch = e.touches[0];
|
|
// We own the gesture once it is a drag: suppress rubber-banding and the
|
|
// synthetic mouse events that would otherwise scroll a second time.
|
|
if (move(touch.clientX, touch.clientY) && e.cancelable) e.preventDefault();
|
|
}
|
|
|
|
function onTouchEnd() {
|
|
active = null;
|
|
}
|
|
|
|
// Guard so importing this from more than one place still attaches the listeners once.
|
|
if (typeof document !== 'undefined' && !window.__wekanHeaderDragscroll) {
|
|
window.__wekanHeaderDragscroll = true;
|
|
document.addEventListener('mousedown', onMouseDown, { passive: true });
|
|
document.addEventListener('mousemove', onMouseMove, { passive: false });
|
|
document.addEventListener('mouseup', onMouseUp, { passive: true });
|
|
document.addEventListener('click', onClick, true);
|
|
document.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
document.addEventListener('touchmove', onTouchMove, { passive: false });
|
|
document.addEventListener('touchend', onTouchEnd, { passive: true });
|
|
document.addEventListener('touchcancel', onTouchEnd, { passive: true });
|
|
}
|