aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/features')
-rw-r--r--src/features/messages.js90
1 files changed, 72 insertions, 18 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index a8815b0..7760654 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -12177,7 +12177,7 @@ export function messagesFeature(ctx) {
slide._ev = ev;
slide._rowId = it.row ? it.row.id : ev.id; // the feed row to land on (a repost's wrapper, not its inner post)
// pinch to zoom a picture (drag pans it zoomed; the wheel is the pager's)
- if (!video && ctx.attachZoom) ctx.attachZoom(slide, media, { wheel: false });
+ if (!video && ctx.attachZoom) ctx.attachZoom(slide, media, { wheel: 'ctrl' }); // ctrl+wheel (a pinch) zooms; the plain wheel is the pager's
if (video) {
guardPicture(media, url);
media.muted = !pagerLoud;
@@ -12470,6 +12470,33 @@ export function messagesFeature(ctx) {
return y ? box.scrollTop + r.top - b.top : box.scrollLeft + r.left - b.left;
};
const pagerHold = (box) => { if (box && box._glide) { cancelAnimationFrame(box._glide); box._glide = 0; } };
+ // the slide on screen — named, not "a screen further", which from a
+ // scroll still settling landed short
+ const pagerHere = () => pager && (pagerSlides().find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.left) < r.width / 2 && Math.abs(r.top) < r.height / 2; }) || pager.cur);
+ // A step: v up or down the posts (-1/1), hz along the post's pictures.
+ // The keys, the wheel and the desktop arrows all come here.
+ function pagerStep(v, hz) {
+ if (!pager) return false;
+ const here = pagerHere();
+ if (v) {
+ const from = pager.onTail || !here ? pager.tail : here.closest('.mp-group');
+ const to = from && (v > 0 ? from.nextElementSibling : from.previousElementSibling);
+ if (to) pagerGlide(pager.scroller, 'y', pagerAt(pager.scroller, to, true));
+ return !!to;
+ }
+ if (hz) {
+ const to = !pager.onTail && here && (hz > 0 ? here.nextElementSibling : here.previousElementSibling);
+ if (to) pagerGlide(here.parentElement, 'x', pagerAt(here.parentElement, to, false));
+ return !!to;
+ }
+ return false;
+ }
+ // the sideways arrows show only where the post has a picture that way
+ function pagerArrows(slide) {
+ if (!pager || !slide) return;
+ pager.el.classList.toggle('has-left', !!slide.previousElementSibling);
+ pager.el.classList.toggle('has-right', !!slide.nextElementSibling);
+ }
function buildPager(want) {
const video = want.kind === 'videos';
@@ -12479,7 +12506,48 @@ export function messagesFeature(ctx) {
h('div', { class: 'mp-top' },
h('button', { class: 'mp-x', type: 'button', 'aria-label': t('close'), onClick: (e) => { e.stopPropagation(); dismissPager(); } }, '×'),
video ? h('button', { class: 'mp-sound', type: 'button', onClick: (e) => { e.stopPropagation(); pagerSound(!pagerLoud); } },
- h('span', { class: 'on' }, '\u{1F50A}'), h('span', { class: 'off' }, '\u{1F507} ' + t('videoUnmute'))) : null));
+ h('span', { class: 'on' }, '\u{1F50A}'), h('span', { class: 'off' }, '\u{1F507} ' + t('videoUnmute'))) : null),
+ // a mouse's way through (shown where there is a pointer to hover with,
+ // style.css): up and down the posts at the right edge, left and right
+ // along a post's pictures when it has more than one (has-left/right)
+ h('div', { class: 'mp-arrows' }, ...[['mp-up', 'pagerPrevPost', 'M6 15l6-6 6 6', -1, 0], ['mp-down', 'pagerNextPost', 'M6 9l6 6 6-6', 1, 0],
+ ['mp-ar-left', 'pagerPrevPic', 'M15 6l-6 6 6 6', 0, -1], ['mp-ar-right', 'pagerNextPic', 'M9 6l6 6-6 6', 0, 1]].map(([cls, label, d, v, hz]) =>
+ h('button', { class: 'mp-arrow ' + cls, type: 'button', 'aria-label': t(label), title: t(label), onClick: (e) => { e.stopPropagation(); pagerStep(v, hz); } },
+ h('span', { style: 'display:flex', html: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="' + d + '"/></svg>' })))));
+ // A mouse wheel pages: a notch down is the next post, a notch up the one
+ // before, a breath between steps so a spin of the wheel doesn't skip
+ // five. A trackpad's run of small deltas is one step per run (its first
+ // 40px; the rest of the run, until a pause, is spent), and a sideways
+ // run — or shift+wheel — walks along the post's pictures. Ctrl+wheel (a
+ // trackpad's pinch comes the same way) zooms the picture and the wheel
+ // pans it while zoomed: attachZoom takes those first (defaultPrevented).
+ // Left to the browser, a notch scrolled the snap container a hundred
+ // pixels and the glide's snap put it straight back: the wheel did nothing.
+ let wheelStepAt = 0, run = null;
+ el.addEventListener('wheel', (e) => {
+ if (!pager || e.defaultPrevented || e.ctrlKey || e.metaKey) return;
+ if (e.target.closest && e.target.closest('.mp-caption.open, .mp-seek')) return;
+ e.preventDefault();
+ const k = e.deltaMode === 1 ? 40 : 1;
+ let dx = e.deltaX * k, dy = e.deltaY * k;
+ if (e.shiftKey && !dx) { dx = dy; dy = 0; }
+ const hz = Math.abs(dx) > Math.abs(dy), d = hz ? dx : dy;
+ if (!d) return;
+ const notch = e.deltaMode === 1 || (hz ? e.wheelDeltaX && e.wheelDeltaX % 120 === 0 : e.wheelDeltaY && e.wheelDeltaY % 120 === 0);
+ const now = e.timeStamp;
+ if (notch) {
+ if (now - wheelStepAt < 220) return;
+ } else {
+ if (!run || now - run.at > 150) run = { at: now, acc: 0, done: false };
+ run.at = now;
+ if (run.done) return;
+ run.acc += d;
+ if (Math.abs(run.acc) < 40) return;
+ run.done = true;
+ }
+ wheelStepAt = now;
+ pagerStep(hz ? 0 : Math.sign(d), hz ? Math.sign(d) : 0);
+ }, { passive: false });
// A touch is the pager's to judge, not the browser's. Left to native
// scrolling, a tap whose finger moved a few pixels was taken for a
// scroll (no click: a tap meant to pause a clip did nothing), and a quick
@@ -12635,6 +12703,7 @@ export function messagesFeature(ctx) {
}
pager.cur = e.target;
pager.curAt = Date.now();
+ pagerArrows(e.target);
if (pager.fromFeed) { const row = feedNow().notes.find((x) => x.id === e.target._rowId); markSeen(row || e.target._ev); }
playSlide(e.target);
pagerCounts(e.target);
@@ -12749,22 +12818,7 @@ export function messagesFeature(ctx) {
// up and down: the next post, or the one before; left and right: along this post's row
const v = ['ArrowDown', 'j', 'PageDown'].includes(e.key) ? 1 : ['ArrowUp', 'k', 'PageUp'].includes(e.key) ? -1 : 0;
const hz = ['ArrowRight', 'l'].includes(e.key) ? 1 : ['ArrowLeft', 'h'].includes(e.key) ? -1 : 0;
- // to the slide (or post) next to the one on screen — named, not "a
- // screen further", which from a scroll still settling landed short
- const here = pagerSlides().find((x) => { const r = x.getBoundingClientRect(); return Math.abs(r.left) < r.width / 2 && Math.abs(r.top) < r.height / 2; }) || pager.cur;
- if (v) {
- e.preventDefault();
- const from = pager.onTail || !here ? pager.tail : here.closest('.mp-group');
- const to = from && (v > 0 ? from.nextElementSibling : from.previousElementSibling);
- if (to) pagerGlide(pager.scroller, 'y', pagerAt(pager.scroller, to, true));
- return;
- }
- if (hz) {
- e.preventDefault();
- const to = !pager.onTail && here && (hz > 0 ? here.nextElementSibling : here.previousElementSibling);
- if (to) pagerGlide(here.parentElement, 'x', pagerAt(here.parentElement, to, false));
- return;
- }
+ if (v || hz) { e.preventDefault(); pagerStep(v, hz); return; }
if (e.key === ' ' && pager.cur) {
const v = pager.cur.querySelector('video.mp-media');
if (v) { e.preventDefault(); if (v.paused) v.play().catch(() => {}); else v.pause(); }