From 09c6d6c7221ff96e718dbc2669e91a7a6745bf9d Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 13 Sep 2020 18:58:05 +0100 Subject: [PATCH] Added button for inserting attachment link to a page For #1460 --- resources/js/components/attachments.js | 9 +++++++++ resources/js/components/markdown-editor.js | 6 ++++++ resources/js/components/wysiwyg-editor.js | 5 +++++ resources/lang/en/entities.php | 1 + resources/views/attachments/manager-list.blade.php | 11 ++++++++++- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/resources/js/components/attachments.js b/resources/js/components/attachments.js index 51e54054e..6dcfe9f12 100644 --- a/resources/js/components/attachments.js +++ b/resources/js/components/attachments.js @@ -33,6 +33,15 @@ class Attachments { this.container.addEventListener('event-emit-select-edit-back', event => { this.stopEdit(); }); + + this.container.addEventListener('event-emit-select-insert', event => { + const insertContent = event.target.closest('[data-drag-content]').getAttribute('data-drag-content'); + const contentTypes = JSON.parse(insertContent); + window.$events.emit('editor::insert', { + html: contentTypes['text/html'], + markdown: contentTypes['text/plain'], + }); + }); } reloadList() { diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index 5ffe4ef4d..c371a9839 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -563,6 +563,12 @@ class MarkdownEditor { this.cm.setCursor(cursorPos.line + prependLineCount, cursorPos.ch); }); + // Insert editor content at the current location + window.$events.listen('editor::insert', (eventContent) => { + const markdown = getContentToInsert(eventContent); + this.cm.replaceSelection(markdown); + }); + // Focus on editor window.$events.listen('editor::focus', () => { this.cm.focus(); diff --git a/resources/js/components/wysiwyg-editor.js b/resources/js/components/wysiwyg-editor.js index 05897c250..a32e78161 100644 --- a/resources/js/components/wysiwyg-editor.js +++ b/resources/js/components/wysiwyg-editor.js @@ -401,6 +401,11 @@ function listenForBookStackEditorEvents(editor) { editor.setContent(content); }); + // Insert editor content at the current location + window.$events.listen('editor::insert', ({html}) => { + editor.insertContent(html); + }); + // Focus on the editor window.$events.listen('editor::focus', () => { editor.focus(); diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index ac17a10d4..f64867a56 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -265,6 +265,7 @@ return [ 'attachments_link_url' => 'Link to file', 'attachments_link_url_hint' => 'Url of site or file', 'attach' => 'Attach', + 'attachments_insert_link' => 'Add Attachment Link to Page', 'attachments_edit_file' => 'Edit File', 'attachments_edit_file_name' => 'File Name', 'attachments_edit_drop_upload' => 'Drop files or click here to upload and overwrite', diff --git a/resources/views/attachments/manager-list.blade.php b/resources/views/attachments/manager-list.blade.php index 30307ff41..313faa575 100644 --- a/resources/views/attachments/manager-list.blade.php +++ b/resources/views/attachments/manager-list.blade.php @@ -10,13 +10,22 @@ {{ $attachment->name }}
+
- +