diff --git a/CHANGELOG.md b/CHANGELOG.md index a1283c2..6db6f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Upload images functionality (Thanks to [@roipoussiere] and [@JeroenvO], [#71], [#101]). - Allow custom image upload function (Thanks to [@sperezp], [#106]). +- More polish to the upload images functionality (Thanks to [@jfly], [#109]). ## [2.7.0] - 2019-07-13 ### Added @@ -125,6 +126,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown [#9]: https://github.com/Ionaru/easy-markdown-editor/issues/9 +[#109]: https://github.com/Ionaru/easy-markdown-editor/pull/109 [#106]: https://github.com/Ionaru/easy-markdown-editor/pull/106 [#101]: https://github.com/Ionaru/easy-markdown-editor/pull/101 [#93]: https://github.com/Ionaru/easy-markdown-editor/pull/93 @@ -136,6 +138,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown [#19]: https://github.com/Ionaru/easy-markdown-editor/pull/19 +[@jfly]: https://github.com/jfly [@sperezp]: https://github.com/sperezp [@JeroenvO]: https://github.com/JeroenvO [@sn3p]: https://github.com/sn3p diff --git a/src/js/easymde.js b/src/js/easymde.js index 5e2376c..c675335 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -1669,6 +1669,9 @@ function EasyMDE(options) { * @param [onError] {function} see EasyMDE.prototype.uploadImage */ EasyMDE.prototype.uploadImages = function (files, onSuccess, onError) { + if (files.length === 0) { + return; + } var names = []; for (var i = 0; i < files.length; i++) { names.push(files[i].name); @@ -1688,6 +1691,9 @@ EasyMDE.prototype.uploadImages = function (files, onSuccess, onError) { * @param {FileList} files The files to upload the the server. */ EasyMDE.prototype.uploadImagesUsingCustomFunction = function (imageUploadFunction, files) { + if (files.length === 0) { + return; + } var names = []; for (var i = 0; i < files.length; i++) { names.push(files[i].name); @@ -1985,7 +1991,11 @@ EasyMDE.prototype.openBrowseFileWindow = function (onSuccess, onError) { var imageInput = this.gui.toolbar.getElementsByClassName('imageInput')[0]; imageInput.click(); //dispatchEvent(new MouseEvent('click')); // replaced with click() for IE11 compatibility. function onChange(event) { - self.uploadImages(event.target.files, onSuccess, onError); + if (self.options.imageUploadFunction) { + self.uploadImagesUsingCustomFunction(self.options.imageUploadFunction, event.target.files); + } else { + self.uploadImages(event.target.files, onSuccess, onError); + } imageInput.removeEventListener('change', onChange); }