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

@ -24,15 +24,16 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
if (!hash) if (!hash)
return false; return;
$("peers").focus(); $("peers").focus();
$("addPeersOk").addEvent("click", (e) => { $("addPeersOk").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const peers = $("peers").value.trim().split(/[\r\n]+/); const peers = $("peers").value.trim().split(/[\r\n]+/);
if (peers.length === 0) if (peers.length === 0)

View file

@ -10,7 +10,7 @@
<script> <script>
"use strict"; "use strict";
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
new Keyboard({ new Keyboard({
defaultEventType: "keydown", defaultEventType: "keydown",
events: { events: {
@ -26,8 +26,10 @@
}).activate(); }).activate();
$("trackersUrls").focus(); $("trackersUrls").focus();
$("addTrackersButton").addEvent("click", (e) => { $("addTrackersButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
new Request({ new Request({
url: "api/v2/torrents/addTrackers", url: "api/v2/torrents/addTrackers",

View file

@ -21,7 +21,7 @@
icon.style.fill = "var(--color-border-default)"; icon.style.fill = "var(--color-border-default)";
} }
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
new Request({ new Request({
url: "images/object-locked.svg", url: "images/object-locked.svg",
method: "get", method: "get",
@ -41,12 +41,12 @@
let prefDeleteContentFiles = prefCache.delete_torrent_content_files; let prefDeleteContentFiles = prefCache.delete_torrent_content_files;
$("deleteFromDiskCB").checked ||= prefDeleteContentFiles; $("deleteFromDiskCB").checked ||= prefDeleteContentFiles;
$("deleteFromDiskCB").addEvent("click", (e) => { $("deleteFromDiskCB").addEventListener("click", (e) => {
setRememberBtnEnabled($("deleteFromDiskCB").checked !== prefDeleteContentFiles); setRememberBtnEnabled($("deleteFromDiskCB").checked !== prefDeleteContentFiles);
}); });
// Set current "Delete files" choice as the default // Set current "Delete files" choice as the default
$("rememberBtn").addEvent("click", (e) => { $("rememberBtn").addEventListener("click", (e) => {
window.parent.qBittorrent.Cache.preferences.set({ window.parent.qBittorrent.Cache.preferences.set({
data: { data: {
"delete_torrent_content_files": $("deleteFromDiskCB").checked "delete_torrent_content_files": $("deleteFromDiskCB").checked
@ -60,13 +60,16 @@
const hashes = new URI().getData("hashes").split("|"); const hashes = new URI().getData("hashes").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEvent("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
window.parent.qBittorrent.Client.closeWindows(); window.parent.qBittorrent.Client.closeWindows();
}); });
$("confirmBtn").addEvent("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
parent.torrentsTable.deselectAll(); parent.torrentsTable.deselectAll();
new Event(e).stop();
const cmd = "api/v2/torrents/delete"; const cmd = "api/v2/torrents/delete";
const deleteFiles = $("deleteFromDiskCB").checked; const deleteFiles = $("deleteFromDiskCB").checked;
new Request({ new Request({

View file

@ -10,15 +10,18 @@
<script> <script>
"use strict"; "use strict";
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const paths = new URI().getData("paths").split("|"); const paths = new URI().getData("paths").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEvent("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
window.parent.qBittorrent.Client.closeWindows(); window.parent.qBittorrent.Client.closeWindows();
}); });
$("confirmBtn").addEvent("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
let completionCount = 0; let completionCount = 0;
paths.forEach((path) => { paths.forEach((path) => {
new Request({ new Request({

View file

@ -10,16 +10,19 @@
<script> <script>
"use strict"; "use strict";
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|"); const rules = new URI().getData("rules").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEvent("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
window.parent.MochaUI.closeWindow(window.parent.$("clearRulesPage")); window.parent.MochaUI.closeWindow(window.parent.$("clearRulesPage"));
}); });
$("confirmBtn").addEvent("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
let completionCount = 0; let completionCount = 0;
rules.forEach((rule) => { rules.forEach((rule) => {
window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), "previouslyMatchedEpisodes", [], () => { window.parent.qBittorrent.RssDownloader.modifyRuleState(decodeURIComponent(rule), "previouslyMatchedEpisodes", [], () => {

View file

@ -10,16 +10,19 @@
<script> <script>
"use strict"; "use strict";
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const rules = new URI().getData("rules").split("|"); const rules = new URI().getData("rules").split("|");
$("cancelBtn").focus(); $("cancelBtn").focus();
$("cancelBtn").addEvent("click", (e) => { $("cancelBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
window.parent.MochaUI.closeWindow(window.parent.$("removeRulePage")); window.parent.MochaUI.closeWindow(window.parent.$("removeRulePage"));
}); });
$("confirmBtn").addEvent("click", (e) => { $("confirmBtn").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
let completionCount = 0; let completionCount = 0;
rules.forEach((rule) => { rules.forEach((rule) => {
new Request({ new Request({

View file

@ -10,7 +10,7 @@
<script> <script>
"use strict"; "use strict";
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
new Keyboard({ new Keyboard({
defaultEventType: "keydown", defaultEventType: "keydown",
events: { events: {
@ -31,13 +31,15 @@
const currentUrl = new URI().getData("url"); const currentUrl = new URI().getData("url");
if (!currentUrl) if (!currentUrl)
return false; return;
$("trackerUrl").value = currentUrl; $("trackerUrl").value = currentUrl;
$("trackerUrl").focus(); $("trackerUrl").focus();
$("editTrackerButton").addEvent("click", (e) => { $("editTrackerButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
new Request({ new Request({
url: "api/v2/torrents/editTracker", url: "api/v2/torrents/editTracker",

View file

@ -30,7 +30,7 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action")); const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes")); const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes"));
const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData("categoryName")); const uriCategoryName = window.qBittorrent.Misc.safeTrim(new URI().getData("categoryName"));
@ -38,7 +38,7 @@
if (uriAction === "edit") { if (uriAction === "edit") {
if (!uriCategoryName) if (!uriCategoryName)
return false; return;
$("categoryName").disabled = true; $("categoryName").disabled = true;
$("categoryName").value = window.qBittorrent.Misc.escapeHtml(uriCategoryName); $("categoryName").value = window.qBittorrent.Misc.escapeHtml(uriCategoryName);
@ -53,8 +53,9 @@
$("categoryName").focus(); $("categoryName").focus();
} }
$("categoryNameButton").addEvent("click", (e) => { $("categoryNameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const savePath = $("savePath").value.trim(); const savePath = $("savePath").value.trim();
const categoryName = $("categoryName").value.trim(); const categoryName = $("categoryName").value.trim();

View file

@ -28,11 +28,13 @@
} }
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
$("feedURL").focus(); $("feedURL").focus();
const path = new URI().getData("path"); const path = new URI().getData("path");
$("submitButton").addEvent("click", (e) => { $("submitButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const feedURL = $("feedURL").value.trim(); const feedURL = $("feedURL").value.trim();
if (feedURL === "") { if (feedURL === "") {

View file

@ -29,11 +29,13 @@
} }
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
$("folderName").focus(); $("folderName").focus();
const path = new URI().getData("path"); const path = new URI().getData("path");
$("submitButton").addEvent("click", (e) => { $("submitButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const folderName = $("folderName").value.trim(); const folderName = $("folderName").value.trim();
if (folderName === "") { if (folderName === "") {

View file

@ -28,10 +28,12 @@
} }
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
$("name").focus(); $("name").focus();
$("submitButton").addEvent("click", (e) => { $("submitButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const name = $("name").value.trim(); const name = $("name").value.trim();
if (name === "") { if (name === "") {

View file

@ -29,7 +29,7 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action")); const uriAction = window.qBittorrent.Misc.safeTrim(new URI().getData("action"));
const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes")); const uriHashes = window.qBittorrent.Misc.safeTrim(new URI().getData("hashes"));
@ -38,8 +38,9 @@
$("tagName").focus(); $("tagName").focus();
$("tagNameButton").addEvent("click", (e) => { $("tagNameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const tagName = $("tagName").value.trim(); const tagName = $("tagName").value.trim();

View file

@ -29,19 +29,21 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const name = new URI().getData("name"); const name = new URI().getData("name");
// set text field to current value // set text field to current value
if (name) if (name)
$("rename").value = name; $("rename").value = name;
$("rename").focus(); $("rename").focus();
$("renameButton").addEvent("click", (e) => { $("renameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const name = $("rename").value.trim(); const name = $("rename").value.trim();
if ((name === null) || (name === "")) if ((name === null) || (name === ""))
return false; return;
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
if (hash) { if (hash) {

View file

@ -28,15 +28,17 @@
} }
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const oldPath = new URI().getData("oldPath"); const oldPath = new URI().getData("oldPath");
$("rename").value = oldPath; $("rename").value = oldPath;
$("rename").focus(); $("rename").focus();
$("rename").setSelectionRange(0, oldPath.length); $("rename").setSelectionRange(0, oldPath.length);
$("renameButton").addEvent("click", (e) => { $("renameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const newPath = $("rename").value.trim(); const newPath = $("rename").value.trim();
if (newPath === "") { if (newPath === "") {

View file

@ -30,7 +30,7 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const hash = new URI().getData("hash"); const hash = new URI().getData("hash");
const oldPath = new URI().getData("path"); const oldPath = new URI().getData("path");
const isFolder = ((new URI().getData("isFolder")) === "true"); const isFolder = ((new URI().getData("isFolder")) === "true");
@ -41,8 +41,10 @@
if (!isFolder) if (!isFolder)
$("rename").setSelectionRange(0, oldName.lastIndexOf(".")); $("rename").setSelectionRange(0, oldName.lastIndexOf("."));
$("renameButton").addEvent("click", (e) => { $("renameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const newName = $("rename").value.trim(); const newName = $("rename").value.trim();
if (newName === "") { if (newName === "") {

View file

@ -55,7 +55,7 @@
checkboxHeader = new Element("input"); checkboxHeader = new Element("input");
checkboxHeader.type = "checkbox"; checkboxHeader.type = "checkbox";
checkboxHeader.id = "rootMultiRename_cb"; checkboxHeader.id = "rootMultiRename_cb";
checkboxHeader.addEvent("click", (e) => { checkboxHeader.addEventListener("click", (e) => {
bulkRenameFilesTable.toggleGlobalCheckbox(); bulkRenameFilesTable.toggleGlobalCheckbox();
fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows(); fileRenamer.selectedFiles = bulkRenameFilesTable.getSelectedRows();
fileRenamer.update(); fileRenamer.update();
@ -143,7 +143,7 @@
}; };
// Setup Search Events that control renaming // Setup Search Events that control renaming
$("multiRenameSearch").addEvent("input", (e) => { $("multiRenameSearch").addEventListener("input", (e) => {
const sanitized = e.target.value.replace(/\n/g, ""); const sanitized = e.target.value.replace(/\n/g, "");
$("multiRenameSearch").value = sanitized; $("multiRenameSearch").value = sanitized;
@ -152,17 +152,17 @@
LocalPreferences.set("multirename_search", sanitized); LocalPreferences.set("multirename_search", sanitized);
fileRenamer.setSearch(sanitized); fileRenamer.setSearch(sanitized);
}); });
$("use_regex_search").addEvent("change", (e) => { $("use_regex_search").addEventListener("change", (e) => {
fileRenamer.useRegex = e.target.checked; fileRenamer.useRegex = e.target.checked;
LocalPreferences.set("multirename_useRegex", e.target.checked); LocalPreferences.set("multirename_useRegex", e.target.checked);
fileRenamer.update(); fileRenamer.update();
}); });
$("match_all_occurrences").addEvent("change", (e) => { $("match_all_occurrences").addEventListener("change", (e) => {
fileRenamer.matchAllOccurrences = e.target.checked; fileRenamer.matchAllOccurrences = e.target.checked;
LocalPreferences.set("multirename_matchAllOccurrences", e.target.checked); LocalPreferences.set("multirename_matchAllOccurrences", e.target.checked);
fileRenamer.update(); fileRenamer.update();
}); });
$("case_sensitive").addEvent("change", (e) => { $("case_sensitive").addEventListener("change", (e) => {
fileRenamer.caseSensitive = e.target.checked; fileRenamer.caseSensitive = e.target.checked;
LocalPreferences.set("multirename_caseSensitive", e.target.checked); LocalPreferences.set("multirename_caseSensitive", e.target.checked);
fileRenamer.update(); fileRenamer.update();
@ -190,7 +190,7 @@
}; };
// Setup Replace Events that control renaming // Setup Replace Events that control renaming
$("multiRenameReplace").addEvent("input", (e) => { $("multiRenameReplace").addEventListener("input", (e) => {
const sanitized = e.target.value.replace(/\n/g, ""); const sanitized = e.target.value.replace(/\n/g, "");
$("multiRenameReplace").value = sanitized; $("multiRenameReplace").value = sanitized;
@ -199,22 +199,22 @@
LocalPreferences.set("multirename_replace", sanitized); LocalPreferences.set("multirename_replace", sanitized);
fileRenamer.setReplacement(sanitized); fileRenamer.setReplacement(sanitized);
}); });
$("applies_to_option").addEvent("change", (e) => { $("applies_to_option").addEventListener("change", (e) => {
fileRenamer.appliesTo = e.target.value; fileRenamer.appliesTo = e.target.value;
LocalPreferences.set("multirename_appliesTo", e.target.value); LocalPreferences.set("multirename_appliesTo", e.target.value);
fileRenamer.update(); fileRenamer.update();
}); });
$("include_files").addEvent("change", (e) => { $("include_files").addEventListener("change", (e) => {
fileRenamer.includeFiles = e.target.checked; fileRenamer.includeFiles = e.target.checked;
LocalPreferences.set("multirename_includeFiles", e.target.checked); LocalPreferences.set("multirename_includeFiles", e.target.checked);
fileRenamer.update(); fileRenamer.update();
}); });
$("include_folders").addEvent("change", (e) => { $("include_folders").addEventListener("change", (e) => {
fileRenamer.includeFolders = e.target.checked; fileRenamer.includeFolders = e.target.checked;
LocalPreferences.set("multirename_includeFolders", e.target.checked); LocalPreferences.set("multirename_includeFolders", e.target.checked);
fileRenamer.update(); fileRenamer.update();
}); });
$("file_counter").addEvent("input", (e) => { $("file_counter").addEventListener("input", (e) => {
let value = e.target.valueAsNumber; let value = e.target.valueAsNumber;
if (!value) if (!value)
value = 0; value = 0;
@ -229,7 +229,7 @@
}); });
// Setup Rename Operation Events // Setup Rename Operation Events
$("renameButton").addEvent("click", (e) => { $("renameButton").addEventListener("click", (e) => {
// Disable Search Options // Disable Search Options
$("multiRenameSearch").disabled = true; $("multiRenameSearch").disabled = true;
$("use_regex_search").disabled = true; $("use_regex_search").disabled = true;
@ -281,7 +281,7 @@
if (err.xhr.status === 409) if (err.xhr.status === 409)
$("rename_error").textContent = `QBT_TR(Rename failed: file or folder already exists)QBT_TR[CONTEXT=PropertiesWidget] \`${row.renamed}\``; $("rename_error").textContent = `QBT_TR(Rename failed: file or folder already exists)QBT_TR[CONTEXT=PropertiesWidget] \`${row.renamed}\``;
}; };
$("renameOptions").addEvent("change", (e) => { $("renameOptions").addEventListener("change", (e) => {
const combobox = e.target; const combobox = e.target;
const replaceOperation = combobox.value; const replaceOperation = combobox.value;
if (replaceOperation === "Replace") if (replaceOperation === "Replace")
@ -293,7 +293,7 @@
LocalPreferences.set("multirename_replaceAll", fileRenamer.replaceAll); LocalPreferences.set("multirename_replaceAll", fileRenamer.replaceAll);
$("renameButton").value = replaceOperation; $("renameButton").value = replaceOperation;
}); });
$("closeButton").addEvent("click", () => { $("closeButton").addEventListener("click", () => {
window.parent.qBittorrent.Client.closeWindows(); window.parent.qBittorrent.Client.closeWindows();
event.preventDefault(); event.preventDefault();
}); });

View file

@ -28,15 +28,17 @@
} }
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const oldName = new URI().getData("rule"); const oldName = new URI().getData("rule");
$("rename").value = oldName; $("rename").value = oldName;
$("rename").focus(); $("rename").focus();
$("rename").setSelectionRange(0, oldName.length); $("rename").setSelectionRange(0, oldName.length);
$("renameButton").addEvent("click", (e) => { $("renameButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const newName = $("rename").value.trim(); const newName = $("rename").value.trim();
if (newName === "") { if (newName === "") {

View file

@ -164,7 +164,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("properties_height_rel", properties_height_rel); LocalPreferences.set("properties_height_rel", properties_height_rel);
}; };
window.addEvent("resize", () => { window.addEventListener("resize", () => {
// only save sizes if the columns are visible // only save sizes if the columns are visible
if (!$("mainColumn").hasClass("invisible")) if (!$("mainColumn").hasClass("invisible"))
saveColumnSizes.delay(200); // Resizing might takes some time. saveColumnSizes.delay(200); // Resizing might takes some time.
@ -1000,7 +1000,7 @@ window.addEventListener("DOMContentLoaded", () => {
} }
}; };
$("alternativeSpeedLimits").addEvent("click", () => { $("alternativeSpeedLimits").addEventListener("click", () => {
// Change icon immediately to give some feedback // Change icon immediately to give some feedback
updateAltSpeedIcon(!alternativeSpeedLimits); updateAltSpeedIcon(!alternativeSpeedLimits);
@ -1018,10 +1018,10 @@ window.addEventListener("DOMContentLoaded", () => {
}).send(); }).send();
}); });
$("DlInfos").addEvent("click", globalDownloadLimitFN); $("DlInfos").addEventListener("click", globalDownloadLimitFN);
$("UpInfos").addEvent("click", globalUploadLimitFN); $("UpInfos").addEventListener("click", globalUploadLimitFN);
$("showTopToolbarLink").addEvent("click", (e) => { $("showTopToolbarLink").addEventListener("click", (e) => {
showTopToolbar = !showTopToolbar; showTopToolbar = !showTopToolbar;
LocalPreferences.set("show_top_toolbar", showTopToolbar.toString()); LocalPreferences.set("show_top_toolbar", showTopToolbar.toString());
if (showTopToolbar) { if (showTopToolbar) {
@ -1035,7 +1035,7 @@ window.addEventListener("DOMContentLoaded", () => {
MochaUI.Desktop.setDesktopSize(); MochaUI.Desktop.setDesktopSize();
}); });
$("showStatusBarLink").addEvent("click", (e) => { $("showStatusBarLink").addEventListener("click", (e) => {
showStatusBar = !showStatusBar; showStatusBar = !showStatusBar;
LocalPreferences.set("show_status_bar", showStatusBar.toString()); LocalPreferences.set("show_status_bar", showStatusBar.toString());
if (showStatusBar) { if (showStatusBar) {
@ -1069,11 +1069,11 @@ window.addEventListener("DOMContentLoaded", () => {
navigator.registerProtocolHandler("magnet", templateUrl, navigator.registerProtocolHandler("magnet", templateUrl,
"qBittorrent WebUI magnet handler"); "qBittorrent WebUI magnet handler");
}; };
$("registerMagnetHandlerLink").addEvent("click", (e) => { $("registerMagnetHandlerLink").addEventListener("click", (e) => {
registerMagnetHandler(); registerMagnetHandler();
}); });
$("showFiltersSidebarLink").addEvent("click", (e) => { $("showFiltersSidebarLink").addEventListener("click", (e) => {
showFiltersSidebar = !showFiltersSidebar; showFiltersSidebar = !showFiltersSidebar;
LocalPreferences.set("show_filters_sidebar", showFiltersSidebar.toString()); LocalPreferences.set("show_filters_sidebar", showFiltersSidebar.toString());
if (showFiltersSidebar) { if (showFiltersSidebar) {
@ -1089,7 +1089,7 @@ window.addEventListener("DOMContentLoaded", () => {
MochaUI.Desktop.setDesktopSize(); MochaUI.Desktop.setDesktopSize();
}); });
$("speedInBrowserTitleBarLink").addEvent("click", (e) => { $("speedInBrowserTitleBarLink").addEventListener("click", (e) => {
speedInTitle = !speedInTitle; speedInTitle = !speedInTitle;
LocalPreferences.set("speed_in_browser_title_bar", speedInTitle.toString()); LocalPreferences.set("speed_in_browser_title_bar", speedInTitle.toString());
if (speedInTitle) if (speedInTitle)
@ -1099,19 +1099,19 @@ window.addEventListener("DOMContentLoaded", () => {
processServerState(); processServerState();
}); });
$("showSearchEngineLink").addEvent("click", (e) => { $("showSearchEngineLink").addEventListener("click", (e) => {
window.qBittorrent.Client.showSearchEngine(!window.qBittorrent.Client.isShowSearchEngine()); window.qBittorrent.Client.showSearchEngine(!window.qBittorrent.Client.isShowSearchEngine());
LocalPreferences.set("show_search_engine", window.qBittorrent.Client.isShowSearchEngine().toString()); LocalPreferences.set("show_search_engine", window.qBittorrent.Client.isShowSearchEngine().toString());
updateTabDisplay(); updateTabDisplay();
}); });
$("showRssReaderLink").addEvent("click", (e) => { $("showRssReaderLink").addEventListener("click", (e) => {
window.qBittorrent.Client.showRssReader(!window.qBittorrent.Client.isShowRssReader()); window.qBittorrent.Client.showRssReader(!window.qBittorrent.Client.isShowRssReader());
LocalPreferences.set("show_rss_reader", window.qBittorrent.Client.isShowRssReader().toString()); LocalPreferences.set("show_rss_reader", window.qBittorrent.Client.isShowRssReader().toString());
updateTabDisplay(); updateTabDisplay();
}); });
$("showLogViewerLink").addEvent("click", (e) => { $("showLogViewerLink").addEventListener("click", (e) => {
window.qBittorrent.Client.showLogViewer(!window.qBittorrent.Client.isShowLogViewer()); window.qBittorrent.Client.showLogViewer(!window.qBittorrent.Client.isShowLogViewer());
LocalPreferences.set("show_log_viewer", window.qBittorrent.Client.isShowLogViewer().toString()); LocalPreferences.set("show_log_viewer", window.qBittorrent.Client.isShowLogViewer().toString());
updateTabDisplay(); updateTabDisplay();
@ -1165,7 +1165,7 @@ window.addEventListener("DOMContentLoaded", () => {
$("mainWindowTabs").addClass("invisible"); $("mainWindowTabs").addClass("invisible");
}; };
$("StatisticsLink").addEvent("click", StatisticsLinkFN); $("StatisticsLink").addEventListener("click", StatisticsLinkFN);
// main window tabs // main window tabs
@ -1364,11 +1364,11 @@ window.addEventListener("DOMContentLoaded", () => {
tabsOnload: function() { tabsOnload: function() {
MochaUI.initializeTabs("panelTabs"); MochaUI.initializeTabs("panelTabs");
$("logMessageLink").addEvent("click", (e) => { $("logMessageLink").addEventListener("click", (e) => {
window.qBittorrent.Log.setCurrentTab("main"); window.qBittorrent.Log.setCurrentTab("main");
}); });
$("logPeerLink").addEvent("click", (e) => { $("logPeerLink").addEventListener("click", (e) => {
window.qBittorrent.Log.setCurrentTab("peer"); window.qBittorrent.Log.setCurrentTab("peer");
}); });
}, },
@ -1458,7 +1458,7 @@ window.addEventListener("DOMContentLoaded", () => {
} }
}; };
$("PropGeneralLink").addEvent("click", function(e) { $("PropGeneralLink").addEventListener("click", function(e) {
$$(".propertiesTabContent").addClass("invisible"); $$(".propertiesTabContent").addClass("invisible");
$("prop_general").removeClass("invisible"); $("prop_general").removeClass("invisible");
hideFilesFilter(); hideFilesFilter();
@ -1466,7 +1466,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("selected_tab", this.id); LocalPreferences.set("selected_tab", this.id);
}); });
$("PropTrackersLink").addEvent("click", function(e) { $("PropTrackersLink").addEventListener("click", function(e) {
$$(".propertiesTabContent").addClass("invisible"); $$(".propertiesTabContent").addClass("invisible");
$("prop_trackers").removeClass("invisible"); $("prop_trackers").removeClass("invisible");
hideFilesFilter(); hideFilesFilter();
@ -1474,7 +1474,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("selected_tab", this.id); LocalPreferences.set("selected_tab", this.id);
}); });
$("PropPeersLink").addEvent("click", function(e) { $("PropPeersLink").addEventListener("click", function(e) {
$$(".propertiesTabContent").addClass("invisible"); $$(".propertiesTabContent").addClass("invisible");
$("prop_peers").removeClass("invisible"); $("prop_peers").removeClass("invisible");
hideFilesFilter(); hideFilesFilter();
@ -1482,7 +1482,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("selected_tab", this.id); LocalPreferences.set("selected_tab", this.id);
}); });
$("PropWebSeedsLink").addEvent("click", function(e) { $("PropWebSeedsLink").addEventListener("click", function(e) {
$$(".propertiesTabContent").addClass("invisible"); $$(".propertiesTabContent").addClass("invisible");
$("prop_webseeds").removeClass("invisible"); $("prop_webseeds").removeClass("invisible");
hideFilesFilter(); hideFilesFilter();
@ -1490,7 +1490,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("selected_tab", this.id); LocalPreferences.set("selected_tab", this.id);
}); });
$("PropFilesLink").addEvent("click", function(e) { $("PropFilesLink").addEventListener("click", function(e) {
$$(".propertiesTabContent").addClass("invisible"); $$(".propertiesTabContent").addClass("invisible");
$("prop_files").removeClass("invisible"); $("prop_files").removeClass("invisible");
showFilesFilter(); showFilesFilter();
@ -1498,7 +1498,7 @@ window.addEventListener("DOMContentLoaded", () => {
LocalPreferences.set("selected_tab", this.id); LocalPreferences.set("selected_tab", this.id);
}); });
$("propertiesPanel_collapseToggle").addEvent("click", (e) => { $("propertiesPanel_collapseToggle").addEventListener("click", (e) => {
updatePropertiesPanel(); updatePropertiesPanel();
}); });
}, },
@ -1516,21 +1516,21 @@ window.addEventListener("DOMContentLoaded", () => {
// listen for changes to torrentsFilterInput // listen for changes to torrentsFilterInput
let torrentsFilterInputTimer = -1; let torrentsFilterInputTimer = -1;
$("torrentsFilterInput").addEvent("input", () => { $("torrentsFilterInput").addEventListener("input", () => {
clearTimeout(torrentsFilterInputTimer); clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = setTimeout(() => { torrentsFilterInputTimer = setTimeout(() => {
torrentsFilterInputTimer = -1; torrentsFilterInputTimer = -1;
torrentsTable.updateTable(); torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY); }, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
}); });
$("torrentsFilterRegexBox").addEvent("change", () => { $("torrentsFilterRegexBox").addEventListener("change", () => {
torrentsTable.updateTable(); torrentsTable.updateTable();
}); });
$("transfersTabLink").addEvent("click", showTransfersTab); $("transfersTabLink").addEventListener("click", showTransfersTab);
$("searchTabLink").addEvent("click", showSearchTab); $("searchTabLink").addEventListener("click", showSearchTab);
$("rssTabLink").addEvent("click", showRssTab); $("rssTabLink").addEventListener("click", showRssTab);
$("logTabLink").addEvent("click", showLogTab); $("logTabLink").addEventListener("click", showLogTab);
updateTabDisplay(); updateTabDisplay();
const registerDragAndDrop = () => { const registerDragAndDrop = () => {

View file

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

View file

@ -151,7 +151,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const mouseMoveFn = function(e) { const mouseMoveFn = function(e) {
const brect = e.target.getBoundingClientRect(); const brect = e.target.getBoundingClientRect();
const mouseXRelative = e.event.clientX - brect.left; const mouseXRelative = e.clientX - brect.left;
if (this.currentHeaderAction === "") { if (this.currentHeaderAction === "") {
if ((brect.width - mouseXRelative) < 5) { if ((brect.width - mouseXRelative) < 5) {
this.resizeTh = e.target; this.resizeTh = e.target;
@ -201,7 +201,7 @@ window.qBittorrent.DynamicTable ??= (() => {
}); });
} }
this.lastHoverTh = e.target; this.lastHoverTh = e.target;
this.lastClientX = e.event.clientX; this.lastClientX = e.clientX;
}.bind(this); }.bind(this);
const mouseOutFn = function(e) { const mouseOutFn = function(e) {
@ -280,9 +280,9 @@ window.qBittorrent.DynamicTable ??= (() => {
for (let i = 0; i < ths.length; ++i) { for (let i = 0; i < ths.length; ++i) {
const th = ths[i]; const th = ths[i];
th.addEvent("mousemove", mouseMoveFn); th.addEventListener("mousemove", mouseMoveFn);
th.addEvent("mouseout", mouseOutFn); th.addEventListener("mouseout", mouseOutFn);
th.addEvent("touchend", onTouch); th.addEventListener("touchend", onTouch);
th.makeResizable({ th.makeResizable({
modifiers: { modifiers: {
x: "", x: "",
@ -728,15 +728,17 @@ window.qBittorrent.DynamicTable ??= (() => {
tr["rowId"] = rowId; tr["rowId"] = rowId;
tr._this = this; tr._this = this;
tr.addEvent("contextmenu", function(e) { tr.addEventListener("contextmenu", function(e) {
if (!this._this.isRowSelected(this.rowId)) { if (!this._this.isRowSelected(this.rowId)) {
this._this.deselectAll(); this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
} }
return true; return true;
}); });
tr.addEvent("click", function(e) { tr.addEventListener("click", function(e) {
e.stop(); e.preventDefault();
e.stopPropagation();
if (e.control || e.meta) { if (e.control || e.meta) {
// CTRL/CMD ⌘ key was pressed // CTRL/CMD ⌘ key was pressed
if (this._this.isRowSelected(this.rowId)) if (this._this.isRowSelected(this.rowId))
@ -755,13 +757,13 @@ window.qBittorrent.DynamicTable ??= (() => {
} }
return false; return false;
}); });
tr.addEvent("touchstart", function(e) { tr.addEventListener("touchstart", function(e) {
if (!this._this.isRowSelected(this.rowId)) { if (!this._this.isRowSelected(this.rowId)) {
this._this.deselectAll(); this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
} }
}); });
tr.addEvent("keydown", function(event) { tr.addEventListener("keydown", function(event) {
switch (event.key) { switch (event.key) {
case "up": case "up":
this._this.selectPreviousRow(); this._this.selectPreviousRow();
@ -1523,8 +1525,10 @@ window.qBittorrent.DynamicTable ??= (() => {
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("dblclick", function(e) { tr.addEventListener("dblclick", function(e) {
e.stop(); e.preventDefault();
e.stopPropagation();
this._this.deselectAll(); this._this.deselectAll();
this._this.selectRow(this.rowId); this._this.selectRow(this.rowId);
const row = this._this.rows.get(this.rowId); const row = this._this.rows.get(this.rowId);
@ -2030,7 +2034,7 @@ window.qBittorrent.DynamicTable ??= (() => {
checkbox.id = "cbRename" + id; checkbox.id = "cbRename" + id;
checkbox.setAttribute("data-id", id); checkbox.setAttribute("data-id", id);
checkbox.className = "RenamingCB"; checkbox.className = "RenamingCB";
checkbox.addEvent("click", (e) => { checkbox.addEventListener("click", (e) => {
const node = that.getNode(id); const node = that.getNode(id);
node.checked = e.target.checked ? 0 : 1; node.checked = e.target.checked ? 0 : 1;
node.full_data.checked = node.checked; node.full_data.checked = node.checked;
@ -2248,7 +2252,7 @@ window.qBittorrent.DynamicTable ??= (() => {
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("keydown", function(event) { tr.addEventListener("keydown", function(event) {
switch (event.key) { switch (event.key) {
case "left": case "left":
qBittorrent.PropFiles.collapseFolder(this._this.getSelectedRowId()); qBittorrent.PropFiles.collapseFolder(this._this.getSelectedRowId());
@ -2578,7 +2582,7 @@ window.qBittorrent.DynamicTable ??= (() => {
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("keydown", function(event) { tr.addEventListener("keydown", function(event) {
switch (event.key) { switch (event.key) {
case "left": case "left":
qBittorrent.PropFiles.collapseFolder(this._this.getSelectedRowId()); qBittorrent.PropFiles.collapseFolder(this._this.getSelectedRowId());
@ -2630,7 +2634,7 @@ window.qBittorrent.DynamicTable ??= (() => {
window.qBittorrent.Rss.showRssFeed(path); window.qBittorrent.Rss.showRssFeed(path);
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("dblclick", function(e) { tr.addEventListener("dblclick", function(e) {
if (this.rowId !== 0) { if (this.rowId !== 0) {
window.qBittorrent.Rss.moveItem(this._this.rows.get(this.rowId).full_data.dataPath); window.qBittorrent.Rss.moveItem(this._this.rows.get(this.rowId).full_data.dataPath);
return true; return true;
@ -2738,7 +2742,7 @@ window.qBittorrent.DynamicTable ??= (() => {
$(this.dynamicTableFixedHeaderDivId).getElements("table")[0].style.left = -$(this.dynamicTableDivId).scrollLeft + "px"; $(this.dynamicTableFixedHeaderDivId).getElements("table")[0].style.left = -$(this.dynamicTableDivId).scrollLeft + "px";
}.bind(this); }.bind(this);
$(this.dynamicTableDivId).addEvent("scroll", scrollFn); $(this.dynamicTableDivId).addEventListener("scroll", scrollFn);
} }
}); });
@ -2771,7 +2775,7 @@ window.qBittorrent.DynamicTable ??= (() => {
window.qBittorrent.Rss.showDetails(feedUid, articleId); window.qBittorrent.Rss.showDetails(feedUid, articleId);
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("dblclick", function(e) { tr.addEventListener("dblclick", function(e) {
showDownloadPage([this._this.rows.get(this.rowId).full_data.torrentURL]); showDownloadPage([this._this.rows.get(this.rowId).full_data.torrentURL]);
return true; return true;
}); });
@ -2833,7 +2837,7 @@ window.qBittorrent.DynamicTable ??= (() => {
$(this.dynamicTableFixedHeaderDivId).getElements("table")[0].style.left = -$(this.dynamicTableDivId).scrollLeft + "px"; $(this.dynamicTableFixedHeaderDivId).getElements("table")[0].style.left = -$(this.dynamicTableDivId).scrollLeft + "px";
}.bind(this); }.bind(this);
$(this.dynamicTableDivId).addEvent("scroll", scrollFn); $(this.dynamicTableDivId).addEventListener("scroll", scrollFn);
} }
}); });
@ -2850,7 +2854,7 @@ window.qBittorrent.DynamicTable ??= (() => {
checkbox.id = "cbRssDlRule" + row.rowId; checkbox.id = "cbRssDlRule" + row.rowId;
checkbox.checked = row.full_data.checked; checkbox.checked = row.full_data.checked;
checkbox.addEvent("click", function(e) { checkbox.addEventListener("click", function(e) {
window.qBittorrent.RssDownloader.rssDownloaderRulesTable.updateRowData({ window.qBittorrent.RssDownloader.rssDownloaderRulesTable.updateRowData({
rowId: row.rowId, rowId: row.rowId,
checked: this.checked checked: this.checked
@ -2872,7 +2876,7 @@ window.qBittorrent.DynamicTable ??= (() => {
return this.rows.getValues(); return this.rows.getValues();
}, },
setupTr: function(tr) { setupTr: function(tr) {
tr.addEvent("dblclick", function(e) { tr.addEventListener("dblclick", function(e) {
window.qBittorrent.RssDownloader.renameRule(this._this.rows.get(this.rowId).full_data.name); window.qBittorrent.RssDownloader.renameRule(this._this.rows.get(this.rowId).full_data.name);
return true; return true;
}); });
@ -2943,7 +2947,7 @@ window.qBittorrent.DynamicTable ??= (() => {
checkbox.id = "cbRssDlFeed" + row.rowId; checkbox.id = "cbRssDlFeed" + row.rowId;
checkbox.checked = row.full_data.checked; checkbox.checked = row.full_data.checked;
checkbox.addEvent("click", function(e) { checkbox.addEventListener("click", function(e) {
window.qBittorrent.RssDownloader.rssDownloaderFeedSelectionTable.updateRowData({ window.qBittorrent.RssDownloader.rssDownloaderFeedSelectionTable.updateRowData({
rowId: row.rowId, rowId: row.rowId,
checked: this.checked checked: this.checked

View file

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

View file

@ -136,7 +136,7 @@ window.qBittorrent.PropFiles ??= (() => {
checkbox.setAttribute("data-id", id); checkbox.setAttribute("data-id", id);
checkbox.setAttribute("data-file-id", fileId); checkbox.setAttribute("data-file-id", fileId);
checkbox.className = "DownloadedCB"; checkbox.className = "DownloadedCB";
checkbox.addEvent("click", fileCheckboxClicked); checkbox.addEventListener("click", fileCheckboxClicked);
updateCheckbox(checkbox, checked); updateCheckbox(checkbox, checked);
return checkbox; return checkbox;
@ -180,7 +180,7 @@ window.qBittorrent.PropFiles ??= (() => {
select.setAttribute("data-id", id); select.setAttribute("data-id", id);
select.setAttribute("data-file-id", fileId); select.setAttribute("data-file-id", fileId);
select.addClass("combo_priority"); select.addClass("combo_priority");
select.addEvent("change", fileComboboxChanged); select.addEventListener("change", fileComboboxChanged);
createPriorityOptionElement(FilePriority.Ignored, (FilePriority.Ignored === selectedPriority), "QBT_TR(Do not download)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select); createPriorityOptionElement(FilePriority.Ignored, (FilePriority.Ignored === selectedPriority), "QBT_TR(Do not download)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select);
createPriorityOptionElement(FilePriority.Normal, (FilePriority.Normal === selectedPriority), "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select); createPriorityOptionElement(FilePriority.Normal, (FilePriority.Normal === selectedPriority), "QBT_TR(Normal)QBT_TR[CONTEXT=PropListDelegate]").injectInside(select);
@ -625,7 +625,7 @@ window.qBittorrent.PropFiles ??= (() => {
const checkbox = new Element("input"); const checkbox = new Element("input");
checkbox.type = "checkbox"; checkbox.type = "checkbox";
checkbox.id = "tristate_cb"; checkbox.id = "tristate_cb";
checkbox.addEvent("click", switchCheckboxState); checkbox.addEventListener("click", switchCheckboxState);
const checkboxTH = tableHeaders[0]; const checkboxTH = tableHeaders[0];
checkbox.injectInside(checkboxTH); checkbox.injectInside(checkboxTH);
@ -637,7 +637,7 @@ window.qBittorrent.PropFiles ??= (() => {
// listen for changes to torrentFilesFilterInput // listen for changes to torrentFilesFilterInput
let torrentFilesFilterInputTimer = -1; let torrentFilesFilterInputTimer = -1;
$("torrentFilesFilterInput").addEvent("input", () => { $("torrentFilesFilterInput").addEventListener("input", () => {
clearTimeout(torrentFilesFilterInputTimer); clearTimeout(torrentFilesFilterInputTimer);
const value = $("torrentFilesFilterInput").value; const value = $("torrentFilesFilterInput").value;

View file

@ -107,7 +107,7 @@ window.qBittorrent.Search ??= (() => {
// listen for changes to searchInNameFilter // listen for changes to searchInNameFilter
let searchInNameFilterTimer = -1; let searchInNameFilterTimer = -1;
$("searchInNameFilter").addEvent("input", () => { $("searchInNameFilter").addEventListener("input", () => {
clearTimeout(searchInNameFilterTimer); clearTimeout(searchInNameFilterTimer);
searchInNameFilterTimer = setTimeout(() => { searchInNameFilterTimer = setTimeout(() => {
searchInNameFilterTimer = -1; searchInNameFilterTimer = -1;
@ -123,7 +123,8 @@ window.qBittorrent.Search ??= (() => {
events: { events: {
"Enter": function(e) { "Enter": function(e) {
// accept enter key as a click // accept enter key as a click
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const elem = e.event.srcElement; const elem = e.event.srcElement;
if (elem.className.contains("searchInputField")) { if (elem.className.contains("searchInputField")) {
@ -159,6 +160,7 @@ window.qBittorrent.Search ??= (() => {
const tabElem = new Element("a", { const tabElem = new Element("a", {
text: pattern, text: pattern,
}); });
const closeTabElem = new Element("img", { const closeTabElem = new Element("img", {
alt: "QBT_TR(Close tab)QBT_TR[CONTEXT=SearchWidget]", alt: "QBT_TR(Close tab)QBT_TR[CONTEXT=SearchWidget]",
title: "QBT_TR(Close tab)QBT_TR[CONTEXT=SearchWidget]", title: "QBT_TR(Close tab)QBT_TR[CONTEXT=SearchWidget]",
@ -166,15 +168,22 @@ window.qBittorrent.Search ??= (() => {
width: "8", width: "8",
height: "8", height: "8",
style: "padding-right: 7px; margin-bottom: -1px; margin-left: -5px", style: "padding-right: 7px; margin-bottom: -1px; margin-left: -5px",
onclick: "qBittorrent.Search.closeSearchTab(this)", onclick: "qBittorrent.Search.closeSearchTab(event, this);",
}); });
closeTabElem.inject(tabElem, "top"); closeTabElem.inject(tabElem, "top");
tabElem.appendChild(getStatusIconElement("QBT_TR(Searching...)QBT_TR[CONTEXT=SearchJobWidget]", "images/queued.svg")); tabElem.appendChild(getStatusIconElement("QBT_TR(Searching...)QBT_TR[CONTEXT=SearchJobWidget]", "images/queued.svg"));
$("searchTabs").appendChild(new Element("li", {
const liElement = new Element("li", {
id: newTabId, id: newTabId,
class: "selected", class: "selected",
html: tabElem.outerHTML, html: tabElem.outerHTML,
})); });
liElement.addEventListener("click", (e) => {
setActiveTab(liElement);
$("startSearchButton").textContent = "QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]";
});
$("searchTabs").appendChild(liElement);
// unhide the results elements // unhide the results elements
if (numSearchTabs() >= 1) { if (numSearchTabs() >= 1) {
@ -184,15 +193,8 @@ window.qBittorrent.Search ??= (() => {
$("searchTabsToolbar").style.display = "block"; $("searchTabsToolbar").style.display = "block";
} }
// reinitialize tabs
$("searchTabs").getElements("li").removeEvents("click");
$("searchTabs").getElements("li").addEvent("click", function(e) {
$("startSearchButton").textContent = "QBT_TR(Search)QBT_TR[CONTEXT=SearchEngineWidget]";
setActiveTab(this);
});
// select new tab // select new tab
setActiveTab($(newTabId)); setActiveTab(liElement);
searchResultsTable.clear(); searchResultsTable.clear();
resetFilters(); resetFilters();
@ -213,11 +215,13 @@ window.qBittorrent.Search ??= (() => {
updateSearchResultsData(searchId); updateSearchResultsData(searchId);
}; };
const closeSearchTab = function(el) { const closeSearchTab = function(e, el) {
e.stopPropagation();
const tab = el.parentElement.parentElement; const tab = el.parentElement.parentElement;
const searchId = getSearchIdFromTab(tab); const searchId = getSearchIdFromTab(tab);
const isTabSelected = tab.hasClass("selected"); const isTabSelected = tab.hasClass("selected");
const newTabToSelect = isTabSelected ? tab.nextSibling || tab.previousSibling : null; const newTabToSelect = isTabSelected ? (tab.nextSibling || tab.previousSibling) : null;
const currentSearchId = getSelectedSearchId(); const currentSearchId = getSelectedSearchId();
const state = searchState.get(currentSearchId); const state = searchState.get(currentSearchId);
@ -388,7 +392,7 @@ window.qBittorrent.Search ??= (() => {
category: category, category: category,
plugins: plugins plugins: plugins
}, },
onSuccess: function(response) { onSuccess: (response) => {
$("startSearchButton").textContent = "QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]"; $("startSearchButton").textContent = "QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]";
const searchId = response.id; const searchId = response.id;
createSearchTab(searchId, pattern); createSearchTab(searchId, pattern);

View file

@ -29,7 +29,7 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const path = new URI().getData("path"); const path = new URI().getData("path");
// set text field to current value // set text field to current value
@ -37,13 +37,15 @@
$("setLocation").value = decodeURIComponent(path); $("setLocation").value = decodeURIComponent(path);
$("setLocation").focus(); $("setLocation").focus();
$("setLocationButton").addEvent("click", (e) => { $("setLocationButton").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
// check field // check field
const location = $("setLocation").value.trim(); const location = $("setLocation").value.trim();
if ((location === null) || (location === "")) { if ((location === null) || (location === "")) {
$("error_div").textContent = "QBT_TR(Save path is empty)QBT_TR[CONTEXT=TorrentsController]"; $("error_div").textContent = "QBT_TR(Save path is empty)QBT_TR[CONTEXT=TorrentsController]";
return false; return;
} }
const hashesList = new URI().getData("hashes"); const hashesList = new URI().getData("hashes");

View file

@ -32,7 +32,7 @@
} }
}).activate(); }).activate();
window.addEvent("domready", () => { window.addEventListener("DOMContentLoaded", () => {
const hashesList = new URI().getData("hashes").split("|"); const hashesList = new URI().getData("hashes").split("|");
const origValues = new URI().getData("orig").split("|"); const origValues = new URI().getData("orig").split("|");
@ -76,11 +76,12 @@
shareLimitChanged(); shareLimitChanged();
$("default").focus(); $("default").focus();
$("save").addEvent("click", (e) => { $("save").addEventListener("click", (e) => {
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
if (!isFormValid()) if (!isFormValid())
return false; return;
const shareLimit = getSelectedRadioValue("shareLimit"); const shareLimit = getSelectedRadioValue("shareLimit");
let ratioLimitValue = 0.00; let ratioLimitValue = 0.00;
@ -99,7 +100,7 @@
inactiveSeedingTimeLimitValue = $("setInactiveMinutes").checked ? $("inactiveMinutes").value : -1; inactiveSeedingTimeLimitValue = $("setInactiveMinutes").checked ? $("inactiveMinutes").value : -1;
} }
else { else {
return false; return;
} }
new Request({ new Request({

View file

@ -16,32 +16,32 @@
(function() { (function() {
MochaUI.initializeTabs("aboutTabs"); MochaUI.initializeTabs("aboutTabs");
$("aboutAboutLink").addEvent("click", () => { $("aboutAboutLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutAboutContent").removeClass("invisible"); $("aboutAboutContent").removeClass("invisible");
}); });
$("aboutAuthorLink").addEvent("click", () => { $("aboutAuthorLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutAuthorContent").removeClass("invisible"); $("aboutAuthorContent").removeClass("invisible");
}); });
$("aboutSpecialThanksLink").addEvent("click", () => { $("aboutSpecialThanksLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutSpecialThanksContent").removeClass("invisible"); $("aboutSpecialThanksContent").removeClass("invisible");
}); });
$("aboutTranslatorsLink").addEvent("click", () => { $("aboutTranslatorsLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutTranslatorsContent").removeClass("invisible"); $("aboutTranslatorsContent").removeClass("invisible");
}); });
$("aboutLicenseLink").addEvent("click", () => { $("aboutLicenseLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutLicenseContent").removeClass("invisible"); $("aboutLicenseContent").removeClass("invisible");
}); });
$("aboutSoftwareUsedLink").addEvent("click", () => { $("aboutSoftwareUsedLink").addEventListener("click", () => {
$$(".aboutTabContent").addClass("invisible"); $$(".aboutTabContent").addClass("invisible");
$("aboutSoftwareUsedContent").removeClass("invisible"); $("aboutSoftwareUsedContent").removeClass("invisible");
}); });

View file

@ -43,7 +43,8 @@
events: { events: {
"Enter": function(e) { "Enter": function(e) {
// accept enter key as a click // accept enter key as a click
new Event(e).stop(); e.preventDefault();
e.stopPropagation();
const elem = e.event.srcElement; const elem = e.event.srcElement;
if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk")) if ((elem.id === "newPluginPath") || (elem.id === "newPluginOk"))

View file

@ -2975,7 +2975,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
if ((buildInfo.platform !== "macos") && (buildInfo.platform !== "windows")) if ((buildInfo.platform !== "macos") && (buildInfo.platform !== "windows"))
$("rowMarkOfTheWeb").style.display = "none"; $("rowMarkOfTheWeb").style.display = "none";
$("networkInterface").addEvent("change", function() { $("networkInterface").addEventListener("change", function() {
updateInterfaceAddresses($(this).value, ""); updateInterfaceAddresses($(this).value, "");
}); });

View file

@ -20,35 +20,35 @@
// Tabs // Tabs
MochaUI.initializeTabs("preferencesTabs"); MochaUI.initializeTabs("preferencesTabs");
$("PrefBehaviorLink").addEvent("click", (e) => { $("PrefBehaviorLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("BehaviorTab").removeClass("invisible"); $("BehaviorTab").removeClass("invisible");
}); });
$("PrefDownloadsLink").addEvent("click", (e) => { $("PrefDownloadsLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("DownloadsTab").removeClass("invisible"); $("DownloadsTab").removeClass("invisible");
}); });
$("PrefConnectionLink").addEvent("click", (e) => { $("PrefConnectionLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("ConnectionTab").removeClass("invisible"); $("ConnectionTab").removeClass("invisible");
}); });
$("PrefSpeedLink").addEvent("click", (e) => { $("PrefSpeedLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("SpeedTab").removeClass("invisible"); $("SpeedTab").removeClass("invisible");
}); });
$("PrefBittorrentLink").addEvent("click", (e) => { $("PrefBittorrentLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("BittorrentTab").removeClass("invisible"); $("BittorrentTab").removeClass("invisible");
}); });
$("PrefRSSLink").addEvent("click", (e) => { $("PrefRSSLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("RSSTab").removeClass("invisible"); $("RSSTab").removeClass("invisible");
}); });
$("PrefWebUILink").addEvent("click", (e) => { $("PrefWebUILink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("WebUITab").removeClass("invisible"); $("WebUITab").removeClass("invisible");
}); });
$("PrefAdvancedLink").addEvent("click", (e) => { $("PrefAdvancedLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible"); $$(".PrefTab").addClass("invisible");
$("AdvancedTab").removeClass("invisible"); $("AdvancedTab").removeClass("invisible");
}); });

View file

@ -473,7 +473,7 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also
flatten(response); flatten(response);
} }
}).send(); }).send();
$("savetoDifferentDir").addEvent("click", () => { $("savetoDifferentDir").addEventListener("click", () => {
$("saveToText").disabled = !$("savetoDifferentDir").checked; $("saveToText").disabled = !$("savetoDifferentDir").checked;
}); });
updateRulesList(); updateRulesList();