Skip to content

Commit

Permalink
WebUI: use native event listeners for keyboard events
Browse files Browse the repository at this point in the history
PR #21924.
  • Loading branch information
Chocobo1 authored Dec 2, 2024
1 parent e8d8de8 commit 2d1c4fc
Show file tree
Hide file tree
Showing 24 changed files with 264 additions and 357 deletions.
21 changes: 8 additions & 13 deletions src/webui/www/private/addpeers.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@
<script>
"use strict";

new Keyboard({
defaultEventType: "keydown",
events: {
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
}
}).activate();
});

window.addEventListener("DOMContentLoaded", () => {
const hash = new URI().getData("hash");
if (!hash)
return;
Expand Down
15 changes: 5 additions & 10 deletions src/webui/www/private/addtrackers.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Escape":
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
break;
}
}).activate();
});

$("trackersUrls").focus();
$("addTrackersButton").addEventListener("click", (e) => {
Expand Down
17 changes: 6 additions & 11 deletions src/webui/www/private/addwebseeds.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Escape":
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
break;
}
}).activate();
});

$("urls").focus();
$("addWebSeedsButton").addEvent("click", (e) => {
$("addWebSeedsButton").addEventListener("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
Expand Down
4 changes: 2 additions & 2 deletions src/webui/www/private/confirmtrackerdeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
$("confirmDeleteTrackerText").textContent = "QBT_TR(Are you sure you want to remove tracker %1 from all torrents?)QBT_TR[CONTEXT=TrackersFilterWidget]".replace("%1", `"${host}"`);

$("cancelBtn").focus();
$("cancelBtn").addEvent("click", (e) => {
$("cancelBtn").addEventListener("click", (e) => {
e.stopPropagation();
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
$("confirmBtn").addEvent("click", (e) => {
$("confirmBtn").addEventListener("click", (e) => {
e.stopPropagation();
const cmd = "api/v2/torrents/removeTrackers";
new Request({
Expand Down
31 changes: 13 additions & 18 deletions src/webui/www/private/downloadlimit.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
<script>
"use strict";

window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
$("applyButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
});

const hashes = new URI().getData("hashes").split("|");
const setDlLimit = () => {
const limit = Number($("dllimitUpdatevalue").value) * 1024;
Expand Down Expand Up @@ -64,24 +77,6 @@
}
};

new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("applyButton").click();
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
}
}).activate();

$("dllimitUpdatevalue").focus();

MochaUI.addDlLimitSlider(hashes);
Expand Down
29 changes: 12 additions & 17 deletions src/webui/www/private/editfeedurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@
<script>
"use strict";

new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": (event) => {
event.preventDefault();
$("submitButton").click();
},
"Escape": (event) => {
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
},
"Esc": (event) => {
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
$("submitButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
}
}).activate();
});

window.addEventListener("DOMContentLoaded", () => {
const currentUrl = new URI().getData("url");

$("url").value = currentUrl;
Expand Down
21 changes: 8 additions & 13 deletions src/webui/www/private/edittracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("editTrackerButton").click();
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
$("editTrackerButton").click();
break;
case "Escape":
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
break;
}
}).activate();
});

const currentUrl = new URI().getData("url");
if (!currentUrl)
Expand Down
23 changes: 9 additions & 14 deletions src/webui/www/private/editwebseed.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,24 @@
"use strict";

window.addEventListener("DOMContentLoaded", () => {
new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("editWebSeedButton").click();
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
$("editWebSeedButton").click();
break;
case "Escape":
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
break;
}
}).activate();
});

const origUrl = new URI().getData("url");
$("url").value = decodeURIComponent(origUrl);
$("url").focus();

$("editWebSeedButton").addEvent("click", (e) => {
$("editWebSeedButton").addEventListener("click", (e) => {
e.stopPropagation();
const hash = new URI().getData("hash");
new Request({
Expand Down
29 changes: 12 additions & 17 deletions src/webui/www/private/newcategory.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,20 @@
<script>
"use strict";

new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": function(event) {
$("categoryNameButton").click();
event.preventDefault();
},
"Escape": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
},
"Esc": function(event) {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
$("categoryNameButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
}
}).activate();
});

window.addEventListener("DOMContentLoaded", () => {
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes"));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData("categoryName"));
Expand Down
30 changes: 13 additions & 17 deletions src/webui/www/private/newfeed.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,20 @@
<script>
"use strict";

new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": (event) => {
$("submitButton").click();
event.preventDefault();
},
"Escape": (event) => {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
},
"Esc": (event) => {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
}
}).activate();
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
$("submitButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
});

$("feedURL").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => {
Expand Down
30 changes: 13 additions & 17 deletions src/webui/www/private/newfolder.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@
<script>
"use strict";

new Keyboard({
defaultEventType: "keydown",
events: {
"Enter": (event) => {
$("submitButton").click();
event.preventDefault();
},
"Escape": (event) => {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
},
"Esc": (event) => {
window.parent.qBittorrent.Client.closeFrameWindow(window);
event.preventDefault();
}
}
}).activate();
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "Enter":
event.preventDefault();
$("submitButton").click();
break;
case "Escape":
event.preventDefault();
window.parent.qBittorrent.Client.closeFrameWindow(window);
break;
}
});

$("folderName").focus();
const path = new URI().getData("path");
$("submitButton").addEventListener("click", (e) => {
Expand Down
Loading

0 comments on commit 2d1c4fc

Please sign in to comment.