mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-06 17:44:27 -06:00
[wip upload-image] Allow image upload with drag&drop
This commit is contained in:
parent
e1536da530
commit
3cb4a817f2
@ -1624,6 +1624,37 @@ function EasyMDE(options) {
|
|||||||
if (options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) {
|
if (options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) {
|
||||||
this.value(options.initialValue);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user