修复如果 tagger.js 处于活动状态则无法粘贴多个标签的问题

This commit is contained in:
WindyMadman 2023-11-13 02:32:24 +08:00
parent beb3b22649
commit 0e29fd0449

View File

@ -16,6 +16,7 @@ Edit.initializeAll = function () {
$(document).on("click.delete-archive", "#delete-archive", Edit.deleteArchive);
$(document).on("click.tagger", ".tagger", Edit.focusTagInput);
$(document).on("click.goback", "#goback", () => { window.location.href = "/"; });
$(document).on("paste.tagger", ".tagger-new", Edit.handlePaste);
Edit.updateOneShotArg();
@ -52,6 +53,22 @@ Edit.initializeAll = function () {
});
};
Edit.handlePaste = function (event) {
// Stop data actually being pasted into div
event.stopPropagation();
event.preventDefault();
// Get pasted data via clipboard API
const pastedData = event.originalEvent.clipboardData.getData("Text");
if (pastedData !== "") {
pastedData.split(/,\s?/).forEach((tag) => {
// Remove trailing/leading spaces from tag before adding it
Edit.tagInput.add_tag(tag.trim());
});
}
};
Edit.hideTags = function () {
$("#tag-spinner").css("display", "block");
$("#tagText").css("opacity", "0.5");