mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
WebUI: Setup copy events only once
It is enough to set them up just once during initial load. Number of elements with copyToClipboard class is fixed - they are context menu items. PR #21558.
This commit is contained in:
parent
0704049026
commit
cbcb46bcfb
1 changed files with 21 additions and 36 deletions
|
@ -672,36 +672,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
tracker.classList.toggle("selectedFilter", (Number(tracker.id) === selectedTracker));
|
||||
};
|
||||
|
||||
const setupCopyEventHandler = (function() {
|
||||
let clipboardEvent;
|
||||
|
||||
return () => {
|
||||
if (clipboardEvent)
|
||||
clipboardEvent.destroy();
|
||||
|
||||
clipboardEvent = new ClipboardJS(".copyToClipboard", {
|
||||
text: function(trigger) {
|
||||
switch (trigger.id) {
|
||||
case "copyName":
|
||||
return copyNameFN();
|
||||
case "copyInfohash1":
|
||||
return copyInfohashFN(1);
|
||||
case "copyInfohash2":
|
||||
return copyInfohashFN(2);
|
||||
case "copyMagnetLink":
|
||||
return copyMagnetLinkFN();
|
||||
case "copyID":
|
||||
return copyIdFN();
|
||||
case "copyComment":
|
||||
return copyCommentFN();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
})();
|
||||
|
||||
let syncMainDataTimeoutID = -1;
|
||||
let syncRequestInProgress = false;
|
||||
const syncMainData = function() {
|
||||
|
@ -824,7 +794,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
updateTrackers = true;
|
||||
}
|
||||
if (response["torrents"]) {
|
||||
let updateTorrentList = false;
|
||||
for (const key in response["torrents"]) {
|
||||
if (!Object.hasOwn(response["torrents"], key))
|
||||
continue;
|
||||
|
@ -838,12 +807,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
update_categories = true;
|
||||
if (addTorrentToTagList(response["torrents"][key]))
|
||||
updateTags = true;
|
||||
if (response["torrents"][key]["name"])
|
||||
updateTorrentList = true;
|
||||
}
|
||||
|
||||
if (updateTorrentList)
|
||||
setupCopyEventHandler();
|
||||
}
|
||||
if (response["torrents_removed"]) {
|
||||
response["torrents_removed"].each((hash) => {
|
||||
|
@ -1663,6 +1627,27 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
}
|
||||
}
|
||||
}).activate();
|
||||
|
||||
new ClipboardJS(".copyToClipboard", {
|
||||
text: function(trigger) {
|
||||
switch (trigger.id) {
|
||||
case "copyName":
|
||||
return copyNameFN();
|
||||
case "copyInfohash1":
|
||||
return copyInfohashFN(1);
|
||||
case "copyInfohash2":
|
||||
return copyInfohashFN(2);
|
||||
case "copyMagnetLink":
|
||||
return copyMagnetLinkFN();
|
||||
case "copyID":
|
||||
return copyIdFN();
|
||||
case "copyComment":
|
||||
return copyCommentFN();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue