diff --git a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js index 6c28182..e213fba 100644 --- a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js +++ b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js @@ -270,40 +270,50 @@ var fileTools = CKEDITOR.fileTools; fileTools.addUploadWidget(editor, 'fileReader', { loadMethod: 'load', - supportedTypes: /image\/(jpeg|png|gif|bmp)/ + supportedTypes: /image\/(gif|png|jpg|jpeg)/, + fileToElement: function () { + var el = new CKEDITOR.dom.element('span'); + el.addClass('cke_upload_uploading'); + el.setText('Loading...'); + return el; + }, + onLoaded: function (loader) { + var el = new CKEDITOR.dom.element('img'); + el.addClass('cke_upload_uploading'); + el.setAttribute('src', loader.data); + //this.replaceWith(''); + console.log(el) + this.replaceWith(el.getOuterHtml()); + } }); editor.on('paste', function (evt) { var file = evt.data.dataTransfer.getFile(0); - if (CKEDITOR.fileTools.isTypeSupported(file, /image\/(jpeg|png|gif|bmp)/)) { + if (CKEDITOR.fileTools.isTypeSupported(file, /image\/(gif|png|jpg|jpeg)/)) { + var loader = editor.uploadRepository.create(file); + loader.load(); editor.execCommand('image'); - $(window).on('dialogcreate', function (e, dialog, $element, settings) { + $(window).one('dialogcreate', function (e, dialog, $element, settings) { var form = $(e.target).find('form.editor-image-dialog'); var formData = new FormData(); - var uploadButtonId = '#' + form.find('[name=fid_upload_button]').attr('id'); - - _.each(Drupal.ajax.instances, function (value, key, list) { - if (value !== null && value.selector === uploadButtonId) { - var myAjaxObject = Drupal.ajax.instances[key]; - - myAjaxObject.beforeSerialize = function (element_settings, options) { - formData.append('files[fid]', file); - $.each(this.$form.serializeArray(), function (_, kv) { - formData[kv.name] = kv.value; - formData.append(kv.name, kv.value); - }); - options.data = formData; - options.contentType = false; - options.processData = false; - }; - - myAjaxObject.execute(); - } - }); - + var uploadButtonId = '#' + form.find('[data-drupal-selector=edit-fid-upload-button]').attr('id'); + + var ajaxObject = getAjaxObject(uploadButtonId); + ajaxObject.beforeSerialize = function (element_settings, options) { + formData.append('files[fid]', file); + $.each(this.$form.serializeArray(), function (k, v) { + formData[v.name] = v.value; + formData.append(v.name, v.value); + }); + options.data = formData; + options.contentType = false; + options.processData = false; + }; + + ajaxObject.execute(); }); } }); @@ -404,6 +414,24 @@ return null; } + /** + * Gets a Drupal AJAX instance by selector id. + * + * @param {string} id + * The selector id. + * @returns {Object} + * The Drupal AJAX instance, or null. + */ + function getAjaxObject(id) { + var ajaxInstance = null; + $.each(Drupal.ajax.instances, function (k, v) { + if (v !== null && v.selector === id) { + return ajaxInstance = Drupal.ajax.instances[k]; + } + }); + return ajaxInstance; + } + // Expose an API for other plugins to interact with drupalimage widgets. CKEDITOR.plugins.drupalimage = { getFocusedWidget: getFocusedWidget