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();
window.addEvent("domready", () => {
window.addEventListener("DOMContentLoaded", () => {
const hash = new URI().getData("hash");
if (!hash)
return false;
return;
$("peers").focus();
$("addPeersOk").addEvent("click", (e) => {
new Event(e).stop();
$("addPeersOk").addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const peers = $("peers").value.trim().split(/[\r\n]+/);
if (peers.length === 0)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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)

View File

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

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();
});
});
};

View File

@ -136,7 +136,7 @@ window.qBittorrent.PropFiles ??= (() => {
checkbox.setAttribute("data-id", id);
checkbox.setAttribute("data-file-id", fileId);
checkbox.className = "DownloadedCB";
checkbox.addEvent("click", fileCheckboxClicked);
checkbox.addEventListener("click", fileCheckboxClicked);
updateCheckbox(checkbox, checked);
return checkbox;
@ -180,7 +180,7 @@ window.qBittorrent.PropFiles ??= (() => {
select.setAttribute("data-id", id);
select.setAttribute("data-file-id", fileId);
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.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");
checkbox.type = "checkbox";
checkbox.id = "tristate_cb";
checkbox.addEvent("click", switchCheckboxState);
checkbox.addEventListener("click", switchCheckboxState);
const checkboxTH = tableHeaders[0];
checkbox.injectInside(checkboxTH);
@ -637,7 +637,7 @@ window.qBittorrent.PropFiles ??= (() => {
// listen for changes to torrentFilesFilterInput
let torrentFilesFilterInputTimer = -1;
$("torrentFilesFilterInput").addEvent("input", () => {
$("torrentFilesFilterInput").addEventListener("input", () => {
clearTimeout(torrentFilesFilterInputTimer);
const value = $("torrentFilesFilterInput").value;

View File

@ -107,7 +107,7 @@ window.qBittorrent.Search ??= (() => {
// listen for changes to searchInNameFilter
let searchInNameFilterTimer = -1;
$("searchInNameFilter").addEvent("input", () => {
$("searchInNameFilter").addEventListener("input", () => {
clearTimeout(searchInNameFilterTimer);
searchInNameFilterTimer = setTimeout(() => {
searchInNameFilterTimer = -1;
@ -123,7 +123,8 @@ window.qBittorrent.Search ??= (() => {
events: {
"Enter": function(e) {
// accept enter key as a click
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const elem = e.event.srcElement;
if (elem.className.contains("searchInputField")) {
@ -159,6 +160,7 @@ window.qBittorrent.Search ??= (() => {
const tabElem = new Element("a", {
text: pattern,
});
const closeTabElem = new Element("img", {
alt: "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",
height: "8",
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");
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,
class: "selected",
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
if (numSearchTabs() >= 1) {
@ -184,15 +193,8 @@ window.qBittorrent.Search ??= (() => {
$("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
setActiveTab($(newTabId));
setActiveTab(liElement);
searchResultsTable.clear();
resetFilters();
@ -213,11 +215,13 @@ window.qBittorrent.Search ??= (() => {
updateSearchResultsData(searchId);
};
const closeSearchTab = function(el) {
const closeSearchTab = function(e, el) {
e.stopPropagation();
const tab = el.parentElement.parentElement;
const searchId = getSearchIdFromTab(tab);
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 state = searchState.get(currentSearchId);
@ -388,7 +392,7 @@ window.qBittorrent.Search ??= (() => {
category: category,
plugins: plugins
},
onSuccess: function(response) {
onSuccess: (response) => {
$("startSearchButton").textContent = "QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]";
const searchId = response.id;
createSearchTab(searchId, pattern);

View File

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

View File

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

View File

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

View File

@ -43,7 +43,8 @@
events: {
"Enter": function(e) {
// accept enter key as a click
new Event(e).stop();
e.preventDefault();
e.stopPropagation();
const elem = e.event.srcElement;
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"))
$("rowMarkOfTheWeb").style.display = "none";
$("networkInterface").addEvent("change", function() {
$("networkInterface").addEventListener("change", function() {
updateInterfaceAddresses($(this).value, "");
});

View File

@ -20,35 +20,35 @@
// Tabs
MochaUI.initializeTabs("preferencesTabs");
$("PrefBehaviorLink").addEvent("click", (e) => {
$("PrefBehaviorLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("BehaviorTab").removeClass("invisible");
});
$("PrefDownloadsLink").addEvent("click", (e) => {
$("PrefDownloadsLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("DownloadsTab").removeClass("invisible");
});
$("PrefConnectionLink").addEvent("click", (e) => {
$("PrefConnectionLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("ConnectionTab").removeClass("invisible");
});
$("PrefSpeedLink").addEvent("click", (e) => {
$("PrefSpeedLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("SpeedTab").removeClass("invisible");
});
$("PrefBittorrentLink").addEvent("click", (e) => {
$("PrefBittorrentLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("BittorrentTab").removeClass("invisible");
});
$("PrefRSSLink").addEvent("click", (e) => {
$("PrefRSSLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("RSSTab").removeClass("invisible");
});
$("PrefWebUILink").addEvent("click", (e) => {
$("PrefWebUILink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("invisible");
$("WebUITab").removeClass("invisible");
});
$("PrefAdvancedLink").addEvent("click", (e) => {
$("PrefAdvancedLink").addEventListener("click", (e) => {
$$(".PrefTab").addClass("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);
}
}).send();
$("savetoDifferentDir").addEvent("click", () => {
$("savetoDifferentDir").addEventListener("click", () => {
$("saveToText").disabled = !$("savetoDifferentDir").checked;
});
updateRulesList();