mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 12:59:56 -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));
|
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 syncMainDataTimeoutID = -1;
|
||||||
let syncRequestInProgress = false;
|
let syncRequestInProgress = false;
|
||||||
const syncMainData = function() {
|
const syncMainData = function() {
|
||||||
|
@ -824,7 +794,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
updateTrackers = true;
|
updateTrackers = true;
|
||||||
}
|
}
|
||||||
if (response["torrents"]) {
|
if (response["torrents"]) {
|
||||||
let updateTorrentList = false;
|
|
||||||
for (const key in response["torrents"]) {
|
for (const key in response["torrents"]) {
|
||||||
if (!Object.hasOwn(response["torrents"], key))
|
if (!Object.hasOwn(response["torrents"], key))
|
||||||
continue;
|
continue;
|
||||||
|
@ -838,12 +807,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
update_categories = true;
|
update_categories = true;
|
||||||
if (addTorrentToTagList(response["torrents"][key]))
|
if (addTorrentToTagList(response["torrents"][key]))
|
||||||
updateTags = true;
|
updateTags = true;
|
||||||
if (response["torrents"][key]["name"])
|
|
||||||
updateTorrentList = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateTorrentList)
|
|
||||||
setupCopyEventHandler();
|
|
||||||
}
|
}
|
||||||
if (response["torrents_removed"]) {
|
if (response["torrents_removed"]) {
|
||||||
response["torrents_removed"].each((hash) => {
|
response["torrents_removed"].each((hash) => {
|
||||||
|
@ -1663,6 +1627,27 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).activate();
|
}).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", () => {
|
window.addEventListener("load", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue