2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-06 09:34:27 -06:00

[wip upload-image] Allow image upload with drag&drop

This commit is contained in:
Nathanaël Jourdane 2019-03-05 11:44:31 +01:00
parent e1536da530
commit 3cb4a817f2

View File

@ -1624,6 +1624,37 @@ function EasyMDE(options) {
if (options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) {
this.value(options.initialValue);
}
if (options.uploadImage) {
var self = this;
this.codemirror.on('dragenter', function(cm, event) {
event.stopPropagation();
event.preventDefault();
});
this.codemirror.on('dragover', function(cm, event) {
event.stopPropagation();
event.preventDefault();
});
this.codemirror.on('drop', function(cm, event) {
event.stopPropagation();
event.preventDefault();
var dt = event.dataTransfer;
var files = dt.files;
console.log(files);
for(var i=0; i<files.length; i++) {
uploadImage(files[i], options, function(url) {
afterImageUploaded(self, url);
}, function(errorStatus, errorStatusText) {
console.log('EasyMDE: error ' + errorStatus + ' when importing image: ' + errorStatusText);
});
}
});
}
}
/**