mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added copy image to the image detail
This commit is contained in:
parent
afcbfcfa03
commit
273a9b14d9
@ -1,12 +1,13 @@
|
|||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
import server from "./server.js";
|
|
||||||
import protectedSessionHolder from "./protected_session_holder.js";
|
import protectedSessionHolder from "./protected_session_holder.js";
|
||||||
import noteDetailService from "./note_detail.js";
|
import noteDetailService from "./note_detail.js";
|
||||||
|
import infoService from "./info.js";
|
||||||
|
|
||||||
const $component = $('#note-detail-image');
|
const $component = $('#note-detail-image');
|
||||||
const $imageView = $('#note-detail-image-view');
|
const $imageView = $('#note-detail-image-view');
|
||||||
|
|
||||||
const $imageDownload = $("#image-download");
|
const $imageDownload = $("#image-download");
|
||||||
|
const $copyToClipboardDownload = $("#image-copy-to-clipboard");
|
||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const currentNote = noteDetailService.getCurrentNote();
|
||||||
@ -18,6 +19,35 @@ async function show() {
|
|||||||
|
|
||||||
$imageDownload.click(() => utils.download(getFileUrl()));
|
$imageDownload.click(() => utils.download(getFileUrl()));
|
||||||
|
|
||||||
|
function selectImage(element) {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(element);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
$copyToClipboardDownload.click(() => {
|
||||||
|
$component.attr('contenteditable','true');
|
||||||
|
|
||||||
|
try {
|
||||||
|
selectImage($component.get(0));
|
||||||
|
|
||||||
|
const success = document.execCommand('copy');
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
infoService.showMessage("Image copied to the clipboard");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
infoService.showAndLogError("Could not copy the image to clipboard.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
window.getSelection().removeAllRanges();
|
||||||
|
$component.removeAttr('contenteditable');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function getFileUrl() {
|
function getFileUrl() {
|
||||||
// electron needs absolute URL so we extract current host, port, protocol
|
// electron needs absolute URL so we extract current host, port, protocol
|
||||||
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
|
return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
|
||||||
|
@ -3,5 +3,9 @@
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<button id="file-download" class="btn btn-primary" type="button">Download</button>
|
<button id="image-download" class="btn btn-primary" type="button">Download</button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button id="image-copy-to-clipboard" class="btn btn-primary" type="button">Copy to clipboard</button>
|
||||||
</div>
|
</div>
|
Loading…
x
Reference in New Issue
Block a user