aboutsummaryrefslogtreecommitdiff
path: root/internal/ui/static/js/touch_handler.js
diff options
context:
space:
mode:
authorGravatar jvoisin <julien.voisin@dustri.org> 2024-03-20 23:59:37 +0100
committerGravatar Frédéric Guillot <f@miniflux.net> 2024-03-20 17:36:01 -0700
commitbeb8c80787beadbfdb8b970368a3200f7d59f58e (patch)
tree1096a698ef89494cc58a5d81be15bc9ca56422d7 /internal/ui/static/js/touch_handler.js
parentfc4bdf3ab0088c8110905148951a26412bdef3ec (diff)
downloadv2-beb8c80787beadbfdb8b970368a3200f7d59f58e.tar.gz
v2-beb8c80787beadbfdb8b970368a3200f7d59f58e.tar.zst
v2-beb8c80787beadbfdb8b970368a3200f7d59f58e.zip
Replace a bunch of `let` with `const`
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const > Many style guides (including MDN's) recommend using const over let whenever a variable is not reassigned in its scope. This makes the intent clear that a variable's type (or value, in the case of a primitive) can never change.
Diffstat (limited to 'internal/ui/static/js/touch_handler.js')
-rw-r--r--internal/ui/static/js/touch_handler.js29
1 files changed, 13 insertions, 16 deletions
diff --git a/internal/ui/static/js/touch_handler.js b/internal/ui/static/js/touch_handler.js
index 37c14e86..ef28d858 100644
--- a/internal/ui/static/js/touch_handler.js
+++ b/internal/ui/static/js/touch_handler.js
@@ -15,8 +15,8 @@ class TouchHandler {
calculateDistance() {
if (this.touch.start.x >= -1 && this.touch.move.x >= -1) {
- let horizontalDistance = Math.abs(this.touch.move.x - this.touch.start.x);
- let verticalDistance = Math.abs(this.touch.move.y - this.touch.start.y);
+ const horizontalDistance = Math.abs(this.touch.move.x - this.touch.start.x);
+ const verticalDistance = Math.abs(this.touch.move.y - this.touch.start.y);
if (horizontalDistance > 30 && verticalDistance < 70 || this.touch.moved) {
return this.touch.move.x - this.touch.start.x;
@@ -54,8 +54,8 @@ class TouchHandler {
this.touch.move.x = event.touches[0].clientX;
this.touch.move.y = event.touches[0].clientY;
- let distance = this.calculateDistance();
- let absDistance = Math.abs(distance);
+ const distance = this.calculateDistance();
+ const absDistance = Math.abs(distance);
if (absDistance > 0) {
this.touch.moved = true;
@@ -78,7 +78,7 @@ class TouchHandler {
}
if (this.touch.element !== null) {
- let absDistance = Math.abs(this.calculateDistance());
+ const absDistance = Math.abs(this.calculateDistance());
if (absDistance > 75) {
toggleEntryStatus(this.touch.element);
@@ -118,9 +118,9 @@ class TouchHandler {
return;
}
- let distance = this.calculateDistance();
- let absDistance = Math.abs(distance);
- let now = Date.now();
+ const distance = this.calculateDistance();
+ const absDistance = Math.abs(distance);
+ const now = Date.now();
if (now - this.touch.time <= 1000 && absDistance > 75) {
if (distance > 0) {
@@ -138,10 +138,10 @@ class TouchHandler {
return;
}
- let now = Date.now();
+ const now = Date.now();
if (this.touch.start.x !== -1 && now - this.touch.time <= 200) {
- let innerWidthHalf = window.innerWidth / 2;
+ const innerWidthHalf = window.innerWidth / 2;
if (this.touch.start.x >= innerWidthHalf && event.changedTouches[0].clientX >= innerWidthHalf) {
goToPage("next");
@@ -158,19 +158,16 @@ class TouchHandler {
}
listen() {
- let hasPassiveOption = DomHelper.hasPassiveEventListenerOption();
+ const hasPassiveOption = DomHelper.hasPassiveEventListenerOption();
- let elements = document.querySelectorAll(".entry-swipe");
-
- elements.forEach((element) => {
+ document.querySelectorAll(".entry-swipe").forEach((element) => {
element.addEventListener("touchstart", (e) => this.onItemTouchStart(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchmove", (e) => this.onItemTouchMove(e), hasPassiveOption ? { passive: false } : false);
element.addEventListener("touchend", (e) => this.onItemTouchEnd(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchcancel", () => this.reset(), hasPassiveOption ? { passive: true } : false);
});
- let element = document.querySelector(".entry-content");
-
+ const element = document.querySelector(".entry-content");
if (element) {
if (element.classList.contains("gesture-nav-tap")) {
element.addEventListener("touchend", (e) => this.onTapEnd(e), hasPassiveOption ? { passive: true } : false);