From efb840c6332a8137491efce3a813ead070d94d29 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Mon, 29 Jul 2019 02:49:36 -0700 Subject: [PATCH 1/3] Fix `openBrowseFileWindow` to also obey `self.options.imageUploadFunction` if specified. I think this part just got missed in https://github.com/Ionaru/easy-markdown-editor/pull/106. I'm not sure if I should be doing anything with the `onSuccess` and `onError` callbacks here. --- src/js/easymde.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index 5e2376c..976328a 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -1985,7 +1985,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); } From 8a2283cf274b106c001f035209b457ee389013ab Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Mon, 29 Jul 2019 02:54:20 -0700 Subject: [PATCH 2/3] Bail out if there are no files to upload. Without this change, if you either: - Click and drag some text into the markdown editor, or - Copy paste some text into the markdown editor The status bar will get updated to say "Uploading image ...", and will never stop. --- src/js/easymde.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/easymde.js b/src/js/easymde.js index 976328a..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); From 78b2083c9e6625b00c5f8e9a678fd9c42487420a Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Tue, 20 Aug 2019 00:26:27 +0200 Subject: [PATCH 3/3] Updated changelog for PR #109 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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