WebUI: use native functions for event handling

PR #21147.
This commit is contained in:
Chocobo1
2024-08-07 22:00:54 +08:00
committed by GitHub
parent 989b1d176d
commit 2d9e3b3330
30 changed files with 261 additions and 196 deletions

View File

@@ -112,8 +112,8 @@ window.qBittorrent.ContextMenu ??= (() => {
});
// position the menu
let xPosMenu = e.page.x + this.options.offsets.x;
let yPosMenu = e.page.y + this.options.offsets.y;
let xPosMenu = e.pageX + this.options.offsets.x;
let yPosMenu = e.pageY + this.options.offsets.y;
if ((xPosMenu + this.menu.offsetWidth) > document.documentElement.clientWidth)
xPosMenu -= this.menu.offsetWidth;
if ((yPosMenu + this.menu.offsetHeight) > document.documentElement.clientHeight)
@@ -156,19 +156,19 @@ window.qBittorrent.ContextMenu ??= (() => {
},
setupEventListeners: function(elem) {
elem.addEvent("contextmenu", (e) => {
elem.addEventListener("contextmenu", (e) => {
this.triggerMenu(e, elem);
});
elem.addEvent("click", (e) => {
elem.addEventListener("click", (e) => {
this.hide();
});
elem.addEvent("touchstart", (e) => {
elem.addEventListener("touchstart", (e) => {
this.hide();
this.touchStartAt = performance.now();
this.touchStartEvent = e;
});
elem.addEvent("touchend", (e) => {
elem.addEventListener("touchend", (e) => {
const now = performance.now();
const touchStartAt = this.touchStartAt;
const touchStartEvent = this.touchStartEvent;
@@ -196,8 +196,10 @@ window.qBittorrent.ContextMenu ??= (() => {
return;
// prevent default, if told to
if (this.options.stopEvent)
e.stop();
if (this.options.stopEvent) {
e.preventDefault();
e.stopPropagation();
}
// record this as the trigger
this.options.element = $(el);
this.adjustMenuPosition(e);
@@ -214,7 +216,7 @@ window.qBittorrent.ContextMenu ??= (() => {
/* menu items */
this.menu.getElements("a").each(function(item) {
item.addEvent("click", (e) => {
item.addEventListener("click", (e) => {
e.preventDefault();
if (!item.hasClass("disabled")) {
this.execute(item.href.split("#")[1], $(this.options.element));
@@ -224,7 +226,7 @@ window.qBittorrent.ContextMenu ??= (() => {
}, this);
// hide on body click
$(document.body).addEvent("click", () => {
$(document.body).addEventListener("click", () => {
this.hide();
});
},
@@ -647,8 +649,8 @@ window.qBittorrent.ContextMenu ??= (() => {
top: "-999em"
});
// position the menu
let xPosMenu = e.page.x + this.options.offsets.x - $("rssdownloaderpage").offsetLeft;
let yPosMenu = e.page.y + this.options.offsets.y - $("rssdownloaderpage").offsetTop;
let xPosMenu = e.pageX + this.options.offsets.x - $("rssdownloaderpage").offsetLeft;
let yPosMenu = e.pageY + this.options.offsets.y - $("rssdownloaderpage").offsetTop;
if ((xPosMenu + this.menu.offsetWidth) > document.documentElement.clientWidth)
xPosMenu -= this.menu.offsetWidth;
if ((yPosMenu + this.menu.offsetHeight) > document.documentElement.clientHeight)