Merge pull request #109 from jfly/upload-polish

Upload polish
pull/115/head
Jeroen Akkerman 5 years ago committed by GitHub
commit d114dab8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
<!-- Linked PRs -->
[#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
<!-- Linked users -->
[@jfly]: https://github.com/jfly
[@sperezp]: https://github.com/sperezp
[@JeroenvO]: https://github.com/JeroenvO
[@sn3p]: https://github.com/sn3p

@ -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);
}

Loading…
Cancel
Save