Skip to content

Commit

Permalink
add a name attribute to image inserted in text so its name can be found
Browse files Browse the repository at this point in the history
when downloaded. fix #3797
  • Loading branch information
NicolasCARPi committed Jun 10, 2023
1 parent a490c93 commit df4d80a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/templates/upload-dropdown-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% if mode == 'edit' %}
<!-- INSERT IN TEXT in edit mode for images -->
{% if ext matches '/(jpg|jpeg|png|gif|svg)$/i' %}
<a class='dropdown-item inserter clickable' data-storage='{{ upload.storage }}' data-link='{{ upload.long_name }}' data-uploadid='{{ upload.id }}'>
<a class='dropdown-item' data-action='insert-image-in-body' data-name='{{ upload.real_name|e('html') }}' data-storage='{{ upload.storage }}' data-link='{{ upload.long_name }}' data-uploadid='{{ upload.id }}'>
<i class='fas fa-fw fa-image mr-1'></i>{{ 'Insert in text at cursor position'|trans }}</a>
{% endif %}

Expand Down
27 changes: 13 additions & 14 deletions src/ts/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ document.addEventListener('DOMContentLoaded', () => {
} else if (el.matches('[data-action="show-plain-text"]')) {
showContentPlainText(el);

// INSERT IMAGE AT CURSOR POSITION IN TEXT
} else if (el.matches('[data-action="insert-image-in-body"]')) {
// link to the image
const url = `app/download.php?name=${el.dataset.name}&f=${el.dataset.link}&storage=${el.dataset.storage}`;
// switch for markdown or tinymce editor
let content: string;
if (editor.type === 'md') {
content = '\n![image](' + url + ')\n';
} else if (editor.type === 'tiny') {
content = '<img src="' + url + '" />';
}
editor.setContent(content);

// ADD CONTENT OF PLAIN TEXT FILES AT CURSOR POSITION IN TEXT
} else if (el.matches('[data-action="insert-plain-text"]')) {
fetch(`app/download.php?storage=${el.dataset.storage}&f=${el.dataset.path}`).then(response => {
Expand Down Expand Up @@ -425,20 +438,6 @@ document.addEventListener('DOMContentLoaded', () => {
});
}

// INSERT IMAGE AT CURSOR POSITION IN TEXT
$(document).on('click', '.inserter', function() {
// link to the image
const url = `app/download.php?f=${$(this).data('link')}&storage=${$(this).data('storage')}`;
// switch for markdown or tinymce editor
let content;
if (editor.type === 'md') {
content = '\n![image](' + url + ')\n';
} else if (editor.type === 'tiny') {
content = '<img src="' + url + '" />';
}
editor.setContent(content);
});

// this should be in uploads but there is no good way so far to interact with the two editors there
document.getElementById('filesdiv').addEventListener('submit', event => {
const el = event.target as HTMLElement;
Expand Down

0 comments on commit df4d80a

Please sign in to comment.