Skip to content

feat: Added swipe right/left #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions internal/glance/static/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,45 @@ function initThemePicker() {
})
}

function setupTouch() {
let touchstartX, touchstartY;
let touchendX, touchendY;
let touchstartT, touchendT;

document.addEventListener('touchstart', function (event) {
touchstartX = event.changedTouches[0].screenX;
touchstartY = event.changedTouches[0].screenY;
touchstartT = new Date();
}, false);

document.addEventListener('touchend', function (event) {
touchendX = event.changedTouches[0].screenX;
touchendY = event.changedTouches[0].screenY;
touchendT = new Date();
let touchTime = touchendT - touchstartT;

const swipeThresholdX = 50; //Min horizontal
const swipeThresholdY = 150; //Max vertical
const swipeThresholdT = 800; //Max time

let touchX = Math.abs(touchendX - touchstartX);
let touchY = Math.abs(touchendY - touchstartY);

if (touchX > touchY*2 && touchX > swipeThresholdX && touchY < swipeThresholdY && touchTime < swipeThresholdT) {
let pos = document.querySelector('input[name="column"]:checked').value;
let maxCol = document.getElementsByName('column').length-1;
if (touchendX < touchstartX) {
pos++
pos = pos > maxCol ? 0 : pos;
} else {
pos--
pos = pos < 0 ? maxCol : pos;
}
document.querySelector('input[name="column"][value="' + pos + '"]').click();
}
}, false);
}

async function setupPage() {
initThemePicker();

Expand All @@ -763,6 +802,7 @@ async function setupPage() {
setupMasonries();
setupDynamicRelativeTime();
setupLazyImages();
setupTouch();
} finally {
pageElement.classList.add("content-ready");
pageElement.setAttribute("aria-busy", "false");
Expand Down