Upload pasted images in codemirror
parent
89aae79531
commit
3864b30d96
|
@ -234,6 +234,19 @@ define([
|
|||
editor.scrollIntoView(cursor);
|
||||
});
|
||||
|
||||
// Don't paste file path in the users wants to paste a file
|
||||
editor.on('paste', function (editor, ev) {
|
||||
try {
|
||||
if (!ev.clipboardData.items) { return; }
|
||||
var items = Array.prototype.slice.apply(ev.clipboardData.items);
|
||||
var hasFile = items.some(function (el) {
|
||||
return el.kind === "file";
|
||||
});
|
||||
if (!hasFile) { return; }
|
||||
ev.preventDefault();
|
||||
} catch (e) { console.error(e); }
|
||||
});
|
||||
|
||||
var setMode = exp.setMode = function (mode, cb) {
|
||||
exp.highlightMode = mode;
|
||||
if (mode === 'markdown') { mode = 'gfm'; }
|
||||
|
|
|
@ -528,6 +528,26 @@ define([
|
|||
$hoverArea.removeClass('cp-fileupload-hovering');
|
||||
onFileDrop(dropped, e);
|
||||
});
|
||||
|
||||
|
||||
// Upload files on paste
|
||||
$area.on('paste', function (e) {
|
||||
try {
|
||||
var ev = e.originalEvent;
|
||||
if (!ev.clipboardData.items) { return; }
|
||||
var items = Array.prototype.slice.apply(ev.clipboardData.items);
|
||||
var hasFile = items.some(function (el) {
|
||||
return el.kind === "file";
|
||||
});
|
||||
if (!hasFile) { return; }
|
||||
ev.preventDefault();
|
||||
items.forEach(function (el) {
|
||||
if (el.kind !== "file") { return; }
|
||||
var file = el.getAsFile();
|
||||
handleFile(file, e);
|
||||
});
|
||||
} catch (e) { console.error(e); }
|
||||
});
|
||||
};
|
||||
var createCkeditorDropHandler = function () {
|
||||
var editor = config.ckeditor;
|
||||
|
|
Loading…
Reference in New Issue