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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 261 additions and 196 deletions

View file

@ -111,12 +111,13 @@ const initializeWindows = function() {
function addClickEvent(el, fn) {
["Link", "Button"].each((item) => {
if ($(el + item))
$(el + item).addEvent("click", fn);
$(el + item).addEventListener("click", fn);
});
}
addClickEvent("download", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
showDownloadPage();
});
@ -148,7 +149,9 @@ const initializeWindows = function() {
};
addClickEvent("preferences", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const id = "preferencesPage";
new MochaUI.Window({
id: id,
@ -173,7 +176,9 @@ const initializeWindows = function() {
});
addClickEvent("upload", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const id = "uploadPage";
new MochaUI.Window({
id: id,
@ -399,7 +404,8 @@ const initializeWindows = function() {
};
addClickEvent("delete", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
deleteFN();
});
@ -1070,7 +1076,8 @@ const initializeWindows = function() {
};
addClickEvent("stopAll", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
if (confirm("QBT_TR(Would you like to stop all torrents?)QBT_TR[CONTEXT=MainWindow]")) {
new Request({
@ -1085,7 +1092,8 @@ const initializeWindows = function() {
});
addClickEvent("startAll", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
if (confirm("QBT_TR(Would you like to start all torrents?)QBT_TR[CONTEXT=MainWindow]")) {
new Request({
@ -1101,7 +1109,9 @@ const initializeWindows = function() {
["stop", "start", "recheck"].each((item) => {
addClickEvent(item, (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
hashes.each((hash, index) => {
@ -1120,7 +1130,8 @@ const initializeWindows = function() {
["decreasePrio", "increasePrio", "topPrio", "bottomPrio"].each((item) => {
addClickEvent(item, (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
setQueuePositionFN(item);
});
});
@ -1140,7 +1151,9 @@ const initializeWindows = function() {
};
addClickEvent("about", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const id = "aboutpage";
new MochaUI.Window({
id: id,
@ -1162,7 +1175,9 @@ const initializeWindows = function() {
});
addClickEvent("logout", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
new Request({
url: "api/v2/auth/logout",
method: "post",
@ -1173,7 +1188,9 @@ const initializeWindows = function() {
});
addClickEvent("shutdown", (e) => {
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
if (confirm("QBT_TR(Are you sure you want to quit qBittorrent?)QBT_TR[CONTEXT=MainWindow]")) {
new Request({
url: "api/v2/app/shutdown",
@ -1191,8 +1208,9 @@ const initializeWindows = function() {
// Deactivate menu header links
$$("a.returnFalse").each((el) => {
el.addEvent("click", (e) => {
new Event(e).stop();
el.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
});
});
};