Skip to content

Commit 09c6d6c

Browse files
committed
Added button for inserting attachment link to a page
For BookStackApp#1460
1 parent ad48cd3 commit 09c6d6c

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

resources/js/components/attachments.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ class Attachments {
3333
this.container.addEventListener('event-emit-select-edit-back', event => {
3434
this.stopEdit();
3535
});
36+
37+
this.container.addEventListener('event-emit-select-insert', event => {
38+
const insertContent = event.target.closest('[data-drag-content]').getAttribute('data-drag-content');
39+
const contentTypes = JSON.parse(insertContent);
40+
window.$events.emit('editor::insert', {
41+
html: contentTypes['text/html'],
42+
markdown: contentTypes['text/plain'],
43+
});
44+
});
3645
}
3746

3847
reloadList() {

resources/js/components/markdown-editor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ class MarkdownEditor {
563563
this.cm.setCursor(cursorPos.line + prependLineCount, cursorPos.ch);
564564
});
565565

566+
// Insert editor content at the current location
567+
window.$events.listen('editor::insert', (eventContent) => {
568+
const markdown = getContentToInsert(eventContent);
569+
this.cm.replaceSelection(markdown);
570+
});
571+
566572
// Focus on editor
567573
window.$events.listen('editor::focus', () => {
568574
this.cm.focus();

resources/js/components/wysiwyg-editor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ function listenForBookStackEditorEvents(editor) {
401401
editor.setContent(content);
402402
});
403403

404+
// Insert editor content at the current location
405+
window.$events.listen('editor::insert', ({html}) => {
406+
editor.insertContent(html);
407+
});
408+
404409
// Focus on the editor
405410
window.$events.listen('editor::focus', () => {
406411
editor.focus();

resources/lang/en/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
'attachments_link_url' => 'Link to file',
266266
'attachments_link_url_hint' => 'Url of site or file',
267267
'attach' => 'Attach',
268+
'attachments_insert_link' => 'Add Attachment Link to Page',
268269
'attachments_edit_file' => 'Edit File',
269270
'attachments_edit_file_name' => 'File Name',
270271
'attachments_edit_drop_upload' => 'Drop files or click here to upload and overwrite',

resources/views/attachments/manager-list.blade.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ class="card drag-card">
1010
<a href="{{ $attachment->getUrl() }}" target="_blank">{{ $attachment->name }}</a>
1111
</div>
1212
<div class="flex-fill justify-flex-end">
13+
<button component="event-emit-select"
14+
option:event-emit-select:name="insert"
15+
type="button"
16+
title="{{ trans('entities.attachments_insert_link') }}"
17+
class="drag-card-action text-center text-primary">@icon('link') </button>
1318
<button component="event-emit-select"
1419
option:event-emit-select:name="edit"
1520
option:event-emit-select:id="{{ $attachment->id }}"
1621
type="button"
22+
title="{{ trans('common.edit') }}"
1723
class="drag-card-action text-center text-primary">@icon('edit')</button>
1824
<div component="dropdown" class="flex-fill relative">
19-
<button refs="dropdown@toggle" type="button" class="drag-card-action text-center text-neg">@icon('close')</button>
25+
<button refs="dropdown@toggle"
26+
type="button"
27+
title="{{ trans('common.delete') }}"
28+
class="drag-card-action text-center text-neg">@icon('close')</button>
2029
<div refs="dropdown@menu" class="dropdown-menu">
2130
<p class="text-neg small px-m mb-xs">{{ trans('entities.attachments_delete') }}</p>
2231
<button refs="ajax-delete-row@delete" type="button" class="text-primary small delete">{{ trans('common.confirm') }}</button>

0 commit comments

Comments
 (0)