Aevann 2024-01-14 16:09:55 +02:00
parent 33106f54b9
commit 23bfbc5de0
1 changed files with 64 additions and 63 deletions

View File

@ -45,27 +45,27 @@ if (fake_textarea) {
//SWIPING //SWIPING
if (screen_width < 768) {
const post_ids = localStorage.getItem("post_ids").split(', ');
const current_index = post_ids.indexOf(pid)
const id_after = post_ids[current_index+1]
const id_before = post_ids[current_index-1]
const post_ids = localStorage.getItem("post_ids").split(', '); const _C = document.querySelector('.container')
const current_index = post_ids.indexOf(pid) const N = _C.children.length
const id_after = post_ids[current_index+1] const NF = 30
const id_before = post_ids[current_index-1]
const _C = document.querySelector('.container') let i = 0, x0 = null, y0 = null, locked = false, w, ini, fin, rID = null, anf, n;
const N = _C.children.length
const NF = 30
let i = 0, x0 = null, y0 = null, locked = false, w, ini, fin, rID = null, anf, n; function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e }; function lock(e) {
function lock(e) {
x0 = unify(e).clientX; x0 = unify(e).clientX;
y0 = unify(e).clientY; y0 = unify(e).clientY;
locked = true locked = true
}; };
function drag(e) { function drag(e) {
if(locked) { if(locked) {
let dx = unify(e).clientX - x0 let dx = unify(e).clientX - x0
let f = +(dx/w).toFixed(2); let f = +(dx/w).toFixed(2);
@ -74,17 +74,17 @@ function drag(e) {
let fy = +(dy/y).toFixed(2); let fy = +(dy/y).toFixed(2);
if (!getSelection().toString() && (f > 0.04 || f < -0.04) && (fy < 0.02 && fy > -0.02)) { if (!getSelection().toString() && (f > 0.04 || f < -0.04) && (fy < 0.02 && fy > -0.02)) {
if (id_before && (f > 0.2 || (screen_width > 768 && f > 0.1))) { if (id_before && f > 0.2) {
location.href = `/post/${id_before}` location.href = `/post/${id_before}`
} }
if (id_after && (f < -0.2 || (screen_width > 768 && f < -0.1))) { if (id_after && f < -0.2) {
location.href = `/post/${id_after}` location.href = `/post/${id_after}`
} }
} }
} }
}; };
function move(e) { function move(e) {
if(locked) { if(locked) {
let dx = unify(e).clientX - x0, let dx = unify(e).clientX - x0,
s = Math.sign(dx), s = Math.sign(dx),
@ -104,23 +104,24 @@ function move(e) {
y0 = null; y0 = null;
locked = false; locked = false;
} }
}; };
function size() { function size() {
w = window.innerWidth w = window.innerWidth
y = window.innerHeight y = window.innerHeight
}; };
size(); size();
_C.style.setProperty('--n', N); _C.style.setProperty('--n', N);
addEventListener('resize', size, false); addEventListener('resize', size, false);
_C.addEventListener('mousedown', lock, false); _C.addEventListener('mousedown', lock, false);
_C.addEventListener('touchstart', lock, false); _C.addEventListener('touchstart', lock, false);
_C.addEventListener('mousemove', drag, false); _C.addEventListener('mousemove', drag, false);
_C.addEventListener('touchmove', drag, false); _C.addEventListener('touchmove', drag, false);
_C.addEventListener('mouseup', move, false); _C.addEventListener('mouseup', move, false);
_C.addEventListener('touchend', move, false); _C.addEventListener('touchend', move, false);
}