core/modules/ckeditor/js/ckeditor.js | 16 +++++++++++++++- core/modules/ckeditor/js/plugins/drupalimage/plugin.js | 13 ++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index 497393f..a63744d 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -215,6 +215,7 @@ // Add a consistent dialog class. var classes = dialogSettings.dialogClass ? dialogSettings.dialogClass.split(' ') : []; + classes.push('ckeditor-drupal-dialog'); classes.push('ui-dialog--narrow'); dialogSettings.dialogClass = classes.join(' '); dialogSettings.autoResize = window.matchMedia('(min-width: 600px)').matches; @@ -248,7 +249,7 @@ }; // Moves the dialog to the top of the CKEDITOR stack. - $(window).on('dialogcreate', function (e, dialog, $element, settings) { + $(window).on('dialogcreate', function (e, dialog) { $('.ui-dialog--narrow').css('zIndex', CKEDITOR.config.baseFloatZIndex + 1); }); @@ -258,6 +259,13 @@ $(this).remove(); }); }); + // @fires event:editor:dialogopen + $(window).on('dialog:aftercreate', function (e, dialog, $element, settings) { + if (!$element.parent().hasClass('ckeditor-drupal-dialog')) { + return; + } + $(window).trigger('editor:dialogopen', [dialog, $element]); + }); // Respond to dialogs that are saved, sending data back to CKEditor. $(window).on('editor:dialogsave', function (e, values) { @@ -267,10 +275,16 @@ }); // Respond to dialogs that are closed, removing the current save handler. + // @fires event:editor:dialogclose $(window).on('dialog:afterclose', function (e, dialog, $element) { + if (!$element.parent().hasClass('ckeditor-drupal-dialog')) { + return; + } + if (Drupal.ckeditor.saveCallback) { Drupal.ckeditor.saveCallback = null; } + $(window).trigger('editor:dialogclose', [dialog, $element]); }); // Set the CKEditor cache-busting string to the same value as Drupal. diff --git a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js index e213fba..2868daa 100644 --- a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js +++ b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js @@ -279,7 +279,7 @@ }, onLoaded: function (loader) { var el = new CKEDITOR.dom.element('img'); - el.addClass('cke_upload_uploading'); + el.setAttribute('data-cke-drupalimage-preview', true); el.setAttribute('src', loader.data); //this.replaceWith(''); console.log(el) @@ -296,8 +296,8 @@ editor.execCommand('image'); - $(window).one('dialogcreate', function (e, dialog, $element, settings) { - var form = $(e.target).find('form.editor-image-dialog'); + $(window).one('editor:dialogopen', function (e, dialog, $element, settings) { + var form = $element.find('form.editor-image-dialog'); var formData = new FormData(); var uploadButtonId = '#' + form.find('[data-drupal-selector=edit-fid-upload-button]').attr('id'); @@ -315,6 +315,13 @@ ajaxObject.execute(); }); + + $(window).one('editor:dialogclose', function (e, dialog, $element, settings) { + var preview = editor.document.findOne('[data-cke-drupalimage-preview]'); + if (preview) { + preview.remove(); + } + }); } });