From 6290f408ff7e995e24b39094ad1fec9449c8da2f Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Fri, 11 Jan 2019 18:09:54 +0100 Subject: [PATCH] Allow to paste images (#153) dropzone.js doesn't support pasting itself yet, so adding it externally and calling `.addFile()` to upload the pasted image. Fixes #130 --- static/js/upload.js | 12 +++++++++++- templates/index.html | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/static/js/upload.js b/static/js/upload.js index 5e54d62..159bad2 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -102,8 +102,18 @@ Dropzone.options.dropzone = { previewsContainer: "#uploads", parallelUploads: 5, headers: {"Accept": "application/json"}, - dictDefaultMessage: "Click or Drop file(s)", + dictDefaultMessage: "Click or Drop file(s) or Paste image", dictFallbackMessage: "" }; +document.onpaste = function(event) { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + for (index in items) { + var item = items[index]; + if (item.kind === "file") { + Dropzone.forElement("#dropzone").addFile(item.getAsFile()); + } + } +}; + // @end-license diff --git a/templates/index.html b/templates/index.html index 5e95d01..87d821d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@
- Click or Drop file(s) + Click or Drop file(s) or Paste image