Skip to content
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

Remove an outdate check for {passive: true} #3058

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
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
Remove an outdate check for {passive: true}
According to https://caniuse.com/?search=passive,
all browsers released after 2016 do support passive event listeners,
so no need to check for its presence.
  • Loading branch information
jvoisin committed Jan 14, 2025
commit 6333650428516e0849142648fd5284661150a991
19 changes: 0 additions & 19 deletions internal/ui/static/js/dom_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,4 @@ class DomHelper {
const elements = document.querySelectorAll(selector);
return [...elements].filter((element) => this.isVisible(element));
}

static hasPassiveEventListenerOption() {
var passiveSupported = false;

try {
var options = Object.defineProperty({}, "passive", {
get: function() {
passiveSupported = true;
}
});

window.addEventListener("test", options, options);
window.removeEventListener("test", options, options);
} catch(err) {
passiveSupported = false;
}

return passiveSupported;
}
}
24 changes: 12 additions & 12 deletions internal/ui/static/js/touch_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,26 @@ class TouchHandler {
}

listen() {
const hasPassiveOption = DomHelper.hasPassiveEventListenerOption();
const eventListenerOptions = { passive: true };

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);
element.addEventListener("touchstart", (e) => this.onItemTouchStart(e), eventListenerOptions);
element.addEventListener("touchmove", (e) => this.onItemTouchMove(e));
element.addEventListener("touchend", (e) => this.onItemTouchEnd(e), eventListenerOptions);
element.addEventListener("touchcancel", () => this.reset(), eventListenerOptions);
});

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);
element.addEventListener("touchmove", () => this.reset(), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchcancel", () => this.reset(), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchend", (e) => this.onTapEnd(e), eventListenerOptions);
element.addEventListener("touchmove", () => this.reset(), eventListenerOptions);
element.addEventListener("touchcancel", () => this.reset(), eventListenerOptions);
} else if (element.classList.contains("gesture-nav-swipe")) {
element.addEventListener("touchstart", (e) => this.onContentTouchStart(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchmove", (e) => this.onContentTouchMove(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchend", (e) => this.onContentTouchEnd(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchcancel", () => this.reset(), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchstart", (e) => this.onContentTouchStart(e), eventListenerOptions);
element.addEventListener("touchmove", (e) => this.onContentTouchMove(e), eventListenerOptions);
element.addEventListener("touchend", (e) => this.onContentTouchEnd(e), eventListenerOptions);
element.addEventListener("touchcancel", () => this.reset(), eventListenerOptions);
}
}
}
Expand Down
Loading