Skip to content
Snippets Groups Projects
Commit 7541bb12 authored by Alfex4936's avatar Alfex4936
Browse files

Organize project

builders
parent 6bd131c2
No related branches found
No related tags found
No related merge requests found
Pipeline #5487 failed
Showing with 17 additions and 23 deletions
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
...@@ -2,6 +2,7 @@ const setupKeys = () => { ...@@ -2,6 +2,7 @@ const setupKeys = () => {
// Mobile swipe left/right // Mobile swipe left/right
let xDown = null; let xDown = null;
let yDown = null; let yDown = null;
const swipeThreshold = 10; // swipe sensitivity
const handleTouchStart = e => { const handleTouchStart = e => {
xDown = e.touches[0].clientX; xDown = e.touches[0].clientX;
...@@ -13,30 +14,27 @@ const setupKeys = () => { ...@@ -13,30 +14,27 @@ const setupKeys = () => {
return; return;
} }
const xUp = e.touches[0].clientX; const xDiff = xDown - e.touches[0].clientX;
const yUp = e.touches[0].clientY; const yDiff = yDown - e.touches[0].clientY;
const xDiff = xDown - xUp; // alert(Math.abs(xDiff));
const yDiff = yDown - yUp;
if (Math.abs(xDiff) > Math.abs(yDiff)) { if (Math.abs(xDiff) > swipeThreshold && Math.abs(xDiff) > Math.abs(yDiff)) {
if (xDiff > 0) { const direction = xDiff > 0 ? "next" : "back";
const link = document.querySelector(".next a"); triggerLinkClick(direction);
if (link) {
link.click();
}
} else {
const link = document.querySelector(".back a");
if (link) {
link.click();
}
}
} }
xDown = null; xDown = null;
yDown = null; yDown = null;
}; };
const triggerLinkClick = direction => {
const link = document.querySelector(`.${direction} a`);
if (link) {
link.click();
}
};
document.addEventListener("touchstart", handleTouchStart, false); document.addEventListener("touchstart", handleTouchStart, false);
document.addEventListener("touchmove", handleTouchMove, false); document.addEventListener("touchmove", handleTouchMove, false);
...@@ -45,21 +43,17 @@ const setupKeys = () => { ...@@ -45,21 +43,17 @@ const setupKeys = () => {
if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey) { if (e.ctrlKey || e.altKey || e.metaKey || e.shiftKey) {
return; return;
} }
let link;
if (e.key === "Right" || e.key === "ArrowRight") { if (e.key === "Right" || e.key === "ArrowRight") {
link = document.querySelector(".next a"); triggerLinkClick("next");
} }
if (e.key === "Left" || e.key === "ArrowLeft") { if (e.key === "Left" || e.key === "ArrowLeft") {
link = document.querySelector(".back a"); triggerLinkClick("back");
}
if (link) {
link.click();
} }
}); });
}; };
// in code block, should not be same // in code block, should not be same
const codeElement = document.querySelector("iframe"); const codeElement = document.querySelector("code");
if (codeElement) { if (codeElement) {
setupKeys(); setupKeys();
codeElement.addEventListener("load", () => { codeElement.addEventListener("load", () => {
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment