From 00b3d7b19a7a3ca0913f7a6780ac59eb56ca3a55 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 12 Nov 2018 17:23:05 +1030 Subject: [PATCH] Add emoji button to text editor toolbar --- .../emoji/js/src/forum/addComposerAutocomplete.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/emoji/js/src/forum/addComposerAutocomplete.js b/extensions/emoji/js/src/forum/addComposerAutocomplete.js index 307b30ac5..663e805fb 100644 --- a/extensions/emoji/js/src/forum/addComposerAutocomplete.js +++ b/extensions/emoji/js/src/forum/addComposerAutocomplete.js @@ -2,6 +2,8 @@ import getCaretCoordinates from 'textarea-caret'; import { extend } from 'flarum/extend'; import ComposerBody from 'flarum/components/ComposerBody'; +import TextEditor from 'flarum/components/TextEditor'; +import TextEditorButton from 'flarum/components/TextEditorButton'; import emojiMap from './generated/emojiMap.json'; import getEmojiIconCode from './helpers/getEmojiIconCode'; import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable'; @@ -45,7 +47,7 @@ export default function addComposerAutocomplete() { $textarea .after($container) - .on('click keyup', function(e) { + .on('click keyup input', function(e) { // Up, down, enter, tab, escape, left, right. if ([9, 13, 27, 40, 38, 37, 39].indexOf(e.which) !== -1) return; @@ -162,4 +164,12 @@ export default function addComposerAutocomplete() { } }); }); + + extend(TextEditor.prototype, 'toolbarItems', function(items) { + items.add('emoji', ( + this.insertAtCursor(':')} icon="far fa-smile"> + {app.translator.trans('flarum-emoji.forum.composer.emoji_tooltip')} + + )); + }); }