copy paste support
This commit is contained in:
parent
adeda1b0f5
commit
3bd9d47a3c
4 changed files with 27 additions and 3 deletions
|
@ -47,6 +47,7 @@ function unhighlight(e) {
|
|||
}
|
||||
|
||||
dropArea.addEventListener('drop', handleDrop, false)
|
||||
window.addEventListener('paste', handlePaste);
|
||||
|
||||
function handleDrop(e) {
|
||||
let dt = e.dataTransfer
|
||||
|
@ -54,6 +55,26 @@ function handleDrop(e) {
|
|||
handleFiles(files)
|
||||
}
|
||||
|
||||
function handlePaste(e) {
|
||||
// Get the data of clipboard
|
||||
const clipboardItems = e.clipboardData.items;
|
||||
const items = [].slice.call(clipboardItems).filter(function (item) {
|
||||
// Filter the image items only
|
||||
return item.type.indexOf('image') !== -1;
|
||||
});
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = items[0];
|
||||
// Get the blob of image
|
||||
const blob = item.getAsFile();
|
||||
console.log(blob)
|
||||
|
||||
uploadFile(blob)
|
||||
previewFile(blob);
|
||||
}
|
||||
|
||||
function handleFiles(files) {
|
||||
files = [...files]
|
||||
files.forEach(uploadFile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue