33 lines
856 B
JavaScript
Raw Normal View History

2023-05-03 10:23:20 +02:00
import toastService from "./toast.js";
function copyImageReferenceToClipboard($imageWrapper) {
try {
$imageWrapper.attr('contenteditable', 'true');
selectImage($imageWrapper.get(0));
const success = document.execCommand('copy');
if (success) {
2024-10-20 02:06:08 +03:00
toastService.showMessage(t("image.copied-to-clipboard"));
2023-05-03 10:23:20 +02:00
} else {
2024-10-20 02:06:08 +03:00
toastService.showAndLogError(t("image.cannot-copy"));
2023-05-03 10:23:20 +02:00
}
}
finally {
window.getSelection().removeAllRanges();
$imageWrapper.removeAttr('contenteditable');
}
}
function selectImage(element) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
export default {
copyImageReferenceToClipboard
};