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-08-17 10:51:43 +03:00
|
|
|
toastService.showMessage("A reference to the image has been copied to clipboard. This can be pasted in any text note.");
|
2023-05-03 10:23:20 +02:00
|
|
|
} else {
|
2024-08-17 10:51:43 +03:00
|
|
|
toastService.showAndLogError("Could not copy the image reference to clipboard.");
|
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
|
|
|
|
|
};
|