From 6c2eb4e98e62c83967e4fb672b692bb6448dcbaf Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 30 Jan 2017 03:25:34 -0300 Subject: Added image pasting from clipboard --- public/js/upload.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'public/js') diff --git a/public/js/upload.js b/public/js/upload.js index ba67d15..b620248 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -105,6 +105,7 @@ upload.prepareDropzone = function(){ }, init: function() { this.on('addedfile', function(file) { + myDropzone = this; document.getElementById('uploads').style.display = 'block'; }); } @@ -139,6 +140,22 @@ upload.prepareDropzone = function(){ } +//Handle image paste event +window.addEventListener('paste', function(event) { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + for (index in items) { + var item = items[index]; + if (item.kind === 'file') { + var blob = item.getAsFile(); + console.log(blob.type); + var file = new File([blob], "pasted-image."+blob.type.match(/(?:[^\/]*\/)([^;]*)/)[1]); + file.type = blob.type; + console.log(file); + myDropzone.addFile(file); + } + } +}); + window.onload = function () { upload.checkIfPublic(); }; \ No newline at end of file -- cgit v1.2.3