From 7af4f9317528e0a2fe7e829dc31118bc1a4a2196 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 25 May 2024 00:59:53 +0900 Subject: [PATCH] Add upload button to CKEditor image dialog --- .../ckeditor/plugins/image/dialogs/image.js | 16 ++++++++++------ modules/editor/skins/ckeditor/config.blade.php | 1 + modules/editor/skins/ckeditor/js/editor.js | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/js/plugins/ckeditor/ckeditor/plugins/image/dialogs/image.js b/common/js/plugins/ckeditor/ckeditor/plugins/image/dialogs/image.js index ae9447989..cbe844af6 100644 --- a/common/js/plugins/ckeditor/ckeditor/plugins/image/dialogs/image.js +++ b/common/js/plugins/ckeditor/ckeditor/plugins/image/dialogs/image.js @@ -574,16 +574,20 @@ }, validate: CKEDITOR.dialog.validate.notEmpty( editor.lang.image.urlMissing ) }, + // Rhymix upload integration { type: 'button', - id: 'browse', - // v-align with the 'txtUrl' field. - // TODO: We need something better than a fixed size here. + id: 'rx_upload', style: 'display:inline-block;margin-top:14px;', align: 'center', - label: editor.lang.common.browseServer, - hidden: true, - filebrowser: 'info:txtUrl' + label: editor.lang.image.upload, + hidden: !editor.config.rx_allow_upload, + onClick: function() { + const editor_container = _getCkeContainer(editor.config.xe_editor_sequence); + const upload_container = editor_container.nextAll('.xefu-container').first(); + upload_container.find('input[type=file]').first().trigger('click'); + this.getDialog().hide(); + } } ] } ] }, diff --git a/modules/editor/skins/ckeditor/config.blade.php b/modules/editor/skins/ckeditor/config.blade.php index 0f586a3a7..402a7dc18 100644 --- a/modules/editor/skins/ckeditor/config.blade.php +++ b/modules/editor/skins/ckeditor/config.blade.php @@ -11,6 +11,7 @@ $ckconfig->toolbar = $editor_toolbar ?? 'default'; $ckconfig->hide_toolbar = $editor_toolbar_hide ?? false; $ckconfig->focus = $editor_focus ?? false; $ckconfig->ios_patch = (bool)preg_match('/i(Phone|Pad|Pod)/', $_SERVER['HTTP_USER_AGENT'] ?? ''); +$ckconfig->allow_upload = $allow_fileupload ?? false; // Plugin configuration $ckconfig->add_plugins = $editor_additional_plugins ?: []; diff --git a/modules/editor/skins/ckeditor/js/editor.js b/modules/editor/skins/ckeditor/js/editor.js index 5613a3cc8..ba888ee8a 100644 --- a/modules/editor/skins/ckeditor/js/editor.js +++ b/modules/editor/skins/ckeditor/js/editor.js @@ -52,7 +52,8 @@ $(function() { language: config.language, iframe_attributes: {}, versionCheck: false, - xe_editor_sequence: editor_sequence + rx_allow_upload: config.allow_upload, + xe_editor_sequence: editor_sequence, }, loadXeComponent: true, enableToolbar: true