mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
refactor(js): minor refactoring of touch_handler.js
- Mark a method as `static` - use `Math.sqrt` instead of `Math.pow(…, 0.5)` - Use `Math.sign` instead of a condition on the sign - Inline some used-once variables - Reduce the scope of some variables
This commit is contained in:
parent
8c3a9184ac
commit
fccca0ce1e
1 changed files with 13 additions and 19 deletions
|
@ -26,7 +26,7 @@ class TouchHandler {
|
|||
return 0;
|
||||
}
|
||||
|
||||
findElement(element) {
|
||||
static findElement(element) {
|
||||
if (element.classList.contains("entry-swipe")) {
|
||||
return element;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class TouchHandler {
|
|||
this.reset();
|
||||
this.touch.start.x = event.touches[0].clientX;
|
||||
this.touch.start.y = event.touches[0].clientY;
|
||||
this.touch.element = this.findElement(event.touches[0].target);
|
||||
this.touch.element = TouchHandler.findElement(event.touches[0].target);
|
||||
this.touch.element.style.transitionDuration = "0s";
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,7 @@ class TouchHandler {
|
|||
if (absDistance > 0) {
|
||||
this.touch.moved = true;
|
||||
|
||||
let tx = absDistance > 75 ? Math.pow(absDistance - 75, 0.5) + 75 : absDistance;
|
||||
|
||||
if (distance < 0) {
|
||||
tx = -tx;
|
||||
}
|
||||
const tx = (absDistance > 75 ? Math.sqrt(absDistance - 75) + 75 : absDistance) * Math.sign(distance);
|
||||
|
||||
this.touch.element.style.transform = "translateX(" + tx + "px)";
|
||||
|
||||
|
@ -78,9 +74,7 @@ class TouchHandler {
|
|||
}
|
||||
|
||||
if (this.touch.element !== null) {
|
||||
const absDistance = Math.abs(this.calculateDistance());
|
||||
|
||||
if (absDistance > 75) {
|
||||
if (Math.abs(this.calculateDistance()) > 75) {
|
||||
toggleEntryStatus(this.touch.element);
|
||||
}
|
||||
|
||||
|
@ -118,15 +112,15 @@ class TouchHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
const distance = this.calculateDistance();
|
||||
const absDistance = Math.abs(distance);
|
||||
const now = Date.now();
|
||||
|
||||
if (now - this.touch.time <= 1000 && absDistance > 75) {
|
||||
if (distance > 0) {
|
||||
goToPage("previous");
|
||||
} else {
|
||||
goToPage("next");
|
||||
if (Date.now() - this.touch.time <= 1000) {
|
||||
const distance = this.calculateDistance();
|
||||
const absDistance = Math.abs(distance);
|
||||
if (absDistance > 75) {
|
||||
if (distance > 0) {
|
||||
goToPage("previous");
|
||||
} else {
|
||||
goToPage("next");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue